palimpsest 0.1.1 → 0.2.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
  SHA1:
3
- metadata.gz: f5c5fd7be63cf42172ba38c5aa33e5be3fa92f83
4
- data.tar.gz: 79170f2245713ce67b510482b3ad4283817aea95
3
+ metadata.gz: c91ac2f955b94300ebb7ad20e909bc52289d256c
4
+ data.tar.gz: dd2e43e3e4a82ae32d5bfd3fefb9d8383554b5b3
5
5
  SHA512:
6
- metadata.gz: 1fbb3b3b92713de6e71c56cd6d3e296e085cf2968d87ff6300eb0cbbb523735c887b137917df09ffbac9e964c3a55ea657ec57a1ab1b58245de8ba0b11b0191e
7
- data.tar.gz: 83ff64c867a93424b6550623dd75a6ef39e9b91440c934f7bcbd85d09fc91eec9df180ed4d249794b722c7ff2f8c5a6b7c4ea0e6805c5ff1be2a4afb51663563
6
+ metadata.gz: 06229184c2aaeec407d38aa6c8b43f2dc7959e47806fedbabd48499b029eb8d93e72630e920639ceee6e044369a7836cf47620839d46141f49b1ee3cceda9fca
7
+ data.tar.gz: 9192ff63c9f12c4648e69d4884817340098e51a8381b87c7b5a2de9f4b6af69fea9dfd8892f4ce01ebabd27ba3b8009bb90da37b732e8d9f0c7343dfcfbe4b54
@@ -1,5 +1,11 @@
1
1
  # Palimpsest ChangeLog
2
2
 
3
+ ## 0.2.0
4
+
5
+ - Added Environment#remove_excludes.
6
+ - Environment#config can be overridden.
7
+ - Environment#copy now uses rsync to exclude .git.
8
+
3
9
  ## 0.1.0
4
10
 
5
11
  - Lots of documentation and improvements.
@@ -32,9 +32,16 @@ module Palimpsest
32
32
  #
33
33
  # # list of external repos
34
34
  # :repos:
35
- # #- [ name, install_path, branch, server (optional) ]
36
- # - [ my_app, apps/my_app, master ]
37
- # - [ sub_app, apps/my_app/sub_app, my_feature, "https://bitbucket.org/razorx" ]
35
+ # #- [ name, install_path, branch, server (optional) ]
36
+ # - [ my_app, apps/my_app, master ]
37
+ # - [ sub_app, apps/my_app/sub_app, my_feature, "https://bitbucket.org/razorx" ]
38
+ #
39
+ # # list of excludes
40
+ # # matching paths are removed with {#remove_excludes}.
41
+ # :excludes:
42
+ # - _assets
43
+ # - apps/*/.gitignore
44
+ #
38
45
  # # asset settings
39
46
  # :assets:
40
47
  # # all options are passed to Assets#options
@@ -85,7 +92,7 @@ module Palimpsest
85
92
  # :options:
86
93
  # # requires the sprockets-image_compressor gem
87
94
  # :image_compression: true
88
- # # options can be overridden per type
95
+ # # options can be overridden per type
89
96
  # :output: images
90
97
  # :paths:
91
98
  # - assets/images
@@ -165,6 +172,7 @@ module Palimpsest
165
172
  # @return [Environment] the current environment instance
166
173
  def cleanup
167
174
  FileUtils.remove_entry_secure directory if @directory
175
+ @config = nil
168
176
  @directory = nil
169
177
  @assets = []
170
178
  @components = []
@@ -190,18 +198,23 @@ module Palimpsest
190
198
  Utility.extract_repo site.repo, treeish, directory
191
199
  @populated = true
192
200
  when :source
193
- FileUtils.cp_r Dir["#{site.source}/*"], directory, preserve: true
201
+ Kernel.system 'rsync', '-rt', %q{--exclude='.git/'}, "#{site.source}/", directory
194
202
  @populated = true
195
203
  end
196
204
 
197
205
  self
198
206
  end
199
207
 
208
+ # @param settings [Hash] merged with current config
200
209
  # @return [Hash] configuration loaded from {#options}`[:config_file]` under {#directory}
201
- def config
202
- populate unless populated
203
- @config = YAML.load_file "#{directory}/#{options[:config_file]}"
204
- validate_config if @config
210
+ def config settings = {}
211
+ if @config.nil?
212
+ populate unless populated
213
+ @config = YAML.load_file "#{directory}/#{options[:config_file]}"
214
+ validate_config if @config
215
+ end
216
+
217
+ @config.merge! settings
205
218
  end
206
219
 
207
220
  # @return [Array<Component>] components with paths loaded from config
@@ -252,6 +265,14 @@ module Palimpsest
252
265
  self
253
266
  end
254
267
 
268
+ # Remove all excludes defined by `config[:excludes]`.
269
+ # @return [Environment] the current environment instance
270
+ def remove_excludes
271
+ return self if config[:excludes].nil?
272
+ config[:excludes].map{ |e| Dir["#{directory}/#{e}"] }.flatten.each { |e| FileUtils.remove_entry_secure e }
273
+ self
274
+ end
275
+
255
276
  # @return [Array<Assets>] assets with settings and paths loaded from config
256
277
  def assets
257
278
  return @assets if @assets
@@ -319,6 +340,10 @@ module Palimpsest
319
340
  end
320
341
  end
321
342
 
343
+ @config[:excludes].each do |v|
344
+ fail RuntimeError, message unless Utility.safe_path? v
345
+ end unless @config[:excludes].nil?
346
+
322
347
  @config[:external].each do |k, v|
323
348
  next if k == :server
324
349
 
@@ -369,7 +394,7 @@ module Palimpsest
369
394
  # process each asset path
370
395
  asset_value.each_with_index do |path, i|
371
396
  fail RuntimeError, message unless Utility.safe_path? path
372
- end
397
+ end if asset_key == :paths
373
398
  end
374
399
  end unless @config[:assets].nil?
375
400
 
@@ -28,6 +28,7 @@ module Palimpsest
28
28
  self.install_path = install_path
29
29
  end
30
30
 
31
+ # @return [String] full path to repo as {#source}`/`{#name}
31
32
  def repo_path
32
33
  ( source.empty? || name.empty? ) ? '' : "#{source}/#{name}"
33
34
  end
@@ -31,19 +31,6 @@ module Palimpsest
31
31
  end
32
32
  end
33
33
 
34
- # Checks that a path is really rooted under a given root directory.
35
- # Forbids use of `../` and `~/` in path.
36
- # @param [String] path
37
- # @param [String] root directory where path should be rooted under
38
- # @return [String] input path if valid
39
- def self.validate_path path, root=''
40
- case
41
- when path[/(\.\.\/|~\/)/] then fail RuntimeError
42
- when File.expand_path(path, root)[/^#{root}/].nil? then fail RuntimeError
43
- else path
44
- end
45
- end
46
-
47
34
  # Extracts a git repo to a directory.
48
35
  # @param [Grit::Repo] repo
49
36
  # @param [String] treeish
@@ -51,6 +38,7 @@ module Palimpsest
51
38
  def self.extract_repo repo, treeish, directory
52
39
  input = Archive::Tar::Minitar::Input.new StringIO.new(repo.archive_tar treeish)
53
40
  input.each { |e| input.extract_entry directory, e }
41
+ FileUtils.remove_entry_secure "#{directory}/pax_global_header"
54
42
  end
55
43
 
56
44
  # Write contents to file.
@@ -1,4 +1,4 @@
1
1
  module Palimpsest
2
2
  # Palimpsest version.
3
- VERSION = '0.1.1'
3
+ VERSION = '0.2.0'
4
4
  end
@@ -7,6 +7,10 @@ describe Palimpsest::Environment do
7
7
 
8
8
  subject(:environment) { Palimpsest::Environment.new }
9
9
 
10
+ before :each do
11
+ allow(Kernel).to receive(:system)
12
+ end
13
+
10
14
  describe ".new" do
11
15
 
12
16
  it "sets default options" do
@@ -149,19 +153,18 @@ describe Palimpsest::Environment do
149
153
  it "copies the source files to the directory preserving mtime" do
150
154
  environment.site = site_1
151
155
  site_1.source = '/path/to/source'
152
- allow(Dir).to receive(:[]).with('/path/to/source/*').and_return( %w(dir_1 dir_2) )
153
- expect(FileUtils).to receive(:cp_r).with( %w(dir_1 dir_2), environment.directory, preserve: true )
156
+ expect(Kernel).to receive(:system).with('rsync', '-rt', %q{--exclude='.git/'}, '/path/to/source/', environment.directory)
154
157
  environment.populate from: :source
155
158
  end
156
159
  end
157
160
  end
158
161
 
159
- describe "config" do
162
+ describe "#config" do
160
163
 
161
164
  subject(:environment) { Palimpsest::Environment.new site: site_1, treeish: 'master' }
162
165
 
163
166
  before :each do
164
- allow(YAML).to receive(:load_file)
167
+ allow(YAML).to receive(:load_file).and_return({})
165
168
  end
166
169
 
167
170
  it "populate if not populated" do
@@ -180,6 +183,32 @@ describe Palimpsest::Environment do
180
183
  expect(YAML).to receive(:load_file).with("#{environment.directory}/palimpsest_config.yml")
181
184
  environment.config
182
185
  end
186
+
187
+ context "settings given" do
188
+
189
+ before :each do
190
+ allow(YAML).to receive(:load_file).with("#{environment.directory}/palimpsest_config.yml")
191
+ .and_return( { conf_1: :val_1, conf_2: :val_2 } )
192
+ end
193
+
194
+ it "merges new settings on first call" do
195
+ expect( environment.config({ conf_3: :val_3 }) ).to eq({ conf_1: :val_1, conf_2: :val_2, conf_3: :val_3 })
196
+ end
197
+
198
+ it "merges new settings on subsequent call" do
199
+ environment.config
200
+ expect( environment.config({ conf_3: :val_3 }) ).to eq({ conf_1: :val_1, conf_2: :val_2, conf_3: :val_3 })
201
+ end
202
+
203
+ it "remembers new settings" do
204
+ environment.config({ conf_3: :val_3 })
205
+ expect(environment.config).to eq({ conf_1: :val_1, conf_2: :val_2, conf_3: :val_3 })
206
+ end
207
+
208
+ it "overwrites current settings" do
209
+ expect( environment.config({ conf_2: :new_val_2 }) ).to eq({ conf_1: :val_1, conf_2: :new_val_2 })
210
+ end
211
+ end
183
212
  end
184
213
 
185
214
  describe "methods that modify the working directory" do
@@ -196,6 +225,9 @@ describe Palimpsest::Environment do
196
225
  :repos:
197
226
  - [ my_app, apps/my_app, master ]
198
227
  - [ sub_app, apps/my_app/sub_app, my_feature, "https://bitbucket.org/razorx" ]
228
+ :excludes:
229
+ - .gitignore
230
+ - apps/*/assets
199
231
  :assets:
200
232
  :options:
201
233
  :output: compiled
@@ -303,6 +335,22 @@ describe Palimpsest::Environment do
303
335
  end
304
336
  end
305
337
 
338
+ describe "#remove_excludes" do
339
+
340
+ it "removes excluded files" do
341
+ allow(Dir).to receive(:[]).with("#{environment.directory}/.gitignore")
342
+ .and_return(["#{environment.directory}/.gitignore"])
343
+
344
+ allow(Dir).to receive(:[]).with("#{environment.directory}/apps/*/assets")
345
+ .and_return( %W(#{environment.directory}/apps/app_1/assets #{environment.directory}/apps/app_2/assets) )
346
+
347
+ expect(FileUtils).to receive(:remove_entry_secure).with("#{environment.directory}/.gitignore")
348
+ expect(FileUtils).to receive(:remove_entry_secure).with("#{environment.directory}/apps/app_1/assets")
349
+ expect(FileUtils).to receive(:remove_entry_secure).with("#{environment.directory}/apps/app_2/assets")
350
+ expect(environment.remove_excludes).to be environment
351
+ end
352
+ end
353
+
306
354
  describe "#assets" do
307
355
 
308
356
  subject(:assets) { environment.assets }
@@ -13,32 +13,27 @@ describe Palimpsest::Utility do
13
13
  end
14
14
  end
15
15
 
16
- describe ".validate_path" do
16
+ describe ".safe_path?" do
17
17
 
18
18
  context "valid path" do
19
19
 
20
- it "returns the input path" do
21
- expect(Palimpsest::Utility.validate_path '/path').to eq '/path'
20
+ it "returns true" do
21
+ expect(Palimpsest::Utility.safe_path? 'path').to be_true
22
22
  end
23
-
24
- it "returns the input path when the root path matches" do
25
- expect(Palimpsest::Utility.validate_path '/path/to/dir', '/path/to').to eq '/path/to/dir'
26
- end
27
-
28
23
  end
29
24
 
30
- context "bad path" do
25
+ context "invalid path" do
31
26
 
32
- it "rasises an error if path contains '../'" do
33
- expect { Palimpsest::Utility.validate_path 'path/with/../in/it' }.to raise_error RuntimeError
27
+ it "returns false if path contains '../'" do
28
+ expect(Palimpsest::Utility.safe_path? 'path/with/../in/it').to be_false
34
29
  end
35
30
 
36
- it "rasises an error if using '~/'" do
37
- expect { Palimpsest::Utility.validate_path '~/path' }.to raise_error RuntimeError
31
+ it "returns false if using '~/'" do
32
+ expect( Palimpsest::Utility.safe_path? '~/path').to be_false
38
33
  end
39
34
 
40
- it "rasises an error if given root does not match path root" do
41
- expect { Palimpsest::Utility.validate_path '/other_root/path', '/root/path' }.to raise_error RuntimeError
35
+ it "returns false if path starts with '/'" do
36
+ expect(Palimpsest::Utility.safe_path? '/path').to be_false
42
37
  end
43
38
  end
44
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: palimpsest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Boyd Sosenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-28 00:00:00.000000000 Z
11
+ date: 2013-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport