Sha256: 6d3672278a3cf9bbecbdbc4f96f7985e5017bf066eb5fcd39d5bc0e8cc5040af

Contents?: true

Size: 917 Bytes

Versions: 8

Compression:

Stored size: 917 Bytes

Contents

module Locomotive
  module Steam

    class ContentTypeFieldSelectOptionRepository

      include Models::Repository

      attr_accessor :content_type_field

      # Entity mapping
      mapping :content_type_field_select_options, entity: ContentTypeField::SelectOption do
        default_attribute :field, -> (repository) { repository.content_type_field }

        localized_attributes :name
      end

      def all
        query { order_by(position: :asc) }.all
      end

      def by_name(name)
        scope.with_locale(query_locale) do
          query { where(name: name) }.first
        end
      end

      def by_id_or_name(id_or_name)
        find(id_or_name) || by_name(id_or_name)
      end

      def query_locale
        # if the select field is not localized, query in the default locale of the site
        content_type_field.localized? ? locale : scope.default_locale 
      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
locomotivecms_steam-1.8.0.alpha2 lib/locomotive/steam/repositories/content_type_field_select_option_repository.rb
locomotivecms_steam-1.8.0.alpha1 lib/locomotive/steam/repositories/content_type_field_select_option_repository.rb
locomotivecms_steam-1.7.1 lib/locomotive/steam/repositories/content_type_field_select_option_repository.rb
locomotivecms_steam-1.7.0 lib/locomotive/steam/repositories/content_type_field_select_option_repository.rb
locomotivecms_steam-1.6.1 lib/locomotive/steam/repositories/content_type_field_select_option_repository.rb
locomotivecms_steam-1.6.0 lib/locomotive/steam/repositories/content_type_field_select_option_repository.rb
locomotivecms_steam-1.6.0.rc1 lib/locomotive/steam/repositories/content_type_field_select_option_repository.rb
locomotivecms_steam-1.6.0.beta1 lib/locomotive/steam/repositories/content_type_field_select_option_repository.rb