Sha256: de0dd625b9f97d9f39b6e1e978f1d68249d646f136277ffee22d9043ba610dfd

Contents?: true

Size: 1.99 KB

Versions: 9

Compression:

Stored size: 1.99 KB

Contents

# This module contains all custom scopes created for selecting products.
#
# All usable scopes *should* be included in SCOPES constant, it represents
# all scopes that are selectable from user interface, extensions can extend
# and modify it, but should provide corresponding translations.
#
# Format of constant is following:
#
#   {
#     :namespace/grouping => {
#       :name_of_the_scope => [:list, :of, :arguments]
#     }
#   }
#
#   This values are used in translation file, to describe them in the interface.
#   So for each scope you define here you have to provide following entry in translation file
#   product_scopes:
#     name_of_the_group:
#       name: Translated name of the group
#       description: Longer description of what this scope group does, inluding
#         any possible help user may need
#       scopes:
#         name_of_the_scope:
#           name: Short name of the scope
#           description: What does this scope does exactly
#           arguments:
#             arg1: Description of argument
#             arg2: Description of second Argument
#
module Scopes
  module_function

  def generate_translation(all_scopes)
    result = {"groups" => {}, "scopes" => {}}
    all_scopes.dup.each_pair do |group_name, scopes|
      result["groups"][group_name.to_s] = {
        'name' => group_name.to_s.humanize,
        'description' => "Scopes for selecting products based on #{group_name.to_s}",
      }

      scopes.each_pair do |scope_name, targs|
        hashed_args = {}
        targs.each{|v| hashed_args[v.to_s] = v.to_s.humanize}
        
        result['scopes'][scope_name.to_s] = {
          'name' => scope_name.to_s.humanize,
          'description' => "",
          'args' => hashed_args.dup
        }
      end
    end

    result
  end

  def generate_translations
    require 'ya2yaml'
    {
      'product_scopes' => generate_translation(Scopes::Product::SCOPES)
    }.ya2yaml
  end
end

ActiveRecord::NamedScope::Scope.class_eval do
  def to_sql
    construct_finder_sql({})
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spree-0.11.4 lib/scopes.rb
spree-0.11.3 lib/scopes.rb
spree-0.11.2 lib/scopes.rb
spree-0.11.1 lib/scopes.rb
spree-0.11.0 lib/scopes.rb
spree-0.10.2 lib/scopes.rb
spree-0.10.1 lib/scopes.rb
spree-0.10.0 lib/scopes.rb
spree-0.10.0.beta lib/scopes.rb