Class: Locomotive::Steam::Models::Scope
- Inherits:
-
Object
- Object
- Locomotive::Steam::Models::Scope
- Defined in:
- lib/locomotive/steam/models/scope.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#site ⇒ Object
Returns the value of attribute site.
Instance Method Summary collapse
- #apply(attributes) ⇒ Object
- #default_locale ⇒ Object
-
#initialize(site, locale, context = nil) ⇒ Scope
constructor
A new instance of Scope.
- #locales ⇒ Object
- #to_key ⇒ Object
- #with_locale(locale, &block) ⇒ Object
Constructor Details
#initialize(site, locale, context = nil) ⇒ Scope
Returns a new instance of Scope.
8 9 10 |
# File 'lib/locomotive/steam/models/scope.rb', line 8 def initialize(site, locale, context = nil) @site, @locale, @context = site, locale, (context || {}) end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
6 7 8 |
# File 'lib/locomotive/steam/models/scope.rb', line 6 def context @context end |
#locale ⇒ Object
Returns the value of attribute locale.
6 7 8 |
# File 'lib/locomotive/steam/models/scope.rb', line 6 def locale @locale end |
#site ⇒ Object
Returns the value of attribute site.
6 7 8 |
# File 'lib/locomotive/steam/models/scope.rb', line 6 def site @site end |
Instance Method Details
#apply(attributes) ⇒ Object
28 29 30 |
# File 'lib/locomotive/steam/models/scope.rb', line 28 def apply(attributes) attributes['site_id'] = @site._id end |
#default_locale ⇒ Object
12 13 14 |
# File 'lib/locomotive/steam/models/scope.rb', line 12 def default_locale site.try(:default_locale) end |
#locales ⇒ Object
16 17 18 |
# File 'lib/locomotive/steam/models/scope.rb', line 16 def locales site.try(:locales) end |
#to_key ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/locomotive/steam/models/scope.rb', line 32 def to_key (@site ? ['site', @site._id] : []).tap do |base| @context.each do |name, object| base << [name, object.try(:_id)] end end.flatten.join('_') end |
#with_locale(locale, &block) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/locomotive/steam/models/scope.rb', line 20 def with_locale(locale, &block) @previous_locale = @locale @locale = locale yield.tap do @locale = @previous_locale end end |