sync_files 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 011e6a60722b7ce84e2fe2e0d2ba25c64c6a01f17dbeab5767c5340fb8f64a27
4
- data.tar.gz: 9974718b84722fe34606ac8f1a0f47a8aafea9c7e16a5d2a49effdea5ac3d91e
3
+ metadata.gz: 82bbb6c9b18dda1bd01ebab192d1f90f2f16a0103f6cb6fed7252e47c0444797
4
+ data.tar.gz: 68e5097672a8c8b856fcb64caf83e21ac231b8ca42cb0e262c43e3046c10b228
5
5
  SHA512:
6
- metadata.gz: 5615d39de51ef02b9eac3dbb60381d9c142198e390f39592da71d5e70109eeacca45070c375ad3d0e6a1640fcdc45b716da531eadf0c08e371b0d70eb41183e6
7
- data.tar.gz: 73eebe3c25969008b46830042740f4f32bb0ac900acc041ffbd0d1948229b2efa973ad5848ab1762db99c9d49cf165d4d81697045684ad8ac2bf9816f73ae8d3
6
+ metadata.gz: a1be1ba62d211b4329f3817dd64a7fd7b94a7817a76e91a3f5eb4b7d7f0b841edb6c7c384b58333b44577dad6b2095df24903b751b1de432a0952aa63184403b
7
+ data.tar.gz: a239ba391d4037c3d6f3f20efa0c95a332b9e99cc31724c5533d844e7e1d63e13607e7d17b20ec6eb4bd62c0ac103d9ef8696eade193e3789b76beb8e69f2613
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2024-01-21
4
+
5
+ - If 'filename' contains folders they'll be created.
6
+ - Fix crash when config file is missing.
7
+
3
8
  ## [0.1.0] - 2023-01-23
4
9
 
5
10
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sync_files (0.1.0)
4
+ sync_files (0.2.0)
5
5
  httparty
6
6
 
7
7
  GEM
@@ -175,6 +175,7 @@ GEM
175
175
 
176
176
  PLATFORMS
177
177
  arm64-darwin-21
178
+ arm64-darwin-22
178
179
  x86_64-linux
179
180
 
180
181
  DEPENDENCIES
data/README.md CHANGED
@@ -20,6 +20,8 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
+ Create a `config/sync_files.yml` or `.sync_files.yml` file with content similar to the following:
24
+
23
25
  ```
24
26
  groups:
25
27
  - settings:
@@ -29,6 +31,15 @@ groups:
29
31
  url: "https://cnn.com"
30
32
  ```
31
33
 
34
+ The destination setting is where the HTML files will be written. The fixtures array contains a list of fixtures to be written. Each fixture has a filename and a url. The filename is the name of the file to be written. The url is the URL of the web page to be fetched and written to the file.
35
+
36
+ To synchronize the files, run the following command:
37
+
38
+ ```
39
+ bundle exec rake sync_files:all
40
+ ```
41
+
42
+
32
43
  ## Development
33
44
 
34
45
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
@@ -9,11 +9,7 @@ module SyncFiles
9
9
  attr_reader :config
10
10
 
11
11
  def initialize
12
- if config_filename
13
- @config = YAML.load(File.read(config_filename))
14
- else
15
- puts "ERROR: No config file found. Please create one of the following files: #{CONFIG_FILENAMES.join(", ")}"
16
- end
12
+ @config = YAML.load(File.read(config_filename)) if config_filename
17
13
  end
18
14
 
19
15
  def has_config?
@@ -16,6 +16,7 @@ module SyncFiles
16
16
  end
17
17
 
18
18
  def validate!
19
+ raise Invalid.new("ERROR: No config file found. Please create one of the following files: #{CONFIG_FILENAMES.join(", ")}") unless @config
19
20
  raise Invalid.new("ERROR: No groups specified in the config file.") unless validate_groups
20
21
  raise Invalid.new("ERROR: No files specified in the config file.") unless validate_fixtures
21
22
  raise Invalid.new("ERROR: No destination specified in the config file.") unless validate_settings
@@ -0,0 +1,37 @@
1
+ module SyncFiles
2
+ module Fixtures
3
+ class Process
4
+ attr_reader :filename, :url, :destination
5
+
6
+ def initialize(filename:, url:, destination:)
7
+ @filename = filename
8
+ @url = url
9
+ @destination = destination
10
+ end
11
+
12
+ def run
13
+ response = HTTParty.get(url)
14
+ if response.code != 200
15
+ puts "ERROR: #{response.code} #{response.message} for #{url}"
16
+ return
17
+ end
18
+
19
+ FileUtils.mkdir_p(write_path)
20
+
21
+ open(write_filename, "wb") do |file|
22
+ file << response.body
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def write_filename
29
+ File.join(::Rails.root.to_s, destination, filename)
30
+ end
31
+
32
+ def write_path
33
+ File.dirname(write_filename)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module SyncFiles
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/sync_files.rb CHANGED
@@ -7,6 +7,7 @@ require "sync_files/config/facade"
7
7
  require "sync_files/config/loader"
8
8
  require "sync_files/config/parser"
9
9
  require "sync_files/config/validation"
10
+ require "sync_files/fixtures/process"
10
11
  require "sync_files/engine"
11
12
 
12
13
  module SyncFiles
@@ -25,17 +26,9 @@ module SyncFiles
25
26
 
26
27
  def process_fixtures
27
28
  @facade.iterate do |filename, url, destination|
28
- puts "Getting fixtures: #{url} #{filename}"
29
+ puts "Fetching fixtures: #{url} #{filename}"
29
30
 
30
- response = HTTParty.get(url)
31
- if response.code != 200
32
- puts "ERROR: #{response.code} #{response.message} for #{url}"
33
- next
34
- end
35
-
36
- open(File.join(::Rails.root.to_s, destination, filename), "wb") do |file|
37
- file << response.body
38
- end
31
+ SyncFiles::Fixtures::Process.new(filename: filename, url: url, destination: destination).run
39
32
  end
40
33
  end
41
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sync_files
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Moen Wulffeld
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-24 00:00:00.000000000 Z
11
+ date: 2024-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -75,6 +75,7 @@ files:
75
75
  - lib/sync_files/config/parser.rb
76
76
  - lib/sync_files/config/validation.rb
77
77
  - lib/sync_files/engine.rb
78
+ - lib/sync_files/fixtures/process.rb
78
79
  - lib/sync_files/version.rb
79
80
  - lib/tasks/sync_files.rake
80
81
  - sync_files.gemspec
@@ -100,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
101
  - !ruby/object:Gem::Version
101
102
  version: '0'
102
103
  requirements: []
103
- rubygems_version: 3.3.7
104
+ rubygems_version: 3.4.18
104
105
  signing_key:
105
106
  specification_version: 4
106
107
  summary: Synchronize web pages to disk.