Class: MagicLocales::Locale
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- MagicLocales::Locale
- Defined in:
- lib/app/models/magic_locales/locale.rb
Constant Summary collapse
- STATES =
> C O N S T A N T S <=============================================================== #
%w(inactive active live)
Class Method Summary collapse
-
.search(search) ⇒ Object
> C L A S S - M E T H O D S <======================================================= #.
Instance Method Summary collapse
-
#do_transition!(transition) ⇒ Object
MicroMachine ..
- #state ⇒ Object
-
#with_translations(*locales) ⇒ Object
> I N S T A N C E - M E T H O D S <================================================= #.
Class Method Details
.search(search) ⇒ Object
> C L A S S - M E T H O D S <======================================================= #
30 31 32 33 34 35 36 |
# File 'lib/app/models/magic_locales/locale.rb', line 30 def self.search(search) if search with_translations.where('name LIKE ?', "%#{search}%") else with_translations end end |
Instance Method Details
#do_transition!(transition) ⇒ Object
MicroMachine .. (Finite State Machine)
39 40 41 42 |
# File 'lib/app/models/magic_locales/locale.rb', line 39 def do_transition!( transition ) state.trigger( transition.to_sym ) self.save end |
#state ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/app/models/magic_locales/locale.rb', line 44 def state @state ||= begin fsm = MicroMachine.new(locale_state || "inactive") fsm.when(:activate, "inactive" => "active") fsm.when(:release, "active" => "live") fsm.when(:deactivate, "active" => "inactive", "live" => "inactive") fsm.on(:any) { self.locale_state = state.state } fsm end end |
#with_translations(*locales) ⇒ Object
> I N S T A N C E - M E T H O D S <================================================= #
57 58 59 60 |
# File 'lib/app/models/magic_locales/locale.rb', line 57 def with_translations(*locales) locales = translated_locales if locales.empty? includes(:translations).with_locales(locales).with_required_attributes end |