Module: Motr::Mods
- Defined in:
- lib/motr/mods.rb,
lib/motr/mods/scopeable.rb,
lib/motr/mods/sluggable.rb
Defined Under Namespace
Instance Method Summary collapse
-
#modded_with(*mods) ⇒ Object
(also: #motr, #mod_with)
modded_with provides the “hook” functionality to mod a model/class with a particular mod.
- #motr_mod_options ⇒ Object
Instance Method Details
#modded_with(*mods) ⇒ Object Also known as: motr, mod_with
modded_with provides the “hook” functionality to mod a model/class with a particular mod. Multiple mods can be applied at once, with options.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/motr/mods.rb', line 17 def modded_with(*mods) include Motr::Mods::Scopeable = mods. modules = mods.map(&:to_sym).uniq modules.each do |mod| const_name = mod.to_s.classify next unless Motr::Mods.const_defined?(:"#{const_name}") self.motr_mods << mod const_incl = Motr::Mods.const_get(:"#{const_name}") # Apply passed options to modules where applicable. # if const_incl.instance_variable_defined?("@_mod_options") mod_opts = const_incl.instance_variable_get("@_mod_options") new_opts = mod_opts.inject({}) do |hsh, option| next hsh unless .key?(option) hsh.merge!(option => .delete(option)) end (class << self; self; end).class_eval do define_method("#{mod}_mod_options"){ [mod.to_s] } define_method("#{mod}_mod_options="){ |opts| [mod.to_s] = opts } end write_inheritable_attribute(:motr_mod_options, {}) if .nil? [mod.to_s] = new_opts end if const_incl.instance_variable_defined?("@_mod_apply_callback") self.class_eval(&const_incl.instance_variable_get("@_mod_apply_callback")) end include const_incl Motr.track_mod(mod, self.name.to_s) end end |
#motr_mod_options ⇒ Object
62 63 64 |
# File 'lib/motr/mods.rb', line 62 def read_inheritable_attribute(:motr_mod_options) end |