Class: BodegaShopify::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/bodega-shopify/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configObject

Returns the value of attribute config.



5
6
7
# File 'lib/bodega-shopify/configuration.rb', line 5

def config
  @config
end

#environmentObject

Returns the value of attribute environment.



5
6
7
# File 'lib/bodega-shopify/configuration.rb', line 5

def environment
  @environment
end

#shopify_configObject

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_keyObject



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_filesObject



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_atObject



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

#passwordObject



23
24
25
# File 'lib/bodega-shopify/configuration.rb', line 23

def password
  config[environment][:password]
end

#saveObject



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_configObject



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

#storeObject



27
28
29
# File 'lib/bodega-shopify/configuration.rb', line 27

def store
  config[environment][:store]
end