Class: Apia::Definitions::Field
- Inherits:
-
Apia::Definition
- Object
- Apia::Definition
- Apia::Definitions::Field
- Defined in:
- lib/apia/definitions/field.rb
Instance Attribute Summary collapse
-
#array ⇒ Object
Returns the value of attribute array.
-
#backend ⇒ Object
Returns the value of attribute backend.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#description ⇒ Object
Returns the value of attribute description.
-
#include ⇒ Object
Returns the value of attribute include.
-
#null ⇒ Object
Returns the value of attribute null.
-
#type ⇒ Class
Return the type of object.
Attributes inherited from Apia::Definition
Instance Method Summary collapse
-
#array? ⇒ Boolean
Is the result from this field expected to be an array?.
-
#dsl ⇒ Apia::DSLs::Field
Return a DSL instance for this field.
-
#include?(value, request) ⇒ Boolean
Should this field be inclued for the given value and request.
-
#initialize(name, id: nil) ⇒ Field
constructor
A new instance of Field.
-
#null? ⇒ Boolean
Can the result for thsi field be nil?.
-
#raw_value_from_object(object) ⇒ Object
Return the backend value from the given object based on the rules that exist for this field.
-
#value(object, request: nil, path: []) ⇒ Object
Return an instance of a Type or a Scalar for this field.
Methods inherited from Apia::Definition
Constructor Details
#initialize(name, id: nil) ⇒ Field
Returns a new instance of Field.
22 23 24 25 |
# File 'lib/apia/definitions/field.rb', line 22 def initialize(name, id: nil) @name = name @id = id end |
Instance Attribute Details
#array ⇒ Object
Returns the value of attribute array.
16 17 18 |
# File 'lib/apia/definitions/field.rb', line 16 def array @array end |
#backend ⇒ Object
Returns the value of attribute backend.
15 16 17 |
# File 'lib/apia/definitions/field.rb', line 15 def backend @backend end |
#condition ⇒ Object
Returns the value of attribute condition.
18 19 20 |
# File 'lib/apia/definitions/field.rb', line 18 def condition @condition end |
#description ⇒ Object
Returns the value of attribute description.
14 15 16 |
# File 'lib/apia/definitions/field.rb', line 14 def description @description end |
#include ⇒ Object
Returns the value of attribute include.
20 21 22 |
# File 'lib/apia/definitions/field.rb', line 20 def include @include end |
#null ⇒ Object
Returns the value of attribute null.
17 18 19 |
# File 'lib/apia/definitions/field.rb', line 17 def null @null end |
Instance Method Details
#array? ⇒ Boolean
Is the result from this field expected to be an array?
44 45 46 |
# File 'lib/apia/definitions/field.rb', line 44 def array? @array == true end |
#dsl ⇒ Apia::DSLs::Field
Return a DSL instance for this field
62 63 64 |
# File 'lib/apia/definitions/field.rb', line 62 def dsl @dsl ||= DSLs::Field.new(self) end |
#include?(value, request) ⇒ Boolean
Should this field be inclued for the given value and request
53 54 55 56 57 |
# File 'lib/apia/definitions/field.rb', line 53 def include?(value, request) return true if @condition.nil? @condition.call(value, request) == true end |
#null? ⇒ Boolean
Can the result for thsi field be nil?
37 38 39 |
# File 'lib/apia/definitions/field.rb', line 37 def null? @null == true end |
#raw_value_from_object(object) ⇒ Object
Return the backend value from the given object based on the rules that exist for this field.
71 72 73 74 75 76 77 |
# File 'lib/apia/definitions/field.rb', line 71 def raw_value_from_object(object) if @backend get_value_from_backend(object) else get_value_directly_from_object(object, @name) end end |
#value(object, request: nil, path: []) ⇒ Object
Return an instance of a Type or a Scalar for this field
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/apia/definitions/field.rb', line 83 def value(object, request: nil, path: []) raw_value = raw_value_from_object(object) return nil if raw_value.nil? && null? raise Apia::NullFieldValueError.new(self, object) if raw_value.nil? if array? && raw_value.is_a?(Array) raw_value.map { |v| type.cast(v, request: request, path: path) } else type.cast(raw_value, request: request, path: path) end end |