Module: GraphqlRails::Model::Configurable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Configuration, Input
- Defined in:
- lib/graphql_rails/model/configurable.rb
Overview
Contains methods which are shared between various configurations.
Expects ‘default_name` to be defined. Expects `build_attribute(attr_name)` method to be defined.
Instance Method Summary collapse
- #attribute(attribute_name, **attribute_options) ⇒ Object
- #attributes ⇒ Object
- #initialize_copy(other) ⇒ Object
- #name(*args) ⇒ Object
- #type_name ⇒ Object
Instance Method Details
#attribute(attribute_name, **attribute_options) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/graphql_rails/model/configurable.rb', line 39 def attribute(attribute_name, **) key = attribute_name.to_s attributes[key] ||= build_attribute(attribute_name).tap do |new_attribute| new_attribute.with(**) unless .empty? yield(new_attribute) if block_given? end end |
#attributes ⇒ Object
27 28 29 |
# File 'lib/graphql_rails/model/configurable.rb', line 27 def attributes @attributes ||= {} end |
#initialize_copy(other) ⇒ Object
21 22 23 24 25 |
# File 'lib/graphql_rails/model/configurable.rb', line 21 def initialize_copy(other) super @type_name = nil @attributes = other.attributes.transform_values(&:dup) end |
#name(*args) ⇒ Object
31 32 33 |
# File 'lib/graphql_rails/model/configurable.rb', line 31 def name(*args) get_or_set_chainable_option(:name, *args) || default_name end |
#type_name ⇒ Object
35 36 37 |
# File 'lib/graphql_rails/model/configurable.rb', line 35 def type_name @type_name ||= "#{name.camelize}Type#{SecureRandom.hex}" end |