Module: Aduki::ClassMethods

Defined in:
lib/aduki.rb

Constant Summary collapse

@@types =
{ }
@@initializers =
{ }

Instance Method Summary collapse

Instance Method Details

#aduki(types) ⇒ Object



141
142
143
144
145
146
147
148
149
# File 'lib/aduki.rb', line 141

def aduki types
  @@types[self] ||= { }
  @@types[self] = @@types[self].merge types
  types.each do |attr, k|
    attr = attr.to_sym
    attr_reader attr unless method_defined? attr
    attr_writer attr unless method_defined? :"#{attr}="
  end
end

#aduki_initialize(name, initial_klass, type = :notset) ⇒ Object



151
152
153
154
155
156
157
158
159
160
# File 'lib/aduki.rb', line 151

def aduki_initialize name, initial_klass, type=:notset
  type = (type == :notset) ? initial_klass : type
  aduki(name => type) if type
  initializer_name = :"aduki_initialize_#{name}"
  define_method initializer_name do
    send :"#{name}=", initial_klass.new
  end
  @@initializers[self] ||= []
  @@initializers[self] << initializer_name
end

#aduki_type_for_attribute_name(name) ⇒ Object



162
163
164
165
# File 'lib/aduki.rb', line 162

def aduki_type_for_attribute_name name
  hsh = @@types[self]
  hsh ? hsh[name.to_sym] : nil
end

#attr_finder(finder, id, *args) ⇒ Object



171
172
173
# File 'lib/aduki.rb', line 171

def attr_finder finder, id, *args
  class_eval Aduki::AttrFinder.attr_finders_text(finder, id, *args)
end

#attr_many_finder(finder, id, name, options = { }) ⇒ Object



175
176
177
# File 'lib/aduki.rb', line 175

def attr_many_finder finder, id, name, options={ }
  class_eval Aduki::AttrFinder.one2many_attr_finder_text(finder, id, name, options)
end

#get_aduki_initializersObject



167
168
169
# File 'lib/aduki.rb', line 167

def get_aduki_initializers
  @@initializers[self] || []
end