Method: GraphQL::Language::Nodes::AbstractNode.inherited

Defined in:
lib/graphql/language/nodes.rb

.inherited(child_class) ⇒ Object

Add a default #visit_method and #children_method_name using the class name



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/graphql/language/nodes.rb', line 137

def inherited(child_class)
  super
  name_underscored = child_class.name
    .split("::").last
    .gsub(/([a-z])([A-Z])/,'\1_\2') # insert underscores
    .downcase # remove caps

  child_class.module_eval <<-RUBY
    def visit_method
      :on_#{name_underscored}
    end

    class << self
      attr_accessor :children_method_name
    end
    self.children_method_name = :#{name_underscored}s
  RUBY
end