Class: Ecoportal::API::GraphQL::Fragment

Inherits:
Object
  • Object
show all
Includes:
Common::GraphQL::ClassHelpers
Defined in:
lib/ecoportal/api/graphql/fragment.rb,
lib/ecoportal/api/graphql/fragment/action.rb,
lib/ecoportal/api/graphql/fragment/pagination.rb,
lib/ecoportal/api/graphql/fragment/location_node.rb,
lib/ecoportal/api/graphql/fragment/location_draft.rb,
lib/ecoportal/api/graphql/fragment/action_category.rb,
lib/ecoportal/api/graphql/fragment/locations_error.rb,
lib/ecoportal/api/graphql/fragment/contractor_entity.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Fragment

Returns a new instance of Fragment.



25
26
27
28
# File 'lib/ecoportal/api/graphql/fragment.rb', line 25

def initialize(client)
  @client = client
  parse
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

#fragmentsObject (readonly)

Returns the value of attribute fragments.



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

def fragments
  @fragments
end

Class Method Details

.fragment(sym, heredoc) ⇒ Object



14
15
16
# File 'lib/ecoportal/api/graphql/fragment.rb', line 14

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

.fragmentsObject



18
19
20
# File 'lib/ecoportal/api/graphql/fragment.rb', line 18

def fragments
  @fragments ||= {}
end

Instance Method Details

#define(sym, heredoc, namespace: ::Fragment) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ecoportal/api/graphql/fragment.rb', line 30

def define(sym, heredoc, namespace: ::Fragment)
  namespace.send(:remove_const, sym) if namespace.const_defined?(sym)

  client.parse(heredoc).tap do |fragment|
    without_warnings do
      namespace.const_set(sym, fragment)
      ::Fragment.const_set(sym, fragment) unless namespace == ::Fragment
    end
  end
rescue ::GraphQL::Client::ValidationError, ::Graphlient::Errors::ClientError => err
  raise err.class, "On fragment #{sym} -- #{err.message}", cause: nil
end