dassets 0.15.0 → 0.15.1

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.
@@ -23,23 +23,23 @@ class Dassets::SourceProxy
23
23
  end
24
24
 
25
25
  def key
26
- "#{self.digest_path} -- #{self.mtime}"
26
+ "#{digest_path} -- #{mtime}"
27
27
  end
28
28
 
29
29
  def content
30
- @content_cache[self.key] ||= source_content
30
+ @content_cache[key] ||= source_content
31
31
  end
32
32
 
33
33
  def fingerprint
34
- @fingerprint_cache[self.key] ||= source_fingerprint
34
+ @fingerprint_cache[key] ||= source_fingerprint
35
35
  end
36
36
 
37
37
  def mtime
38
- @source_files.map{ |f| f.mtime }.compact.max
38
+ @source_files.map(&:mtime).compact.max
39
39
  end
40
40
 
41
41
  def response_headers
42
- @source_files.inject(Hash.new){ |hash, f| hash.merge!(f.response_headers) }
42
+ @source_files.inject({}){ |hash, f| hash.merge!(f.response_headers) }
43
43
  end
44
44
 
45
45
  def exists?
@@ -49,7 +49,7 @@ class Dassets::SourceProxy
49
49
  private
50
50
 
51
51
  def source_content
52
- @source_files.map{ |f| f.compiled }.join("\n")
52
+ @source_files.map(&:compiled).join("\n")
53
53
  end
54
54
 
55
55
  def source_fingerprint
@@ -57,9 +57,9 @@ class Dassets::SourceProxy
57
57
  end
58
58
 
59
59
  def get_source_files(digest_path, **options)
60
- Dassets.config.combinations[digest_path.to_s].map { |source_digest_path|
60
+ Dassets.config.combinations[digest_path.to_s].map do |source_digest_path|
61
61
  Dassets::SourceFile.find_by_digest_path(source_digest_path, **options)
62
- }
62
+ end
63
63
  end
64
64
  end
65
65
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dassets
4
- VERSION = "0.15.0"
4
+ VERSION = "0.15.1"
5
5
  end
@@ -1,5 +1,7 @@
1
- # this file is automatically required when you run `assert`
2
- # put any test helpers here
1
+ # frozen_string_literal: true
2
+
3
+ # This file is automatically required when you run `assert`
4
+ # put any test helpers here.
3
5
 
4
6
  # add the root dir to the load path
5
7
  $LOAD_PATH.unshift(File.expand_path("../..", __FILE__))
@@ -12,20 +14,30 @@ require "test/support/factory"
12
14
  require "pathname"
13
15
  TEST_SUPPORT_PATH = Pathname.new(File.expand_path("../support", __FILE__))
14
16
 
15
- ENV["DASSETS_TEST_MODE"] = "yes"
17
+ ENV["DASSETS_TEST_MODE"] = "yes"
16
18
 
17
19
  require "dassets"
18
20
 
19
21
  @dumb_engine =
20
22
  Class.new(Dassets::Engine) do
21
- def ext(in_ext); ""; end
22
- def compile(input); "#{input}\nDUMB"; end
23
+ def ext(_in_ext)
24
+ ""
25
+ end
26
+
27
+ def compile(input)
28
+ "#{input}\nDUMB"
29
+ end
23
30
  end
24
31
 
25
32
  @useless_engine =
26
33
  Class.new(Dassets::Engine) do
27
- def ext(in_ext); "no-use"; end
28
- def compile(input); "#{input}\nUSELESS"; end
34
+ def ext(_in_ext)
35
+ "no-use"
36
+ end
37
+
38
+ def compile(input)
39
+ "#{input}\nUSELESS"
40
+ end
29
41
  end
30
42
 
31
43
  Dassets.configure do |c|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "sinatra/base"
2
4
 
3
5
  class SinatraApp < Sinatra::Base
File without changes
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert/factory"
2
4
 
3
5
  module Factory
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "dassets"
3
5
 
@@ -39,7 +41,8 @@ module Dassets
39
41
  assert_that(resp.body).is_empty
40
42
  end
41
43
 
42
- should "return a partial content response on valid partial content requests" do
44
+ should "return a partial content response on valid partial content "\
45
+ "requests" do
43
46
  content = Dassets["file1.txt"].content
44
47
  size = Factory.integer(content.length)
45
48
  # see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35
@@ -59,7 +62,8 @@ module Dassets
59
62
  assert_that(resp.body).equals(Dassets["file1.txt"].content)
60
63
  end
61
64
 
62
- should "return a full response on multiple-range partial content requests" do
65
+ should "return a full response on multiple-range partial content "\
66
+ "requests" do
63
67
  # see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35
64
68
  env = { "HTTP_RANGE" => "bytes=0-1,2-3" }
65
69
  resp = get "/file1-daa05c683a4913b268653f7a7e36a5b4.txt", {}, env
@@ -106,9 +110,13 @@ module Dassets
106
110
 
107
111
  should "return a successful response" do
108
112
  resp =
109
- get("/file1-daa05c683a4913b268653f7a7e36a5b4.txt", {}, {
110
- "HTTP_IF_MODIFIED_SINCE" => Dassets["file1.txt"].mtime.to_s
111
- })
113
+ get(
114
+ "/file1-daa05c683a4913b268653f7a7e36a5b4.txt",
115
+ {},
116
+ {
117
+ "HTTP_IF_MODIFIED_SINCE" => Dassets["file1.txt"].mtime.to_s,
118
+ },
119
+ )
112
120
 
113
121
  assert_that(resp.status).equals(304)
114
122
  assert_that(resp.body).is_empty
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "dassets/asset_file"
3
5
 
@@ -8,13 +10,14 @@ require "dassets/source_proxy"
8
10
  class Dassets::AssetFile
9
11
  class UnitTests < Assert::Context
10
12
  desc "Dassets::AssetFile"
11
- subject { @asset_file }
13
+ subject{ @asset_file }
12
14
 
13
15
  setup do
14
16
  @asset_file = Dassets::AssetFile.new("file1.txt")
15
17
  end
16
18
 
17
- should have_readers :digest_path, :dirname, :extname, :basename, :source_proxy
19
+ should have_readers :digest_path, :dirname, :extname, :basename
20
+ should have_readers :source_proxy
18
21
  should have_imeths :digest!, :url, :href, :fingerprint, :content
19
22
  should have_imeths :mtime, :size, :mime_type, :exists?, :==
20
23
 
@@ -30,7 +33,7 @@ class Dassets::AssetFile
30
33
  assert_that(subject.size).equals(subject.content.bytesize)
31
34
  assert_that(subject.mime_type).equals("text/plain")
32
35
  assert_that(subject.response_headers)
33
- .equals(subject.source_proxy.response_headers)
36
+ .equals(subject.source_proxy.response_headers)
34
37
  assert_that(subject.exists?).is_true
35
38
 
36
39
  null_file = Dassets::AssetFile.new("")
@@ -79,7 +82,7 @@ class Dassets::AssetFile
79
82
 
80
83
  should "build it's url/href from the file, fingerpint, and "\
81
84
  "any configured base url" do
82
- assert_that(subject.url).matches(/^\/file1-[a-f0-9]{32}\.txt$/)
85
+ assert_that(subject.url).matches(%r{^/file1-[a-f0-9]{32}\.txt$})
83
86
  assert_that(subject.href).matches(subject.url)
84
87
 
85
88
  nested = Dassets::AssetFile.new("nested/file1.txt")
@@ -89,7 +92,8 @@ class Dassets::AssetFile
89
92
  base_url = Factory.url
90
93
  Assert.stub(Dassets.config, :base_url){ base_url }
91
94
 
92
- assert_that(subject.url).matches(/^#{base_url}\/file1-[a-f0-9]{32}\.txt$/)
95
+ assert_that(subject.url)
96
+ .matches(%r{^#{base_url}/file1-[a-f0-9]{32}\.txt$})
93
97
  assert_that(subject.href).matches(subject.url)
94
98
 
95
99
  assert_that(nested.url).equals("#{base_url}/nested/file1-.txt")
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "dassets/cache"
3
5
 
4
6
  class Dassets::MemCache
5
7
  class UnitTests < Assert::Context
6
8
  desc "Dassets::MemCache"
7
- subject { Dassets::MemCache.new }
9
+ subject{ Dassets::MemCache.new }
8
10
 
9
11
  should have_imeths :keys, :[], :[]=
10
12
 
@@ -19,7 +21,7 @@ end
19
21
  class Dassets::NoCache
20
22
  class UnitTests < Assert::Context
21
23
  desc "Dassets::NoCache"
22
- subject { Dassets::NoCache.new }
24
+ subject{ Dassets::NoCache.new }
23
25
 
24
26
  should have_imeths :keys, :[], :[]=
25
27
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "dassets/config"
3
5
 
@@ -7,7 +9,7 @@ require "dassets/file_store"
7
9
  class Dassets::Config
8
10
  class UnitTests < Assert::Context
9
11
  desc "Dassets::Config"
10
- subject { @config }
12
+ subject{ @config }
11
13
 
12
14
  setup do
13
15
  @config = Dassets::Config.new
@@ -101,7 +103,7 @@ class Dassets::Config
101
103
 
102
104
  should "register new sources with the `source` method" do
103
105
  path = Factory.path
104
- filter = proc{ |paths| [] }
106
+ filter = proc{ |_paths| [] }
105
107
  subject.source(path){ |s| s.filter(&filter) }
106
108
 
107
109
  assert_that(subject.sources.size).equals(1)
@@ -110,7 +112,8 @@ class Dassets::Config
110
112
  assert_that(subject.sources.first.filter).equals(filter)
111
113
  end
112
114
 
113
- should "know its combinations and return the keyed digest path by default" do
115
+ should "know its combinations and return the keyed digest path by "\
116
+ "default" do
114
117
  assert_that(subject.combinations).is_kind_of(::Hash)
115
118
  assert_that(subject.combinations["some/digest.path"])
116
119
  .equals(["some/digest.path"])
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "dassets"
3
5
 
@@ -7,7 +9,7 @@ require "dassets/asset_file"
7
9
  module Dassets
8
10
  class UnitTests < Assert::Context
9
11
  desc "Dassets"
10
- subject { Dassets }
12
+ subject{ Dassets }
11
13
 
12
14
  should have_imeths :config, :configure, :init, :reset
13
15
  should have_imeths :asset_file, :[], :source_files, :combinations
@@ -18,7 +20,7 @@ module Dassets
18
20
 
19
21
  should "know how to reset itself" do
20
22
  config_reset_called = false
21
- Assert.stub(subject.config, :reset) { config_reset_called = true }
23
+ Assert.stub(subject.config, :reset){ config_reset_called = true }
22
24
 
23
25
  file1 = subject["nested/file3.txt"]
24
26
 
@@ -45,11 +47,11 @@ module Dassets
45
47
  end
46
48
 
47
49
  should "complain if digest path is not found using the index operator" do
48
- assert_that(-> {
50
+ assert_that(->{
49
51
  subject.asset_file("path/not/found.txt")
50
52
  }).does_not_raise
51
53
 
52
- assert_that { subject["path/not/found.txt"] }.raises(AssetFileError)
54
+ assert_that{ subject["path/not/found.txt"] }.raises(AssetFileError)
53
55
  end
54
56
 
55
57
  should "know its list of configured source files" do
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "dassets/engine"
3
5
 
4
6
  class Dassets::Engine
5
7
  class UnitTests < Assert::Context
6
8
  desc "Dassets::Engine"
7
- subject { Dassets::Engine.new }
9
+ subject{ Dassets::Engine.new }
8
10
 
9
11
  should have_reader :opts
10
12
  should have_imeths :ext, :compile
@@ -15,8 +17,8 @@ class Dassets::Engine
15
17
  end
16
18
 
17
19
  should "raise NotImplementedError on `ext` and `compile`" do
18
- assert_that { subject.ext("foo") }.raises(NotImplementedError)
19
- assert_that { subject.compile("some content") }
20
+ assert_that{ subject.ext("foo") }.raises(NotImplementedError)
21
+ assert_that{ subject.compile("some content") }
20
22
  .raises(NotImplementedError)
21
23
  end
22
24
  end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "dassets/file_store"
3
5
 
4
6
  class Dassets::FileStore
5
7
  class UnitTests < Assert::Context
6
8
  desc "Dassets::FileStore"
7
- subject { Dassets::FileStore.new(@root.to_s) }
9
+ subject{ Dassets::FileStore.new(@root.to_s) }
8
10
 
9
11
  setup do
10
12
  @root = TEST_SUPPORT_PATH.join("public")
@@ -32,7 +34,7 @@ class Dassets::FileStore
32
34
  content = Factory.text
33
35
  assert_that(@root_path).is_not_a_file
34
36
 
35
- path = subject.save(@url_path) { content }
37
+ path = subject.save(@url_path){ content }
36
38
 
37
39
  assert_that(path).equals(@root_path)
38
40
  assert_that(@root_path).is_a_file
@@ -44,7 +46,7 @@ end
44
46
  class Dassets::NullFileStore
45
47
  class UnitTests < Assert::Context
46
48
  desc "Dassets::NullFileStore"
47
- subject { Dassets::NullFileStore.new }
49
+ subject{ Dassets::NullFileStore.new }
48
50
 
49
51
  setup do
50
52
  @root = TEST_SUPPORT_PATH.join("public")
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "dassets/server/request"
3
5
 
@@ -6,7 +8,7 @@ require "dassets/asset_file"
6
8
  class Dassets::Server::Request
7
9
  class UnitTests < Assert::Context
8
10
  desc "Dassets::Server::Request"
9
- subject { @req }
11
+ subject{ @req }
10
12
 
11
13
  setup do
12
14
  @path = "/file1-daa05c683a4913b268653f7a7e36a5b4.txt"
@@ -28,7 +30,7 @@ class Dassets::Server::Request
28
30
  req =
29
31
  file_request(
30
32
  "GET",
31
- "/nested/file3-d41d8cd98f00b204e9800998ecf8427e.txt"
33
+ "/nested/file3-d41d8cd98f00b204e9800998ecf8427e.txt",
32
34
  )
33
35
  assert_that(req.for_asset_file?).is_true
34
36
 
@@ -36,7 +38,8 @@ class Dassets::Server::Request
36
38
  req = file_request("HEAD", "/file1-daa05c683a4913b268653f7a7e36a5b4.txt")
37
39
  assert_that(req.for_asset_file?).is_true
38
40
 
39
- # find even if fingerprint is *not* matching - just need to have any fingerprint
41
+ # find even if fingerprint is *not* matching - just need to have any
42
+ # fingerprint
40
43
  req = file_request("GET", "/file1-d41d8cd98f00b204e9800998ecf8427e.txt")
41
44
  assert_that(req.for_asset_file?).is_true
42
45
 
@@ -70,7 +73,7 @@ class Dassets::Server::Request
70
73
  def file_request(method, path_info)
71
74
  Dassets::Server::Request.new({
72
75
  "REQUEST_METHOD" => method,
73
- "PATH_INFO" => path_info
76
+ "PATH_INFO" => path_info,
74
77
  })
75
78
  end
76
79
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "dassets/server/response"
3
5
 
@@ -7,7 +9,7 @@ require "dassets/asset_file"
7
9
  class Dassets::Server::Response
8
10
  class UnitTests < Assert::Context
9
11
  desc "Dassets::Server::Response"
10
- subject { @response }
12
+ subject{ @response }
11
13
 
12
14
  setup do
13
15
  @env = {}
@@ -42,9 +44,9 @@ class Dassets::Server::Response
42
44
 
43
45
  exp_headers =
44
46
  @asset_file.response_headers.merge({
45
- "Content-Type" => "text/plain",
47
+ "Content-Type" => "text/plain",
46
48
  "Content-Length" => @asset_file.size.to_s,
47
- "Last-Modified" => @asset_file.mtime.to_s,
49
+ "Last-Modified" => @asset_file.mtime.to_s,
48
50
  })
49
51
  assert_that(resp.headers).equals(exp_headers)
50
52
 
@@ -94,7 +96,7 @@ class Dassets::Server::Response
94
96
 
95
97
  class BodyTests < UnitTests
96
98
  desc "Body"
97
- subject { @body }
99
+ subject{ @body }
98
100
 
99
101
  setup do
100
102
  @body = Body.new(@env, @asset_file)
@@ -189,14 +191,14 @@ class Dassets::Server::Response
189
191
  @partial_begin = @start_chunk * Body::CHUNK_SIZE
190
192
  @partial_chunks = @num_chunks - Factory.integer(@min_num_chunks)
191
193
  @partial_size = @partial_chunks * Body::CHUNK_SIZE
192
- @partial_end = @partial_begin + (@partial_size-1)
194
+ @partial_end = @partial_begin + (@partial_size - 1)
193
195
 
194
196
  @env = { "HTTP_RANGE" => "bytes=#{@partial_begin}-#{@partial_end}" }
195
197
  end
196
198
  end
197
199
 
198
200
  class PartialBodyTests < PartialBodySetupTests
199
- subject { @body }
201
+ subject{ @body }
200
202
 
201
203
  setup do
202
204
  @body = Body.new(@env, @asset_file)