Module: GraphQL::Definable

Included in:
Directive, Enum, Field, ObjectType
Defined in:
lib/graph_ql/definition_helpers/definable.rb

Overview

Define attributes which can be assigned & read, or “defined”, by passing the new value as an argument

Examples:

defining an object’s name

object.name("New name")

Instance Method Summary collapse

Instance Method Details

#attr_definable(*names) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/graph_ql/definition_helpers/definable.rb', line 8

def attr_definable(*names)
  attr_accessor(*names)
  names.each do |name|
    ivar_name = "@#{name}".to_sym
    define_method(name) do |new_value=nil|
      new_value && self.instance_variable_set(ivar_name, new_value)
      instance_variable_get(ivar_name)
    end
  end
end