lib/shoppe.rb in shoppe-0.0.15 vs lib/shoppe.rb in shoppe-0.0.16
- old
+ new
@@ -1,5 +1,8 @@
+require "coffee-rails"
+require "sass-rails"
+require "jquery-rails"
require 'haml'
require 'bcrypt'
require 'dynamic_form'
require 'kaminari'
require 'ransack'
@@ -12,54 +15,29 @@
module Shoppe
class Error < StandardError; end
class << self
+
def root
File.expand_path('../../', __FILE__)
end
- 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
+ def settings
+ Thread.current[:shoppe_settings] ||= Shoppe::Settings.new(Shoppe::Setting.to_hash)
end
- def setup_config(config)
- ActionMailer::Base.smtp_settings = config[:smtp_settings] if config[:smtp_settings]
+ def reset_settings
+ Thread.current[:shoppe_settings] = nil
end
- def validate_live_config(*requirements)
- validate_config(self.config, [], *requirements)
+ def add_setting_group(group, fields = [])
+ setting_groups[group] ||= []
+ setting_groups[group] = setting_groups[group] | fields
end
- 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
+ def setting_groups
+ @setting_groups ||= {}
end
end
end