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

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, **attribute_options)
  key = attribute_name.to_s

  attributes[key] ||= build_attribute(attribute_name).tap do |new_attribute|
    new_attribute.with(**attribute_options) unless attribute_options.empty?
    yield(new_attribute) if block_given?
  end
end

#attributesObject



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_nameObject



35
36
37
# File 'lib/graphql_rails/model/configurable.rb', line 35

def type_name
  @type_name ||= "#{name.camelize}Type#{SecureRandom.hex}"
end