Module: Ecoportal::API::GraphQL::Concerns::FragmentDefinitions::ClassMethods

Defined in:
lib/ecoportal/api/graphql/concerns/fragment_definitions.rb

Instance Method Summary collapse

Instance Method Details

#assemble(*syms) ⇒ Object

Returns concatenated fragment definition strings for the given symbols. Searches own fragments and all registered sub-namespaces.



38
39
40
41
# File 'lib/ecoportal/api/graphql/concerns/fragment_definitions.rb', line 38

def assemble(*syms)
  all = namespaces.reduce(fragments.dup) { |h, ns| h.merge(ns.fragments) }
  syms.map { |sym| all[sym] }.compact.join("\n\n")
end

#fragment(sym, heredoc) ⇒ Object



19
20
21
# File 'lib/ecoportal/api/graphql/concerns/fragment_definitions.rb', line 19

def fragment(sym, heredoc)
  fragments[sym] = heredoc
end

#fragmentsObject



23
24
25
# File 'lib/ecoportal/api/graphql/concerns/fragment_definitions.rb', line 23

def fragments
  @fragments ||= {}
end

#namespacesObject



32
33
34
# File 'lib/ecoportal/api/graphql/concerns/fragment_definitions.rb', line 32

def namespaces
  @namespaces ||= []
end

#register_namespace(klass) ⇒ Object

Register a sub-namespace class whose fragments are visible via assemble.



28
29
30
# File 'lib/ecoportal/api/graphql/concerns/fragment_definitions.rb', line 28

def register_namespace(klass)
  namespaces << klass
end