Sha256: 70d6c5d2bab131e68c4a287da20621b849573b49330db0f0722e39bc0c229b38

Contents?: true

Size: 852 Bytes

Versions: 17

Compression:

Stored size: 852 Bytes

Contents

module Locomotive::Steam
  module Models

    class Scope

      attr_accessor :site, :locale, :context

      def initialize(site, locale, context = nil)
        @site, @locale, @context = site, locale, (context || {})
      end

      def default_locale
        site.try(:default_locale)
      end

      def locales
        site.try(:locales)
      end

      def with_locale(locale, &block)
        @previous_locale = @locale
        @locale = locale
        yield.tap do
          @locale = @previous_locale
        end
      end

      def apply(attributes)
        attributes['site_id'] = @site._id
      end

      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

    end

  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
locomotivecms_steam-1.8.0.alpha2 lib/locomotive/steam/models/scope.rb
locomotivecms_steam-1.8.0.alpha1 lib/locomotive/steam/models/scope.rb
locomotivecms_steam-1.7.1 lib/locomotive/steam/models/scope.rb
locomotivecms_steam-1.7.0 lib/locomotive/steam/models/scope.rb
locomotivecms_steam-1.6.1 lib/locomotive/steam/models/scope.rb
locomotivecms_steam-1.6.0 lib/locomotive/steam/models/scope.rb
locomotivecms_steam-1.6.0.rc1 lib/locomotive/steam/models/scope.rb
locomotivecms_steam-1.6.0.beta1 lib/locomotive/steam/models/scope.rb
locomotivecms_steam-1.5.3 lib/locomotive/steam/models/scope.rb
locomotivecms_steam-1.5.2 lib/locomotive/steam/models/scope.rb
locomotivecms_steam-1.5.1 lib/locomotive/steam/models/scope.rb
locomotivecms_steam-1.5.0 lib/locomotive/steam/models/scope.rb
locomotivecms_steam-1.5.0.rc1 lib/locomotive/steam/models/scope.rb
locomotivecms_steam-1.5.0.rc0 lib/locomotive/steam/models/scope.rb
locomotivecms_steam-1.5.0.beta3 lib/locomotive/steam/models/scope.rb
locomotivecms_steam-1.5.0.beta2 lib/locomotive/steam/models/scope.rb
locomotivecms_steam-1.5.0.beta1 lib/locomotive/steam/models/scope.rb