Module: Rails::Surrender::ModelAdditions::ClassMethods
- Defined in:
- lib/rails/surrender/model_additions.rb
Instance Method Summary collapse
- #surrender_attributes ⇒ Object
- #surrender_available_attributes ⇒ Object
- #surrender_available_expands ⇒ Object
- #surrender_callable_attributes ⇒ Object
- #surrender_callable_expands ⇒ Object
- #surrender_expands ⇒ Object
- #surrenders(*args) ⇒ Object
Instance Method Details
#surrender_attributes ⇒ Object
33 34 35 |
# File 'lib/rails/surrender/model_additions.rb', line 33 def surrender_attributes @surrender_attributes ||= %i[id created_at] end |
#surrender_available_attributes ⇒ Object
37 38 39 |
# File 'lib/rails/surrender/model_additions.rb', line 37 def surrender_available_attributes @surrender_available_attributes ||= [] end |
#surrender_available_expands ⇒ Object
45 46 47 |
# File 'lib/rails/surrender/model_additions.rb', line 45 def @surrender_available_expands ||= [] end |
#surrender_callable_attributes ⇒ Object
49 50 51 |
# File 'lib/rails/surrender/model_additions.rb', line 49 def surrender_callable_attributes @surrender_callable_attributes ||= (surrender_attributes + surrender_available_attributes).flatten end |
#surrender_callable_expands ⇒ Object
53 54 55 |
# File 'lib/rails/surrender/model_additions.rb', line 53 def @surrender_callable_expands ||= ( + ).flatten end |
#surrender_expands ⇒ Object
41 42 43 |
# File 'lib/rails/surrender/model_additions.rb', line 41 def @surrender_expands ||= [] end |
#surrenders(*args) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rails/surrender/model_additions.rb', line 17 def surrenders(*args) directives = args. # Run through the various lists of attributes and assign them to the rendering context # If the superclass has attributes then consume those as well. %w[attributes expands available_attributes available_expands].each do |directive| surrender_directive = "surrender_#{directive}" list = [] if superclass.instance_variable_defined?("@#{surrender_directive}") list << superclass.instance_variable_get("@#{surrender_directive}") end list << directives[directive.to_sym] if directives.key?(directive.to_sym) instance_variable_set("@#{surrender_directive}", list.flatten.uniq) end end |