Module: Shoppe

Defined in:
lib/shoppe.rb,
lib/shoppe/engine.rb,
lib/shoppe/version.rb,
lib/shoppe/setup_generator.rb,
app/mailers/shoppe/user_mailer.rb,
lib/shoppe/errors/not_enough_stock.rb,
lib/shoppe/errors/payment_declined.rb,
lib/shoppe/errors/invalid_configuration.rb,
app/controllers/shoppe/application_controller.rb,
lib/shoppe/errors/insufficient_stock_to_fulfil.rb,
lib/shoppe/errors/inappropriate_delivery_service.rb

Defined Under Namespace

Modules: ApplicationHelper, Errors, ShoppeHelper Classes: ApplicationController, AttachmentsController, DashboardController, DeliveryService, DeliveryServicePrice, DeliveryServicePricesController, DeliveryServicesController, Engine, Error, Order, OrderItem, OrderMailer, OrdersController, Product, ProductAttribute, ProductCategoriesController, ProductCategory, ProductsController, SessionsController, SetupGenerator, User, UserMailer, UsersController

Constant Summary collapse

VERSION =
"0.0.9"

Class Method Summary collapse

Class Method Details

.configObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/shoppe.rb', line 19

def config
  @config ||= begin
    path = Rails.root.join('config', 'shoppe.yml')
    if File.exist?(path)
      config = YAML.load_file(path).with_indifferent_access
      setup_config(config)
      config
    else
      raise InvalidConfiguration, "Shoppe configuration file missing at #{path}"
    end
  end
end

.rootObject



15
16
17
# File 'lib/shoppe.rb', line 15

def root
  File.expand_path('../../', __FILE__)
end

.setup_config(config) ⇒ Object



32
33
34
# File 'lib/shoppe.rb', line 32

def setup_config(config)
  ActionMailer::Base.smtp_settings = config[:smtp_settings] if config[:smtp_settings]
end

.validate_config(config, scope, *requirements) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/shoppe.rb', line 40

def validate_config(config, scope, *requirements)
  for req in requirements
    case req
    when String, Symbol
      unless config.keys.include?(req.to_s)
        raise Shoppe::Errors::InvalidConfiguration, "Missing configuration option '#{scope.join('.')}.#{req}' in shoppe.yml"
      end
    when Array
      validate_config(config, scope, *req)
    when Hash
      req.each do |key, value|
        if config[key] && config[key].is_a?(Hash)
          scope << key
          validate_config(config[key], scope, *value)
        else
          validate_config(config, scope, key)
        end
      end
    end
  end
end

.validate_live_config(*requirements) ⇒ Object



36
37
38
# File 'lib/shoppe.rb', line 36

def validate_live_config(*requirements)
  validate_config(self.config, [], *requirements)
end