Class: Locomotive::Steam::Models::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/locomotive/steam/models/scope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contextObject

Returns the value of attribute context.



6
7
8
# File 'lib/locomotive/steam/models/scope.rb', line 6

def context
  @context
end

#localeObject

Returns the value of attribute locale.



6
7
8
# File 'lib/locomotive/steam/models/scope.rb', line 6

def locale
  @locale
end

#siteObject

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_localeObject



12
13
14
# File 'lib/locomotive/steam/models/scope.rb', line 12

def default_locale
  site.try(:default_locale)
end

#localesObject



16
17
18
# File 'lib/locomotive/steam/models/scope.rb', line 16

def locales
  site.try(:locales)
end

#to_keyObject



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