Module: Motr::Modding
- Included in:
- Motr::Mods::Sluggable
- Defined in:
- lib/motr/modding.rb
Instance Method Summary collapse
- #append_features(base) ⇒ Object
-
#apply(&block) ⇒ Object
Apply is run each time a mod is applied to a model.
-
#configure(orm = nil, &block) ⇒ Object
Each mod can pass an optional configuration block (or one global config and one per orm) which is run when a particular class or model implements that mod.
-
#options(*options) ⇒ Object
Each mod can specify any number of options that may be passed to it when applied to a class/model.
Instance Method Details
#append_features(base) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/motr/modding.rb', line 9 def append_features(base) return false if base < self super # Apply any orm specific configurations # if instance_variable_defined?("@_mod_config_for_orm") @_mod_config_for_orm.each do |orm, configs| # Each orm should implement a motr_orm_type value which identifies # itself to mods (ie :active_record, :mongoid) next unless base.respond_to?(:motr_orm_type) && base.__send__(:motr_orm_type).to_s === orm.to_s [configs].flatten.each{ |conf| base.class_eval(&conf) } end end base.extend const_get("ClassMethods") if const_defined?("ClassMethods") base.send :include, const_get("InstanceMethods") if const_defined?("InstanceMethods") base.class_eval(&@_mod_config_callback) if instance_variable_defined?("@_mod_config_callback") end |
#apply(&block) ⇒ Object
Apply is run each time a mod is applied to a model. As opposed to the configure method, apply blocks are run each time modded_with :your_mod is called.
43 44 45 |
# File 'lib/motr/modding.rb', line 43 def apply(&block) @_mod_apply_callback = block end |
#configure(orm = nil, &block) ⇒ Object
Each mod can pass an optional configuration block (or one global config and one per orm) which is run when a particular class or model implements that mod. Configure methods are only run on first inclusion. To run functionality each time the mod is applied, see Motr::Mod.apply
Orm specific functionality can be configured by passing an :orm as the first option
73 74 75 76 77 78 79 |
# File 'lib/motr/modding.rb', line 73 def configure(orm = nil, &block) if orm.nil? @_mod_config_callback = block else (@_mod_config_for_orm ||= {})[orm] = block end end |
#options(*options) ⇒ Object
Each mod can specify any number of options that may be passed to it when applied to a class/model.
93 94 95 |
# File 'lib/motr/modding.rb', line 93 def (*) @_mod_options = end |