Class: SimpleJsonApi::IncludeList

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_json_api/include_list.rb

Overview

List of Included associations for a resource

Instance Attribute Summary collapse

Instance Method Summary collapse

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_hashObject (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

#parseObject



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