Class: ActiveGraphql::Model::Configuration
- Inherits:
-
Object
- Object
- ActiveGraphql::Model::Configuration
- Defined in:
- lib/active_graphql/model/configuration.rb
Overview
stores all information for how to handle graphql requets for model
Defined Under Namespace
Classes: Attribute
Instance Method Summary collapse
- #attribute(name, nesting = nil, decorate_with: nil) ⇒ Object
- #attributes(*list, **detailed_attributes) ⇒ Object
- #attributes_graphql_output ⇒ Object
- #formatter(new_formatter = nil, &block) ⇒ Object
- #graphql_client(client = nil) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #initialize_copy(other) ⇒ Object
- #primary_key(value = nil) ⇒ Object
- #resource_name(value = nil) ⇒ Object
- #resource_plural_name(value = nil) ⇒ Object
- #url(value = nil) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
21 22 23 24 |
# File 'lib/active_graphql/model/configuration.rb', line 21 def initialize @attributes = [] @primary_key = :id end |
Instance Method Details
#attribute(name, nesting = nil, decorate_with: nil) ⇒ Object
55 56 57 |
# File 'lib/active_graphql/model/configuration.rb', line 55 def attribute(name, nesting = nil, decorate_with: nil) @attributes << Attribute.new(name, nesting: nesting, decorate_with: decorate_with) end |
#attributes(*list, **detailed_attributes) ⇒ Object
45 46 47 48 49 |
# File 'lib/active_graphql/model/configuration.rb', line 45 def attributes(*list, **detailed_attributes) list.each { |name| attribute(name) } detailed_attributes.each { |key, val| attribute(key, val) } @attributes end |
#attributes_graphql_output ⇒ Object
51 52 53 |
# File 'lib/active_graphql/model/configuration.rb', line 51 def attributes_graphql_output attributes.map(&:to_graphql_output) end |
#formatter(new_formatter = nil, &block) ⇒ Object
40 41 42 43 |
# File 'lib/active_graphql/model/configuration.rb', line 40 def formatter(new_formatter = nil, &block) @formatter = new_formatter || block if new_formatter || block @formatter ||= Model::ActionFormatter end |
#graphql_client(client = nil) ⇒ Object
35 36 37 38 |
# File 'lib/active_graphql/model/configuration.rb', line 35 def graphql_client(client = nil) @graphql_client = client if client @graphql_client ||= ActiveGraphql::Client.new(url: url) end |
#initialize_copy(other) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/active_graphql/model/configuration.rb', line 26 def initialize_copy(other) super @attributes = other.attributes.dup @graphql_client = other.graphql_client @url = other.url.dup @resource_name = other.resource_name.dup @resource_plural_name = other.resource_plural_name.dup end |
#primary_key(value = nil) ⇒ Object
71 72 73 |
# File 'lib/active_graphql/model/configuration.rb', line 71 def primary_key(value = nil) update_or_return_config(:primary_key, value&.to_sym) end |
#resource_name(value = nil) ⇒ Object
63 64 65 |
# File 'lib/active_graphql/model/configuration.rb', line 63 def resource_name(value = nil) update_or_return_config(:resource_name, value) end |
#resource_plural_name(value = nil) ⇒ Object
67 68 69 |
# File 'lib/active_graphql/model/configuration.rb', line 67 def resource_plural_name(value = nil) update_or_return_config(:resource_plural_name, value) end |
#url(value = nil) ⇒ Object
59 60 61 |
# File 'lib/active_graphql/model/configuration.rb', line 59 def url(value = nil) update_or_return_config(:url, value) end |