class Bluepine::Attributes::ObjectAttribute
Attributes
attributes[R]
Public Class Methods
new(name, options = {}, &block)
click to toggle source
# File lib/bluepine/attributes/object_attribute.rb, line 11 def initialize(name, options = {}, &block) @name = name @options = options @attributes = {} instance_exec(&block) if block_given? end
Public Instance Methods
[](name)
click to toggle source
# File lib/bluepine/attributes/object_attribute.rb, line 56 def [](name) @attributes[name.to_sym] end
[]=(name, attribute)
click to toggle source
# File lib/bluepine/attributes/object_attribute.rb, line 60 def []=(name, attribute) assert_kind_of Attribute, attribute @attributes[name.to_sym] = attribute end
group(options, &block)
click to toggle source
Apply default options to all attributes
group if: :deleted? { … } group unless: :deleted? { … } group if: ->{ @user.deleted? } { … }
# File lib/bluepine/attributes/object_attribute.rb, line 27 def group(options, &block) return unless block_given? # Use stacks to allow nested conditions self.class.stacks << Attribute.options Attribute.options = options instance_exec(&block) # restore options Attribute.options = self.class.stacks.pop end
keys()
click to toggle source
# File lib/bluepine/attributes/object_attribute.rb, line 66 def keys @attributes.keys end
method_missing(type, name = nil, options = {}, &block)
click to toggle source
Shortcut for creating attribute (delegate call to Registry.create
) This allows us to access newly registered attributes
string :username (or array, number etc)
Calls superclass method
# File lib/bluepine/attributes/object_attribute.rb, line 44 def method_missing(type, name = nil, options = {}, &block) if Attributes.registry.key?(type) @attributes[name] = Attributes.create(type, name, options, &block) else super end end
native_type()
click to toggle source
# File lib/bluepine/attributes/object_attribute.rb, line 18 def native_type "object" end
respond_to_missing?(method, *)
click to toggle source
Calls superclass method
# File lib/bluepine/attributes/object_attribute.rb, line 52 def respond_to_missing?(method, *) super end