Module: Aduki::ClassMethods

Defined in:
lib/aduki.rb

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#aduki(types) ⇒ Object



157
158
159
160
161
162
163
164
165
# File 'lib/aduki.rb', line 157

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



167
168
169
170
171
172
173
174
175
176
# File 'lib/aduki.rb', line 167

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



178
179
180
181
# File 'lib/aduki.rb', line 178

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

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



187
188
189
# File 'lib/aduki.rb', line 187

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



191
192
193
# File 'lib/aduki.rb', line 191

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

#get_aduki_initializersObject



183
184
185
# File 'lib/aduki.rb', line 183

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