middleman-cdn 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/middleman-cdn/commands.rb +6 -4
- data/lib/middleman-cdn/version.rb +1 -1
- data/middleman-cdn.gemspec +0 -1
- data/spec/lib/middleman-cdn/commands_spec.rb +101 -16
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7df50ddbc16cbcc2aad12f23bc81f594664f71c
|
4
|
+
data.tar.gz: 2bbb29162f24ed5fb9470847460b3052612ed87b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6413c23a7d9080e4846e2c73db67736aa03292567b2e85e6d3ee35ba8468f5a0fe27b11ea2bd4d152136a926317019176da5211e402a961dea6a9529b19495c7
|
7
|
+
data.tar.gz: 70f29c73716425f684dabf4887fcb262362912de4f5e22b0751412a0fba1a7363297ca845960dbb20092367549291826b72f96f6a6199079cb35a08193a538c9
|
@@ -24,14 +24,16 @@ module Middleman
|
|
24
24
|
if options.nil?
|
25
25
|
app_instance = ::Middleman::Application.server.inst
|
26
26
|
unless app_instance.respond_to?(:cdn_options)
|
27
|
-
|
27
|
+
self.class.say_status(nil, "Error: You need to activate the cdn extension in config.rb.\n#{example_configuration}".light_red)
|
28
|
+
raise
|
28
29
|
end
|
29
30
|
options = app_instance.cdn_options
|
30
31
|
end
|
31
32
|
options.filter ||= /.*/
|
32
33
|
|
33
34
|
if cdns.all? { |cdn| options.public_send(cdn.key.to_sym).nil? }
|
34
|
-
|
35
|
+
self.class.say_status(nil, "Error: You must specify a config for one of the supported CDNs.\n#{example_configuration}".light_red)
|
36
|
+
raise
|
35
37
|
end
|
36
38
|
|
37
39
|
files = list_files(options.filter)
|
@@ -56,7 +58,7 @@ module Middleman
|
|
56
58
|
end
|
57
59
|
end
|
58
60
|
|
59
|
-
|
61
|
+
private
|
60
62
|
|
61
63
|
def cdns
|
62
64
|
[
|
@@ -72,7 +74,7 @@ module Middleman
|
|
72
74
|
def example_configuration
|
73
75
|
<<-TEXT
|
74
76
|
|
75
|
-
|
77
|
+
Example configuration:
|
76
78
|
activate :cdn do |cdn|
|
77
79
|
#{cdns.map(&:example_configuration).join}
|
78
80
|
cdn.filter = /\.html/i # default /.*/
|
data/middleman-cdn.gemspec
CHANGED
@@ -1,23 +1,108 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'fog/aws/models/cdn/distributions'
|
3
2
|
|
4
3
|
describe Middleman::Cli::CDN do
|
5
|
-
let(:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
4
|
+
let(:subject) { described_class.new }
|
5
|
+
|
6
|
+
describe '.exit_on_failure?' do
|
7
|
+
it "should return true" do
|
8
|
+
expect(described_class.exit_on_failure?).to eq(true)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '.say_status' do
|
13
|
+
context "defaults" do
|
14
|
+
it "should say" do
|
15
|
+
described_class.say_status(nil, "a status")
|
16
|
+
end
|
17
|
+
end
|
17
18
|
end
|
18
|
-
let(:distribution) { double('distribution', invalidations: double('invalidations')) }
|
19
19
|
|
20
|
-
describe '#
|
21
|
-
|
20
|
+
describe '#cdn_invalidate' do
|
21
|
+
before do
|
22
|
+
allow(Dir).to receive(:chdir).with(anything) { |path, &block| block.call }
|
23
|
+
allow(Dir).to receive(:glob).with('**/*', File::FNM_DOTMATCH).and_return([".", "index.html", "image.png"])
|
24
|
+
allow(File).to receive(:directory?).with(".").and_return(true)
|
25
|
+
allow(File).to receive(:directory?).with("index.html").and_return(false)
|
26
|
+
allow(File).to receive(:directory?).with("image.png").and_return(false)
|
27
|
+
end
|
28
|
+
|
29
|
+
context "all files matched" do
|
30
|
+
context "no cdn provided" do
|
31
|
+
let(:options) do
|
32
|
+
OpenStruct.new({
|
33
|
+
filter: /.*/
|
34
|
+
})
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should invalidate the files with only cloudflare" do
|
38
|
+
expect_any_instance_of(::Middleman::Cli::CloudFlareCDN).to_not receive(:invalidate)
|
39
|
+
expect_any_instance_of(::Middleman::Cli::CloudFrontCDN).to_not receive(:invalidate)
|
40
|
+
expect { subject.cdn_invalidate(options) }.to raise_error(RuntimeError)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "one cdn provided" do
|
45
|
+
let(:options) do
|
46
|
+
OpenStruct.new({
|
47
|
+
cloudflare: {},
|
48
|
+
filter: /.*/
|
49
|
+
})
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should invalidate the files with only cloudflare" do
|
53
|
+
expect_any_instance_of(::Middleman::Cli::CloudFlareCDN).to receive(:invalidate).with(options.cloudflare, ["/index.html", "/image.png", "/"])
|
54
|
+
expect_any_instance_of(::Middleman::Cli::CloudFrontCDN).to_not receive(:invalidate)
|
55
|
+
subject.cdn_invalidate(options)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "all cdns provided" do
|
60
|
+
let(:options) do
|
61
|
+
OpenStruct.new({
|
62
|
+
cloudflare: {},
|
63
|
+
cloudfront: {},
|
64
|
+
filter: /.*/
|
65
|
+
})
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should invalidate the files with all cdns" do
|
69
|
+
expect_any_instance_of(::Middleman::Cli::CloudFlareCDN).to receive(:invalidate).with(options.cloudflare, ["/index.html", "/image.png", "/"])
|
70
|
+
expect_any_instance_of(::Middleman::Cli::CloudFrontCDN).to receive(:invalidate).with(options.cloudfront, ["/index.html", "/image.png", "/"])
|
71
|
+
subject.cdn_invalidate(options)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "some files matched" do
|
77
|
+
let(:options) do
|
78
|
+
OpenStruct.new({
|
79
|
+
cloudflare: {},
|
80
|
+
cloudfront: {},
|
81
|
+
filter: /\.html/
|
82
|
+
})
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should invalidate the files with all cdns" do
|
86
|
+
expect_any_instance_of(::Middleman::Cli::CloudFlareCDN).to receive(:invalidate).with(options.cloudflare, ["/index.html", "/"])
|
87
|
+
expect_any_instance_of(::Middleman::Cli::CloudFrontCDN).to receive(:invalidate).with(options.cloudfront, ["/index.html", "/"])
|
88
|
+
subject.cdn_invalidate(options)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "no files matched" do
|
93
|
+
let(:options) do
|
94
|
+
OpenStruct.new({
|
95
|
+
cloudflare: {},
|
96
|
+
cloudfront: {},
|
97
|
+
filter: /\.htm$/
|
98
|
+
})
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should invalidate the files with all cdns" do
|
102
|
+
expect_any_instance_of(::Middleman::Cli::CloudFlareCDN).to_not receive(:invalidate)
|
103
|
+
expect_any_instance_of(::Middleman::Cli::CloudFrontCDN).to_not receive(:invalidate)
|
104
|
+
subject.cdn_invalidate(options)
|
105
|
+
end
|
106
|
+
end
|
22
107
|
end
|
23
108
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-cdn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leigh McCulloch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fog
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: fastly
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '1.1'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '1.1'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: colorize
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|