Sha256: 627df73e10de64c1f9a455bdfb639d845e800d5580b0de030ca64a88efccc83e

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 KB

Contents

module SolidusVolumePricing
  class Engine < Rails::Engine
    isolate_namespace Spree
    engine_name 'solidus_volume_pricing'

    initializer 'solidus_volume_pricing.preferences', before: 'spree.environment' do
      Spree::AppConfiguration.class_eval do
        preference :use_master_variant_volume_pricing, :boolean, default: false
        preference :volume_pricing_role, :string, default: 'wholesale'
      end
    end

    def self.activate
      Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
        Rails.configuration.cache_classes ? require(c) : load(c)
      end

      String.class_eval do
        def to_range
          case count('.')
          when 2
            elements = split('..')
            return Range.new(elements[0].delete('(').to_i, elements[1].to_i)
          when 3
            elements = split('...')
            return Range.new(elements[0].delete('(').to_i, elements[1].to_i - 1)
          else
            raise ArgumentError.new(
              I18n.t(
                :'activerecord.errors.messages.could_not_conver_to_range',
                number: self
              )
            )
          end
        end
      end
    end

    config.autoload_paths += %W(#{config.root}/lib)
    config.to_prepare(&method(:activate).to_proc)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
solidus_volume_pricing-0.2.1 lib/solidus_volume_pricing/engine.rb
solidus_volume_pricing-0.1.1 lib/solidus_volume_pricing/engine.rb
solidus_volume_pricing-0.2.0 lib/solidus_volume_pricing/engine.rb
solidus_volume_pricing-0.1.0 lib/solidus_volume_pricing/engine.rb