Module: GraphQL::Schema::Member::AcceptsDefinition::AcceptsDefinitionDefinitionMethods Private

Defined in:
lib/graphql/schema/member/accepts_definition.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#accepts_definition(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/graphql/schema/member/accepts_definition.rb', line 63

def accepts_definition(name)
  own_accepts_definition_methods << name

  ivar_name = "@#{name}_args"
  if self.is_a?(Class)
    define_singleton_method(name) do |*args|
      if args.any?
        instance_variable_set(ivar_name, args)
      end
      instance_variable_get(ivar_name) || (superclass.respond_to?(name) ? superclass.public_send(name) : nil)
    end

    define_method(name) do |*args|
      if args.any?
        instance_variable_set(ivar_name, args)
      end
      instance_variable_get(ivar_name)
    end
  else
    # Special handling for interfaces, define it here
    # so it's appropriately passed down
    self::DefinitionMethods.module_eval do
      define_method(name) do |*args|
        if args.any?
          instance_variable_set(ivar_name, args)
        else
          if (v = instance_variable_get(ivar_name))
            v
          elsif (ancestor = ancestors.find { |i| i.respond_to?(name) && i != self })
            ancestor.public_send(name)
          else
            nil
          end
        end
      end
    end
  end
end

#accepts_definition_methodsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/graphql/schema/member/accepts_definition.rb', line 102

def accepts_definition_methods
  inherited_methods = if self.is_a?(Class)
    superclass.respond_to?(:accepts_definition_methods) ? superclass.accepts_definition_methods : []
  elsif self.is_a?(Module)
    m = []
    ancestors.each do |a|
      if a.respond_to?(:own_accepts_definition_methods)
        m.concat(a.own_accepts_definition_methods)
      end
    end
    m
  else
    self.class.accepts_definition_methods
  end

  own_accepts_definition_methods + inherited_methods
end

#own_accepts_definition_methodsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



120
121
122
# File 'lib/graphql/schema/member/accepts_definition.rb', line 120

def own_accepts_definition_methods
  @own_accepts_definition_methods ||= []
end