Class: Graphoid::Attribute

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

Constant Summary collapse

PERMS =
%i[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.



9
10
11
12
13
# File 'lib/graphoid/operators/attribute.rb', line 9

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/graphoid/operators/attribute.rb', line 5

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/graphoid/operators/attribute.rb', line 5

def type
  @type
end

Class Method Details

.correct(model, attributes) ⇒ Object



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

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



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

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

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



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

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



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

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



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

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

Instance Method Details

#create(_, _, _) ⇒ Object



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

def create(_, _, _); end

#embedded?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/graphoid/operators/attribute.rb', line 19

def embedded?
  false
end

#precreate(value) ⇒ Object



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

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

#relation?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/graphoid/operators/attribute.rb', line 23

def relation?
  false
end

#resolve(o) ⇒ Object



15
16
17
# File 'lib/graphoid/operators/attribute.rb', line 15

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