Class: BodegaShopify::Syncer
- Inherits:
-
Object
- Object
- BodegaShopify::Syncer
- Defined in:
- lib/bodega-shopify/syncer.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #cli ⇒ Object
- #files ⇒ Object
-
#initialize(params = {}) ⇒ Syncer
constructor
A new instance of Syncer.
- #modified_files ⇒ Object
- #replace! ⇒ Object
- #save_config ⇒ Object
- #sync! ⇒ Object
- #watch ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Syncer
Returns a new instance of Syncer.
8 9 10 |
# File 'lib/bodega-shopify/syncer.rb', line 8 def initialize params={} self.config = params[:config] end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
6 7 8 |
# File 'lib/bodega-shopify/syncer.rb', line 6 def config @config end |
Instance Method Details
#cli ⇒ Object
12 13 14 |
# File 'lib/bodega-shopify/syncer.rb', line 12 def cli @cli ||= ShopifyTheme::Cli.new end |
#files ⇒ Object
16 17 18 |
# File 'lib/bodega-shopify/syncer.rb', line 16 def files Dir["**/*"] end |
#modified_files ⇒ Object
20 21 22 |
# File 'lib/bodega-shopify/syncer.rb', line 20 def modified_files files.select{ |file| !(config.ignore_files.any? { |ignore| file =~ /^#{ignore}/ } || File.directory?(file) || File.mtime(file).to_i < config.last_sync_at.to_time.to_i) } end |
#replace! ⇒ Object
24 25 26 27 |
# File 'lib/bodega-shopify/syncer.rb', line 24 def replace! cli.replace cli.upload 'config/settings_data.json' end |
#save_config ⇒ Object
29 30 31 32 |
# File 'lib/bodega-shopify/syncer.rb', line 29 def save_config config.last_sync_at = Time.now config.save end |
#sync! ⇒ Object
34 35 36 37 |
# File 'lib/bodega-shopify/syncer.rb', line 34 def sync! modified_files.each { |file| cli.upload file } save_config end |
#watch ⇒ Object
39 40 41 |
# File 'lib/bodega-shopify/syncer.rb', line 39 def watch cli.watch end |