Skip to content

Commit

Permalink
Refactor arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
nepalez committed May 9, 2016
1 parent d9d17ae commit f5bdd8f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Andrew Kozin (aka nepalez)
Copyright (c) 2016 Andrew Kozin (nepalez), Vladimir Kochnev (marshall-lee)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Initializer

def self.define(proc = nil, &block)
Module.new do |container|
container.extend Dry::Initializer::Mixin
container.extend Mixin
container.instance_exec(&(proc || block))
end
end
Expand Down
9 changes: 5 additions & 4 deletions lib/dry/initializer/arguments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ def declaration
<<-RUBY
attr_reader #{select(&:reader).map { |arg| ":#{arg.name}" }.join(", ")}
define_method :initialize do |#{signature}|
#{assign_arguments}
#{take_declarations}
#{assign_defaults}
#{check_constraints}
#{operations.map(&method(:send)).compact.join("\n")}
end
RUBY
end
Expand Down Expand Up @@ -65,6 +62,10 @@ def signature
(params + options).map(&:signature).join(", ")
end

def operations
%w(assign_arguments take_declarations assign_defaults check_constraints)
end

def assign_arguments
map(&:assignment).join("\n")
end
Expand Down

0 comments on commit f5bdd8f

Please sign in to comment.