Module: Morpheus::Mixins::Attributes::ClassMethods

Defined in:
lib/morpheus/mixins/attributes.rb

Instance Method Summary collapse

Instance Method Details

#attribute_defined?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/morpheus/mixins/attributes.rb', line 26

def attribute_defined?(attribute)
  default_attributes.keys.include?(attribute.to_s)
end

#default_attributesObject



18
19
20
# File 'lib/morpheus/mixins/attributes.rb', line 18

def default_attributes
  @attributes ||= HashWithIndifferentAccess.new(superclass.respond_to?(:default_attributes) ? superclass.default_attributes : {})
end

#property(name, typecast_class = nil) ⇒ Object



11
12
13
14
15
16
# File 'lib/morpheus/mixins/attributes.rb', line 11

def property(name, typecast_class = nil)
  typecast_attributes.store(name.to_sym, typecast_class)
  default_attributes.store(name.to_sym, nil)

  define_attribute_accessor(name)
end

#typecast_attributesObject



22
23
24
# File 'lib/morpheus/mixins/attributes.rb', line 22

def typecast_attributes
  @typecast_attributes ||= HashWithIndifferentAccess.new(superclass.respond_to?(:default_attributes) ? superclass.default_attributes : {})
end