Class: GraphQLIncludable::IncludesBuilder
- Inherits:
-
Object
- Object
- GraphQLIncludable::IncludesBuilder
- Defined in:
- lib/graphql_includable/includes_builder.rb
Instance Attribute Summary collapse
-
#included_path ⇒ Object
readonly
Returns the value of attribute included_path.
-
#includes ⇒ Object
readonly
Returns the value of attribute includes.
Instance Method Summary collapse
- #active_record_includes ⇒ Object
- #includes? ⇒ Boolean
-
#initialize(only_one_path: true) ⇒ IncludesBuilder
constructor
A new instance of IncludesBuilder.
- #path(*symbols, &block) ⇒ Object
- #path_leaf_includes ⇒ Object
- #sibling_path(*symbols, &block) ⇒ Object
Constructor Details
#initialize(only_one_path: true) ⇒ IncludesBuilder
Returns a new instance of IncludesBuilder.
5 6 7 8 9 |
# File 'lib/graphql_includable/includes_builder.rb', line 5 def initialize(only_one_path: true) @only_one_path = only_one_path @included_path = [] @includes = GraphQLIncludable::Includes.new(nil) end |
Instance Attribute Details
#included_path ⇒ Object (readonly)
Returns the value of attribute included_path.
3 4 5 |
# File 'lib/graphql_includable/includes_builder.rb', line 3 def included_path @included_path end |
#includes ⇒ Object (readonly)
Returns the value of attribute includes.
3 4 5 |
# File 'lib/graphql_includable/includes_builder.rb', line 3 def includes @includes end |
Instance Method Details
#active_record_includes ⇒ Object
15 16 17 |
# File 'lib/graphql_includable/includes_builder.rb', line 15 def active_record_includes @includes.active_record_includes end |
#includes? ⇒ Boolean
11 12 13 |
# File 'lib/graphql_includable/includes_builder.rb', line 11 def includes? @included_path.present? end |
#path(*symbols, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/graphql_includable/includes_builder.rb', line 23 def path(*symbols, &block) raise ArgumentError, 'Can only add path once' if @included_path.present? && @only_one_path if symbols.present? first, *rest = symbols includes = @includes.add_child(first) rest.each do |key| includes = includes.add_child(key) end else includes = @includes end if block_given? nested = GraphQLIncludable::IncludesBuilder.new nested.instance_eval(&block) symbols += nested.included_path includes.merge_includes(nested.includes) end @included_path = symbols end |
#path_leaf_includes ⇒ Object
19 20 21 |
# File 'lib/graphql_includable/includes_builder.rb', line 19 def path_leaf_includes @includes.dig(included_path) end |
#sibling_path(*symbols, &block) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/graphql_includable/includes_builder.rb', line 45 def sibling_path(*symbols, &block) if symbols.present? first, *rest = symbols includes = @includes.add_child(first) rest.each do |key| includes = includes.add_child(key) end else includes = @includes end return unless block_given? nested = GraphQLIncludable::IncludesBuilder.new(only_one_path: false) nested.instance_eval(&block) includes.merge_includes(nested.includes) end |