Class: Graphoid::Attribute
- Inherits:
-
Object
- Object
- Graphoid::Attribute
- Defined in:
- lib/graphoid/operators/attribute.rb
Constant Summary collapse
- PERMS =
%i[read create update delete]
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
- .correct(model, attributes) ⇒ Object
- .fieldnames_of(model, action = :read) ⇒ Object
- .fields_of(model, action = :read) ⇒ Object
- .forbidden_fields_of(model, action) ⇒ Object
- .graphields_of(model) ⇒ Object
Instance Method Summary collapse
- #create(_, _, _) ⇒ Object
- #embedded? ⇒ Boolean
-
#initialize(name:, type:) ⇒ Attribute
constructor
A new instance of Attribute.
- #precreate(value) ⇒ Object
- #relation? ⇒ Boolean
- #resolve(o) ⇒ Object
Constructor Details
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/graphoid/operators/attribute.rb', line 5 def name @name end |
#type ⇒ Object (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
19 20 21 |
# File 'lib/graphoid/operators/attribute.rb', line 19 def 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
23 24 25 |
# File 'lib/graphoid/operators/attribute.rb', line 23 def relation? false end |