Class: BodegaShopify::Configuration
- Inherits:
-
Object
- Object
- BodegaShopify::Configuration
- Defined in:
- lib/bodega-shopify/configuration.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#shopify_config ⇒ Object
Returns the value of attribute shopify_config.
Instance Method Summary collapse
- #api_key ⇒ Object
- #config_file(key) ⇒ Object
- #ignore_files ⇒ Object
-
#initialize(params = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #last_sync_at ⇒ Object
- #last_sync_at=(last_sync_at) ⇒ Object
- #password ⇒ Object
- #save ⇒ Object
- #save_shopify_config ⇒ Object
- #store ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Configuration
Returns a new instance of Configuration.
7 8 9 10 11 12 13 |
# File 'lib/bodega-shopify/configuration.rb', line 7 def initialize params={} self.environment = (params[:environment] || DEFAULT_ENVIRONMENT).to_sym self.config = File.exists?(CONFIG_FILE) ? YAML.load(File.read(CONFIG_FILE)) || {} : {} self.shopify_config = File.exists?(SHOPIFY_CONFIG_FILE) ? YAML.load(File.read(SHOPIFY_CONFIG_FILE)) || {} : {} BodegaShopify.logger.info "Configured #{environment} store #{store}" save_shopify_config end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
5 6 7 |
# File 'lib/bodega-shopify/configuration.rb', line 5 def config @config end |
#environment ⇒ Object
Returns the value of attribute environment.
5 6 7 |
# File 'lib/bodega-shopify/configuration.rb', line 5 def environment @environment end |
#shopify_config ⇒ Object
Returns the value of attribute shopify_config.
5 6 7 |
# File 'lib/bodega-shopify/configuration.rb', line 5 def shopify_config @shopify_config end |
Instance Method Details
#api_key ⇒ Object
19 20 21 |
# File 'lib/bodega-shopify/configuration.rb', line 19 def api_key config[environment][:api_key] end |
#config_file(key) ⇒ Object
15 16 17 |
# File 'lib/bodega-shopify/configuration.rb', line 15 def config_file key config[key.to_s].to_s.chomp("/").reverse.chomp("/").reverse if config.has_key?(key.to_s) end |
#ignore_files ⇒ Object
31 32 33 |
# File 'lib/bodega-shopify/configuration.rb', line 31 def ignore_files (shopify_config[:ignore_files] || []).compact.map { |r| Regexp.new(r) } end |
#last_sync_at ⇒ Object
35 36 37 |
# File 'lib/bodega-shopify/configuration.rb', line 35 def last_sync_at config[environment][:last_sync_at] ||= Time.parse('2000-01-01 00:00:00') end |
#last_sync_at=(last_sync_at) ⇒ Object
39 40 41 |
# File 'lib/bodega-shopify/configuration.rb', line 39 def last_sync_at= last_sync_at config[environment][:last_sync_at] = last_sync_at end |
#password ⇒ Object
23 24 25 |
# File 'lib/bodega-shopify/configuration.rb', line 23 def password config[environment][:password] end |
#save ⇒ Object
43 44 45 |
# File 'lib/bodega-shopify/configuration.rb', line 43 def save File.open(CONFIG_FILE, 'w') {|f| f.write config.to_yaml } end |
#save_shopify_config ⇒ Object
47 48 49 50 51 52 |
# File 'lib/bodega-shopify/configuration.rb', line 47 def save_shopify_config shopify_config[:api_key] = api_key shopify_config[:password] = password shopify_config[:store] = store File.open(SHOPIFY_CONFIG_FILE, 'w') {|f| f.write shopify_config.to_yaml } end |
#store ⇒ Object
27 28 29 |
# File 'lib/bodega-shopify/configuration.rb', line 27 def store config[environment][:store] end |