Class: JsonApi::Includes
- Inherits:
-
Object
- Object
- JsonApi::Includes
- Defined in:
- lib/json_api_ruby/includes.rb
Overview
Builds a traversible representation of the included resources
Instance Attribute Summary collapse
- #includes ⇒ Object
-
#name ⇒ Object
readonly
Returns the value of attribute name.
- #next ⇒ Object
Class Method Summary collapse
-
.parse_includes(includes) ⇒ Object
Returns: #<Includes>.
Instance Method Summary collapse
Instance Attribute Details
#includes ⇒ Object
32 33 34 |
# File 'lib/json_api_ruby/includes.rb', line 32 def includes @includes || [] end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/json_api_ruby/includes.rb', line 4 def name @name end |
#next ⇒ Object
36 37 38 |
# File 'lib/json_api_ruby/includes.rb', line 36 def next @next || self.class.new end |
Class Method Details
.parse_includes(includes) ⇒ Object
Returns:
#<Includes>
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/json_api_ruby/includes.rb', line 10 def self.parse_includes(includes) first_include = self.new split_includes = Array(includes).map{|inc| inc.to_s.split('.')} split_includes = ArrayTransposer.new(split_includes).transpose_array first_array = split_includes.shift first_include.includes = Array(first_array).uniq.compact split_includes.inject(first_include) do |base_include, sub_array| new_include = self.new new_include.includes = sub_array.uniq.compact base_include.next = new_include new_include end first_include end |
Instance Method Details
#has_name?(name) ⇒ Boolean
28 29 30 |
# File 'lib/json_api_ruby/includes.rb', line 28 def has_name?(name) includes.include?(name) end |