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.
-
#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.
27 28 29 30 31 |
# File 'lib/unchained/client/mixins/resource.rb', line 27 def initialize(name, type, opts) @name = name @type = type @opts = opts end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/unchained/client/mixins/resource.rb', line 23 def name @name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
25 26 27 |
# File 'lib/unchained/client/mixins/resource.rb', line 25 def opts @opts end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
24 25 26 |
# File 'lib/unchained/client/mixins/resource.rb', line 24 def type @type end |
Instance Method Details
#allow_nil? ⇒ Boolean
Whether or not to allow nil, defaults to false.
48 49 50 |
# File 'lib/unchained/client/mixins/resource.rb', line 48 def allow_nil? @opts.fetch(:allow_nil, false) 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
43 44 45 |
# File 'lib/unchained/client/mixins/resource.rb', line 43 def json_field @opts.fetch(:json, @name.to_s) end |