Module: ConstantTableSaver::NameClassMethods
- Defined in:
- lib/constant_table_saver.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *arguments, &block) ⇒ Object
214
215
216
217
218
219
220
221
|
# File 'lib/constant_table_saver.rb', line 214
def method_missing(method_id, *arguments, &block)
if @constant_record_methods.nil?
define_named_record_methods
send(method_id, *arguments, &block) else
super
end
end
|
Instance Method Details
#define_named_record_methods ⇒ Object
200
201
202
203
204
205
206
207
208
|
# File 'lib/constant_table_saver.rb', line 200
def define_named_record_methods
@constant_record_methods = [] @constant_record_methods = all.collect do |record|
method_name = "#{constant_table_options[:name_prefix]}#{record[constant_table_options[:name]].downcase.gsub(/\W+/, '_')}#{constant_table_options[:name_suffix]}"
next if method_name.blank?
(class << self; self; end;).instance_eval { define_method(method_name) { record } }
method_name.to_sym
end.compact.uniq
end
|
#respond_to?(method_id, include_private = false) ⇒ Boolean
210
211
212
|
# File 'lib/constant_table_saver.rb', line 210
def respond_to?(method_id, include_private = false)
super || (@constant_record_methods.nil? && @attribute_methods_generated && define_named_record_methods && super)
end
|