Class: Graphoid::Attribute
- Inherits:
-
Object
- Object
- Graphoid::Attribute
- Defined in:
- lib/graphoid/operators/attribute.rb
Constant Summary collapse
- PERMS =
[: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.
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
17 18 19 |
# File 'lib/graphoid/operators/attribute.rb', line 17 def 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
21 22 23 |
# File 'lib/graphoid/operators/attribute.rb', line 21 def relation? false end |