class Graphoid::Operation
Attributes
operand[R]
operator[R]
scope[R]
value[R]
Public Class Methods
new(scope, key, value)
click to toggle source
# File lib/graphoid/queries/operation.rb, line 7 def initialize(scope, key, value) @scope = scope @operator = nil @operand = key @value = value match = key.match(/^(.+)_(.+)$/) @operand, @operator = match[1..2] if match @operand = build_operand(@scope, @operand) || @operand end
Public Instance Methods
resolve()
click to toggle source
# File lib/graphoid/queries/operation.rb, line 18 def resolve @operand.resolve(self) end
Private Instance Methods
build_operand(model, key)
click to toggle source
# File lib/graphoid/queries/operation.rb, line 24 def build_operand(model, key) fields = Attribute.fields_of(model) field = fields.find { |f| f.name == key } return Attribute.new(name: key, type: field.type) if field field = fields.find { |f| f.name == key.underscore } return Attribute.new(name: key.underscore, type: field.type) if field relations = model.reflect_on_all_associations relation = relations.find { |r| r.name == key.to_sym } return Graphoid.driver.class_of(relation).new(relation) if relation relation = relations.find { |r| r.name == key.underscore.to_sym } return Graphoid.driver.class_of(relation).new(relation) if relation end