Module: ValidatesTimeliness::ORM::ActiveModel::ClassMethods
- Defined in:
- lib/validates_timeliness/orm/active_model.rb
Instance Method Summary collapse
- #define_attribute_methods(*attr_names) ⇒ Object
- #define_attribute_timeliness_methods(attr_name, before_type_cast = false) ⇒ Object
- #define_timeliness_before_type_cast_method(attr_name) ⇒ Object
- #define_timeliness_methods(before_type_cast = false) ⇒ Object
- #define_timeliness_write_method(attr_name) ⇒ Object
- #generated_timeliness_methods ⇒ Object
- #undefine_attribute_methods ⇒ Object
- #undefine_timeliness_attribute_methods ⇒ Object
Instance Method Details
#define_attribute_methods(*attr_names) ⇒ Object
9 10 11 |
# File 'lib/validates_timeliness/orm/active_model.rb', line 9 def define_attribute_methods(*attr_names) super.tap { define_timeliness_methods } end |
#define_attribute_timeliness_methods(attr_name, before_type_cast = false) ⇒ Object
36 37 38 39 |
# File 'lib/validates_timeliness/orm/active_model.rb', line 36 def define_attribute_timeliness_methods(attr_name, before_type_cast=false) define_timeliness_write_method(attr_name) define_timeliness_before_type_cast_method(attr_name) if before_type_cast end |
#define_timeliness_before_type_cast_method(attr_name) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/validates_timeliness/orm/active_model.rb', line 52 def define_timeliness_before_type_cast_method(attr_name) generated_timeliness_methods.module_eval " def \#{attr_name}_before_type_cast\n read_timeliness_attribute_before_type_cast('\#{attr_name}')\n end\n STR\nend\n", __FILE__, __LINE__ + 1 |
#define_timeliness_methods(before_type_cast = false) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/validates_timeliness/orm/active_model.rb', line 17 def define_timeliness_methods(before_type_cast=false) return if timeliness_validated_attributes.blank? timeliness_validated_attributes.each do |attr_name| define_attribute_timeliness_methods(attr_name, before_type_cast) end end |
#define_timeliness_write_method(attr_name) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/validates_timeliness/orm/active_model.rb', line 41 def define_timeliness_write_method(attr_name) generated_timeliness_methods.module_eval " def \#{attr_name}=(value)\n @timeliness_cache ||= {}\n @timeliness_cache['\#{attr_name}'] = value\n\n @attributes['\#{attr_name}'] = super\n end\n STR\nend\n", __FILE__, __LINE__ + 1 |
#generated_timeliness_methods ⇒ Object
24 25 26 27 28 |
# File 'lib/validates_timeliness/orm/active_model.rb', line 24 def generated_timeliness_methods @generated_timeliness_methods ||= Module.new { |m| extend Mutex_m }.tap { |mod| include mod } end |
#undefine_attribute_methods ⇒ Object
13 14 15 |
# File 'lib/validates_timeliness/orm/active_model.rb', line 13 def undefine_attribute_methods super.tap { undefine_timeliness_attribute_methods } end |
#undefine_timeliness_attribute_methods ⇒ Object
30 31 32 33 34 |
# File 'lib/validates_timeliness/orm/active_model.rb', line 30 def undefine_timeliness_attribute_methods generated_timeliness_methods.module_eval do instance_methods.each { |m| undef_method(m) } end end |