Class: JSONAPI::IncludeDirectives

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonapi/include_directives.rb

Instance Method Summary collapse

Constructor Details

#initialize(includes_array) ⇒ IncludeDirectives

Construct an IncludeDirectives Hash from an array of dot separated include strings. For example ['posts.comments.tags'] will transform into => {

posts:{
  include:true,
  include_related:{
    comments:{
      include:true,
      include_related:{
        tags:{
          include:true
        }
      }
    }
  }
}

}


22
23
24
25
26
27
# File 'lib/jsonapi/include_directives.rb', line 22

def initialize(includes_array)
  @include_directives_hash = { include_related: {} }
  includes_array.each do |include|
    parse_include(include)
  end
end

Instance Method Details

#include_directivesObject


29
30
31
# File 'lib/jsonapi/include_directives.rb', line 29

def include_directives
  @include_directives_hash
end

#model_includesObject


33
34
35
# File 'lib/jsonapi/include_directives.rb', line 33

def model_includes
  get_includes(@include_directives_hash)
end