Module: Attrio::ClassMethods

Defined in:
lib/attrio.rb

Instance Method Summary collapse

Instance Method Details

#const_missing(name) ⇒ Object



44
45
46
# File 'lib/attrio.rb', line 44

def const_missing(name)
  Attrio::AttributesParser.cast_type(name) || super
end

#define_attributes(options = {}, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/attrio.rb', line 29

def define_attributes(options = {}, &block)
  options[:as] ||= :attributes
  
  cattr_accessor options[:as].to_sym
  class_eval(<<-EOS)
    @@#{options[:as].to_s} ||= {}
  EOS

  self.define_attrio_new(options[:as])
  self.define_attrio_reset(options[:as])
  self.define_attrio_inspect(options[:as]) unless options[:inspect] == false

  Attrio::AttributesParser.new(self, options, &block)
end