Module: Gluttonberg::Content::Localization::ClassMethods
- Defined in:
- lib/gluttonberg/content/localization.rb
Instance Method Summary collapse
- #is_localized(opts = {}, &blk) ⇒ Object
- #localized? ⇒ Boolean
-
#new_with_localization(attrs = {}) ⇒ Object
Returns a new instance of the model, with a localization instance already assigned to it based on the options passed in.
Instance Method Details
#is_localized(opts = {}, &blk) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/gluttonberg/content/localization.rb', line 16 def is_localized(opts={}, &blk) # Why yes, this is localized. self.localized = true self.parent_key = (opts[:parent_key] || :parent_id) # Create the localization model create_localization_model(&blk) end |
#localized? ⇒ Boolean
25 26 27 |
# File 'lib/gluttonberg/content/localization.rb', line 25 def localized? self.localized end |
#new_with_localization(attrs = {}) ⇒ Object
Returns a new instance of the model, with a localization instance already assigned to it based on the options passed in.
The options include the attributes for the both new model and its localization.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gluttonberg/content/localization.rb', line 33 def new_with_localization(attrs={}) new_model = new default_localization = nil # new localization object for all locales. Gluttonberg::Locale.all.each do |locale| loc = self.localized_model.new(:locale_id => locale.id) new_model.instance_variable_set(:@current_localization, loc) new_model.localizations << loc loc.parent = new_model #update current object and current localization attrs.each do |name, value| new_model.send("#{name}=", value) end if locale.default? default_localization = loc end end # make default localization as default default_localization = new_model.localizations.first if default_localization.blank? new_model.instance_variable_set(:@current_localization, default_localization) new_model end |