Class: Inject::Target
Instance Method Summary collapse
- #apply(params, target) ⇒ Object
- #attribute ⇒ Object
- #default ⇒ Object
-
#initialize(klass, attribute, opts = {}) ⇒ Target
constructor
A new instance of Target.
- #klass ⇒ Object
- #options ⇒ Object
- #required? ⇒ Boolean
Constructor Details
#initialize(klass, attribute, opts = {}) ⇒ Target
Returns a new instance of Target.
4 5 6 7 8 9 10 |
# File 'lib/attr_inject/target.rb', line 4 def initialize(klass, attribute, opts={}) @klass = klass @attribute = attribute opts add_accessor(attribute, klass) end |
Instance Method Details
#apply(params, target) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/attr_inject/target.rb', line 12 def apply(params, target) validate! params set_value(target, default) if !default.nil? set_value(target, attribute_value(params)) if params.include?(attribute) end |
#attribute ⇒ Object
27 28 29 |
# File 'lib/attr_inject/target.rb', line 27 def attribute @attribute end |
#default ⇒ Object
23 24 25 |
# File 'lib/attr_inject/target.rb', line 23 def default [:default] end |
#klass ⇒ Object
31 32 33 |
# File 'lib/attr_inject/target.rb', line 31 def klass @klass end |
#options ⇒ Object
35 36 37 |
# File 'lib/attr_inject/target.rb', line 35 def @options end |
#required? ⇒ Boolean
19 20 21 |
# File 'lib/attr_inject/target.rb', line 19 def required? [:required] && default.nil? end |