Class: Graphoid::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/graphoid/operators/attribute.rb

Constant Summary collapse

PERMS =
[:read, :create, :update, :delete]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type:) ⇒ Attribute

Returns a new instance of Attribute.



7
8
9
10
11
# File 'lib/graphoid/operators/attribute.rb', line 7

def initialize(name:, type:)
  @name = name.to_s
  @camel_name = Utils.camelize(@name)
  @type = type
end

Instance Attribute Details

#name ⇒ Object (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/graphoid/operators/attribute.rb', line 3

def name
  @name
end

#type ⇒ Object (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/graphoid/operators/attribute.rb', line 3

def type
  @type
end

Class Method Details

.correct(model, attributes) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/graphoid/operators/attribute.rb', line 53

def correct(model, attributes)
  result = {}
  fieldnames = fieldnames_of(model)
  attributes.each do |key, value|
    key = key.to_s.underscore if fieldnames.exclude?(key.to_s)
    result[key] = value
  end
  result
end

.fieldnames_of(model, action = :read) ⇒ Object



38
39
40
# File 'lib/graphoid/operators/attribute.rb', line 38

def fieldnames_of(model, action = :read)
  fields_of(model, action).map(&:name)
end

.fields_of(model, action = :read) ⇒ Object



33
34
35
36
# File 'lib/graphoid/operators/attribute.rb', line 33

def fields_of(model, action = :read)
  fields = Graphoid.driver.fields_of(model) + graphields_of(model)
  fields.select { |field| forbidden_fields_of(model, action).exclude?(field.name) }
end

.forbidden_fields_of(model, action) ⇒ Object



46
47
48
49
50
51
# File 'lib/graphoid/operators/attribute.rb', line 46

def forbidden_fields_of(model, action)
  skips = model.respond_to?(:forbidden_fields) ? model.send(:forbidden_fields) : []
  skips.map do |field, actions|
    field.to_s if actions.empty? || actions.include?(action)
  end
end

.graphields_of(model) ⇒ Object



42
43
44
# File 'lib/graphoid/operators/attribute.rb', line 42

def graphields_of(model)
  model.respond_to?(:graphields) ? model.send(:graphields) : []
end

Instance Method Details

#create(_, _, _) ⇒ Object



29
30
# File 'lib/graphoid/operators/attribute.rb', line 29

def create(_,_,_)
end

#embedded? ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/graphoid/operators/attribute.rb', line 17

def embedded?
  false
end

#precreate(value) ⇒ Object



25
26
27
# File 'lib/graphoid/operators/attribute.rb', line 25

def precreate(value)
  { self.name.to_sym => value }
end

#relation? ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/graphoid/operators/attribute.rb', line 21

def relation?
  false
end

#resolve(o) ⇒ Object



13
14
15
# File 'lib/graphoid/operators/attribute.rb', line 13

def resolve(o)
  Graphoid.driver.parse(o.operand, o.value, o.operator)
end