lib/jsonapi/include_directives.rb in jsonapi-resources-0.4.2 vs lib/jsonapi/include_directives.rb in jsonapi-resources-0.4.3
- old
+ new
@@ -1,29 +1,28 @@
module JSONAPI
class 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
+ # posts:{
+ # include:true,
+ # include_related:{
+ # comments:{
+ # include:true,
+ # include_related:{
+ # tags:{
+ # include:true
# }
# }
# }
# }
# }
# }
def initialize(includes_array)
- @include_directives_hash = {include_related: {}}
+ @include_directives_hash = { include_related: {} }
includes_array.each do |include|
parse_include(include)
end
end
@@ -34,14 +33,15 @@
def model_includes
get_includes(@include_directives_hash)
end
private
+
def get_related(current_path)
current = @include_directives_hash
current_path.split('.').each do |fragment|
fragment = fragment.to_sym
- current[:include_related][fragment] ||= {include: false, include_related: {}}
+ current[:include_related][fragment] ||= { include: false, include_related: {} }
current = current[:include_related][fragment]
end
current
end