Class: SimpleJsonApi::IncludeList
- Inherits:
-
Object
- Object
- SimpleJsonApi::IncludeList
- Defined in:
- lib/simple_json_api/include_list.rb
Overview
List of Included associations for a resource
Instance Attribute Summary collapse
-
#include_hash ⇒ Object
readonly
Returns the value of attribute include_hash.
Instance Method Summary collapse
-
#initialize(include) ⇒ IncludeList
constructor
A new instance of IncludeList.
- #parse ⇒ Object
Constructor Details
#initialize(include) ⇒ IncludeList
Returns a new instance of IncludeList.
7 8 9 10 11 12 13 |
# File 'lib/simple_json_api/include_list.rb', line 7 def initialize(include) @include = include # autovivificious hash @include_hash = Hash.new do |hash, key| hash[key] = Hash.new(&hash.default_proc) end end |
Instance Attribute Details
#include_hash ⇒ Object (readonly)
Returns the value of attribute include_hash.
5 6 7 |
# File 'lib/simple_json_api/include_list.rb', line 5 def include_hash @include_hash end |
Instance Method Details
#parse ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/simple_json_api/include_list.rb', line 15 def parse @include.split(',').each do |a| inc = a.split('.').inject(@include_hash) do |hash, key| hash[key.pluralize.to_sym] end inc[:include] = true end if @include self end |