Class: Unchained::Client::Mixins::Resource::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/unchained/client/mixins/resource.rb

Overview

An Attribute is what attribute creates.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/unchained/client/mixins/resource.rb', line 24

def name
  @name
end

#optsObject (readonly)

Returns the value of attribute opts.



26
27
28
# File 'lib/unchained/client/mixins/resource.rb', line 26

def opts
  @opts
end

#typeObject (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.

Returns:

  • (Boolean)


49
50
51
# File 'lib/unchained/client/mixins/resource.rb', line 49

def allow_nil?
  @opts.fetch(:allow_nil, false)
end

#expand_methodObject

Some of the attributes can be expanded.



54
55
56
# File 'lib/unchained/client/mixins/resource.rb', line 54

def expand_method
  @opts.fetch(:expand, nil)
end

#json_fieldObject

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