How to make your own properties, eg. "devise :authenticable" in ruby / rails -


i wondering how have various properties in models. eg:

property < activerecord::base    locatable, saleable ... 

would these mixins? or there way of implementing this? eg. way devise has:

  class user < activerecord::base     # include default devise modules. others available are:     # :token_authenticatable, :confirmable,     # :lockable, :timeoutable , :omniauthable     devise :database_authenticatable, :registerable,            :recoverable, :rememberable, :trackable, :validatable   end 

great part open source stuff can take , find out. i've removed non-relevant lines (gems/devise-2.2.3/lib/devise/models.rb:83):

def devise(*modules)    devise_modules_hook!     include devise::models::authenticatable     selected_modules.each |m|       mod = devise::models.const_get(m.to_s.classify)        if mod.const_defined?("classmethods")         class_mod = mod.const_get("classmethods")         extend class_mod          if class_mod.respond_to?(:available_configs)           available_configs = class_mod.available_configs           available_configs.each |config|             next unless options.key?(config)             send(:"#{config}=", options.delete(config))           end         end       end        include mod     end   end end 

all devise doing (aside housekeeping stuff) automating looping through splatted array of symbols passed in, , including them (or using extend) class devise::models::#{property_name}.

you same. whether should or not doing. often, seeing include somemodule::someclass far, far more informative cutsey helper method.


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -