Class: Api::ResourceAttributeSet
- Inherits:
-
Struct
- Object
- Struct
- Api::ResourceAttributeSet
- Defined in:
- lib/api/resource_attribute_set.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#includes ⇒ Object
Returns the value of attribute includes.
-
#methods_list ⇒ Object
Returns the value of attribute methods_list.
Class Method Summary collapse
Instance Method Summary collapse
-
#parsed_includes ⇒ Object
Parse json_attrs into { assoc_name => spec_or_nil }.
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes
2 3 4 |
# File 'lib/api/resource_attribute_set.rb', line 2 def attributes @attributes end |
#includes ⇒ Object
Returns the value of attribute includes
2 3 4 |
# File 'lib/api/resource_attribute_set.rb', line 2 def includes @includes end |
#methods_list ⇒ Object
Returns the value of attribute methods_list
2 3 4 |
# File 'lib/api/resource_attribute_set.rb', line 2 def methods_list @methods_list end |
Class Method Details
.for(model_class, jattrs: nil) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/api/resource_attribute_set.rb', line 3 def self.for(model_class, jattrs: nil) jattrs ||= model_class.respond_to?(:json_attrs) ? (model_class.json_attrs || {}) : {} only = Array(jattrs[:only]).map(&:to_sym) if only.empty? except = Array(jattrs[:except]).map(&:to_sym) only = model_class.column_names.map(&:to_sym) - except end new(only.reject { |a| a == :id }, Array(jattrs[:methods]).map(&:to_sym), jattrs[:include]) end |
Instance Method Details
#parsed_includes ⇒ Object
Parse json_attrs into { assoc_name => spec_or_nil }. Handles both symbol items (:roles) and hash items (users: { only: [:id] }).
15 16 17 18 19 20 21 22 23 |
# File 'lib/api/resource_attribute_set.rb', line 15 def parsed_includes return {} unless includes Array(includes).each_with_object({}) do |item, hash| case item when Hash then item.each { |k, v| hash[k] = v } when Symbol then hash[item] = nil end end end |