Class: Wallaby::AllFields
- Inherits:
-
Object
- Object
- Wallaby::AllFields
- Defined in:
- lib/fields/wallaby/all_fields.rb
Overview
A simple wrapper so that all fields (index/show/form and other fields appear before itself) can be set in one-line.
Instance Method Summary collapse
-
#[](key) ⇒ AllFields
Self.
-
#[]=(last_key, value) ⇒ Object
Set value for given keys.
-
#initialize(decorator) ⇒ AllFields
constructor
A new instance of AllFields.
Constructor Details
#initialize(decorator) ⇒ AllFields
Returns a new instance of AllFields.
17 18 19 20 |
# File 'lib/fields/wallaby/all_fields.rb', line 17 def initialize(decorator) @decorator = decorator @keys = [] end |
Instance Method Details
#[](key) ⇒ AllFields
Returns self.
24 25 26 27 |
# File 'lib/fields/wallaby/all_fields.rb', line 24 def [](key) @keys << key self end |
#[]=(last_key, value) ⇒ Object
Set value for given keys
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fields/wallaby/all_fields.rb', line 33 def []=(last_key, value) all_fields.each do |fields_method| last = @keys.reduce(@decorator.try(fields_method)) do |, key| .try :[], key end last.try :[]=, last_key, value end @keys = [] value # rubocop:disable Lint/Void end |