class Statham::AttributeSet
Public: Collection of definition of child attributes inside JSON.
Attributes
name[R]
Public: Name of the parent JSON attribute.
parent[R]
Public: AttributeSet
defined in the parent class of the owner of the AttributeSet
.
Public Class Methods
new(options = {})
click to toggle source
Internal: Initialize an AttributeSet
.
options - The hash options used to define AttributeSets:
:name - Name of the parent attribute.
Returns new AttributeSet
.
# File lib/statham/attribute_set.rb, line 16 def initialize(options = {}) @name = options[:name] @parent = options[:parent] @attributes = {} end
Public Instance Methods
attribute(name, options = {})
click to toggle source
Public: Define an attribute serialized inside JSON.
name - Name of the attribute. options - The hash options used to define new attribute:
:type - Type of the attribute. :default - Default value for the attribute.
Returns nothing.
# File lib/statham/attribute_set.rb, line 30 def attribute(name, options = {}) @attributes[name] = Statham::Attribute.new(options) end
attributes()
click to toggle source
Public: Collection of attributes definition. If parent AttributeSet
exists, it merges attributes on the AttributeSet
with attributes of parent.
Returns Hash collection of attributes.
# File lib/statham/attribute_set.rb, line 39 def attributes if @parent @attributes.reverse_merge @parent.attributes else @attributes end end