parklife 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97be6505f9a1ac2cf9b5b2f5864b6a73fbf110c173043b991a32b04892c8e865
4
- data.tar.gz: edd6ec37ae40bc0250bbb43ddaa9020a88d6e0884d0957dcb0888a0ab15cb9d0
3
+ metadata.gz: 32db274b9f5ec6ce7c56203a391c30c2d541bb8f319bc1b4130b22a2ed85bcf3
4
+ data.tar.gz: dce6ff9a4911863acb4fdb19c134f822d729a4ced0df62799fc69853154e412f
5
5
  SHA512:
6
- metadata.gz: 80877ef06ba4a6cde8dea7ea58f1bea6ee02a7bba095a26f3644454ecdfa7b567895a00d6b55b53fb0b3d1c365b3d93ee3c0fdca137130a85e0f612e15aea782
7
- data.tar.gz: ce193737f065bcbb63d0350c5e01001c2b83a56e313d8fc2e3994ce653efd8937f7f83695589134d1f12f2cb2e0ce07df76601d102add3f911bfa313c608e7d2
6
+ metadata.gz: 434a2acf5bd27046330a6f4c954dcf7908e3672db1e9ce08e985b833f299273306b4535115093f8f18517210605da098e347bcd03a3481106e3c35958da5df5a
7
+ data.tar.gz: 43249f1f24c7f932da0fd3d949b9d2590274ae7360d86a4f70f268c2a566dde1cf946aa6ba665a89c9bd5bbb5d5b6ee3ef714edbb7f4acbd34000045ac72dff5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## Version 0.4.0 - 2023-03-01
2
+
3
+ - Add a `parklife --version` command.
4
+ - No need to `require parklife` from the Parkfile.
5
+
1
6
  ## Version 0.3.0 - 2023-02-26
2
7
 
3
8
  - Allow overriding `config.base` from the CLI build command with the `--base` option.
@@ -1,4 +1,3 @@
1
- require 'parklife'
2
1
  require 'rack'
3
2
 
4
3
  app = Proc.new { |env|
@@ -1,4 +1,3 @@
1
- require 'parklife'
2
1
  require 'sinatra'
3
2
 
4
3
  get '/' do
@@ -23,12 +23,17 @@ module Parklife
23
23
  crawler.start
24
24
  end
25
25
 
26
+ def configure
27
+ yield config
28
+ end
29
+
26
30
  def crawler
27
31
  @crawler ||= Crawler.new(config, @route_set)
28
32
  end
29
33
 
30
- def configure
31
- yield config
34
+ def load_Parkfile(path)
35
+ raise ParkfileLoadError.new(path) unless File.exist?(path)
36
+ load path
32
37
  end
33
38
 
34
39
  def routes(&block)
data/lib/parklife/cli.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'parklife'
1
2
  require 'thor'
2
3
 
3
4
  module Parklife
@@ -20,21 +21,22 @@ module Parklife
20
21
  end
21
22
  end
22
23
 
24
+ map '--version' => :version
25
+ desc 'version', 'output the current version of Parklife'
26
+ def version
27
+ puts Parklife::VERSION
28
+ end
29
+
23
30
  private
24
31
  def application
25
- @application ||= begin
26
- # Reach inside the consuming app's directory to load Parklife and
27
- # apply its config. It's only at this point that the
28
- # Parklife::Application is defined.
29
- load discover_Parkfile(Dir.pwd)
30
-
31
- Parklife.application.config.reporter = $stdout
32
- Parklife.application
33
- end
34
- end
32
+ @application ||= Parklife.application.tap { |app|
33
+ # Default output to stdout (can be overridden in the Parkfile).
34
+ app.config.reporter = $stdout
35
35
 
36
- def discover_Parkfile(dir)
37
- File.expand_path('Parkfile', dir)
36
+ # Reach inside the consuming app's directory to apply its Parklife
37
+ # config.
38
+ app.load_Parkfile(File.join(Dir.pwd, 'Parkfile'))
39
+ }
38
40
  end
39
41
  end
40
42
  end
@@ -48,14 +48,14 @@ module Parklife
48
48
  when 404
49
49
  case config.on_404
50
50
  when :warn
51
- $stderr.puts HTTPError.new(path: route.path, status: 404).message
51
+ $stderr.puts HTTPError.new(404, route.path).message
52
52
  when :skip
53
53
  return false
54
54
  else
55
- raise HTTPError.new(path: route.path, status: 404)
55
+ raise HTTPError.new(404, route.path)
56
56
  end
57
57
  else
58
- raise HTTPError.new(path: route.path, status: response.status)
58
+ raise HTTPError.new(response.status, route.path)
59
59
  end
60
60
 
61
61
  Utils.save_page(route.path, response.body, config)
@@ -4,17 +4,24 @@ module Parklife
4
4
  RackAppNotDefinedError = Class.new(Error)
5
5
 
6
6
  class HTTPError < Error
7
- def initialize(path:, status:)
8
- @path = path
7
+ def initialize(status, path)
9
8
  @status = status
9
+ @path = path
10
10
  end
11
11
 
12
12
  def message
13
- %Q(#{status} response from path "#{path}")
13
+ %Q(#{@status} response from path "#{@path}")
14
+ end
15
+ end
16
+
17
+ class ParkfileLoadError < Error
18
+ def initialize(path)
19
+ @path = path
14
20
  end
15
21
 
16
- private
17
- attr_reader :path, :status
22
+ def message
23
+ %Q(Cannot load Parkfile "#{@path}")
24
+ end
18
25
  end
19
26
 
20
27
  class RailsNotDefinedError < Error
@@ -1,9 +1,5 @@
1
- require 'parklife/errors'
2
-
3
1
  raise Parklife::RailsNotDefinedError unless defined?(Rails)
4
2
 
5
- require 'parklife'
6
-
7
3
  # Allow use of the consuming Rails application's route helpers from within the
8
4
  # block when defining Parklife routes.
9
5
  Parklife::RouteSet.include(Rails.application.routes.url_helpers)
@@ -1,3 +1,3 @@
1
1
  module Parklife
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parklife
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Pickles
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-26 00:00:00.000000000 Z
11
+ date: 2023-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri