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 +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +2 -1
- data/README.md +11 -0
- data/lib/sync_files/config/loader.rb +1 -5
- data/lib/sync_files/config/validation.rb +1 -0
- data/lib/sync_files/fixtures/process.rb +37 -0
- data/lib/sync_files/version.rb +1 -1
- data/lib/sync_files.rb +3 -10
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82bbb6c9b18dda1bd01ebab192d1f90f2f16a0103f6cb6fed7252e47c0444797
|
4
|
+
data.tar.gz: 68e5097672a8c8b856fcb64caf83e21ac231b8ca42cb0e262c43e3046c10b228
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1be1ba62d211b4329f3817dd64a7fd7b94a7817a76e91a3f5eb4b7d7f0b841edb6c7c384b58333b44577dad6b2095df24903b751b1de432a0952aa63184403b
|
7
|
+
data.tar.gz: a239ba391d4037c3d6f3f20efa0c95a332b9e99cc31724c5533d844e7e1d63e13607e7d17b20ec6eb4bd62c0ac103d9ef8696eade193e3789b76beb8e69f2613
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
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
|
data/lib/sync_files/version.rb
CHANGED
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 "
|
29
|
+
puts "Fetching fixtures: #{url} #{filename}"
|
29
30
|
|
30
|
-
|
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.
|
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:
|
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.
|
104
|
+
rubygems_version: 3.4.18
|
104
105
|
signing_key:
|
105
106
|
specification_version: 4
|
106
107
|
summary: Synchronize web pages to disk.
|