Class: SuperValue::Base
- Inherits:
-
Object
- Object
- SuperValue::Base
- Includes:
- ActiveSupport::Callbacks
- Defined in:
- lib/super_value/base.rb
Class Method Summary collapse
- .after_init(method_name = nil, &block) ⇒ Object
- .before_init(method_name = nil, &block) ⇒ Object
- .init(model_name) ⇒ Object
- .property(method_name) ⇒ Object
Class Method Details
.after_init(method_name = nil, &block) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/super_value/base.rb', line 30 def after_init(method_name=nil, &block) if block_given? set_callback :init, :after, &block else set_callback :init, :after, method_name end end |
.before_init(method_name = nil, &block) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/super_value/base.rb', line 22 def before_init(method_name=nil, &block) if block_given? set_callback :init, :before, &block else set_callback :init, :before, method_name end end |
.init(model_name) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/super_value/base.rb', line 8 def init(model_name) self.model_name = model_name self.send(:attr_accessor, model_name) define_method :initialize do |model| run_callbacks :init do self.send("#{model_name}=", model) end end end |
.property(method_name) ⇒ Object
18 19 20 |
# File 'lib/super_value/base.rb', line 18 def property(method_name) delegate method_name, to: model_name end |