Class: Unchained::Client::Mixins::Resource::Attribute
- Inherits:
-
Object
- Object
- Unchained::Client::Mixins::Resource::Attribute
- Defined in:
- lib/unchained/client/mixins/resource.rb
Overview
An Attribute is what attribute creates.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#allow_nil? ⇒ Boolean
Whether or not to allow nil, defaults to false.
-
#expand_method ⇒ Object
Some of the attributes can be expanded.
-
#initialize(name, type, opts) ⇒ Attribute
constructor
A new instance of Attribute.
-
#json_field ⇒ Object
The field that maps to this attribute in the JSON.
Constructor Details
#initialize(name, type, opts) ⇒ Attribute
Returns a new instance of Attribute.
28 29 30 31 32 |
# File 'lib/unchained/client/mixins/resource.rb', line 28 def initialize(name, type, opts) @name = name @type = type @opts = opts end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'lib/unchained/client/mixins/resource.rb', line 24 def name @name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
26 27 28 |
# File 'lib/unchained/client/mixins/resource.rb', line 26 def opts @opts end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
25 26 27 |
# File 'lib/unchained/client/mixins/resource.rb', line 25 def type @type end |
Instance Method Details
#allow_nil? ⇒ Boolean
Whether or not to allow nil, defaults to false.
49 50 51 |
# File 'lib/unchained/client/mixins/resource.rb', line 49 def allow_nil? @opts.fetch(:allow_nil, false) end |
#expand_method ⇒ Object
Some of the attributes can be expanded.
54 55 56 |
# File 'lib/unchained/client/mixins/resource.rb', line 54 def @opts.fetch(:expand, nil) end |
#json_field ⇒ Object
The field that maps to this attribute in the JSON.
Usage:
# json_field will return 'FOO'
attribute :foo, json: 'FOO'
# json_field will return 'foo_bar'
attribute :foo_bar
44 45 46 |
# File 'lib/unchained/client/mixins/resource.rb', line 44 def json_field @opts.fetch(:json, @name.to_s) end |