hem 1.1.2 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ce0720a2204325f9c039e61d06f4f22beab37db
4
- data.tar.gz: 619aad110e585018fad30f2e54f22473aca10e7d
3
+ metadata.gz: 9c2214ffe026377c966275a58d880aa25252d40c
4
+ data.tar.gz: 68652bf1eb37edbee90647547321376e2bfa3340
5
5
  SHA512:
6
- metadata.gz: 859e56bd09b826fc401ca9024cd5deb29dec7da0a0c5064df4457804ffee772b36d3c769828fb056434228f7937028e3dd402dddaaedd65f2af99b6a3dfb4769
7
- data.tar.gz: 182c906fede71dd021565ef39b83937fee8f4a6da160bb1660bde2ef1020458ffaff3121905f2fc71fc0f1ddf3eb2f001d66c630b2cb53e10fa15a8d7a905847
6
+ metadata.gz: 3bf49d38642adc775fdf1077af834d27a655a89fe396344ae600bb29165db708758b8293e310684232c64fc16d13f44aa424428a41fbe500e740161d3cb861cf
7
+ data.tar.gz: c5348d734c3689b91e5312633d08b8ec9497411c57a6e381e5d559d91b78028b742c45b96134de1f841566ab2462cda600c5293bbb6963efe07bc5786af63301
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hem (1.1.2)
4
+ hem (1.2.0)
5
5
  aws-sdk (~> 2.3.8)
6
6
  deepstruct (~> 0.0.7)
7
7
  highline (~> 1.7.3)
@@ -6,29 +6,31 @@ module Hem
6
6
  @opts = {
7
7
  :replacer => Replacer.new,
8
8
  :config_class => Hem::Config::File,
9
+ :template_excludes => [],
9
10
  }.merge! opts
10
11
  @replace_done = false
11
12
  end
12
13
 
13
14
  def setup seed, config
14
- project_path = config[:project_path]
15
+ config = DeepStruct.wrap(config)
16
+ project_path = config.project_path
15
17
 
16
18
  seed.update
17
19
  seed.export project_path, config
18
20
 
19
21
  Dir.chdir(project_path) do
20
- config[:seed][:version] = seed.version
21
- config[:hostname] = "#{config[:name]}.dev"
22
- config[:asset_bucket] = "inviqa-assets-#{config[:name]}"
23
- config[:vm] = {
22
+ config.seed.version = seed.version
23
+ config.hostname = "#{config.name}.dev"
24
+ config.asset_bucket = "inviqa-assets-#{config.name}"
25
+ config.vm = {
24
26
  :project_mount_path => "/vagrant"
25
27
  }
26
- config[:tmp] = {}
28
+ config.tmp = {}
27
29
 
28
30
  Hem.project_path = project_path
29
31
  load_seed_init(config)
30
32
 
31
- @opts[:replacer].replace(config[:project_path], Hem.project_config)
33
+ @opts[:replacer].replace(project_path, config)
32
34
 
33
35
  config.delete :project_path
34
36
  config.delete :tmp
@@ -43,9 +45,17 @@ module Hem
43
45
 
44
46
  private
45
47
 
48
+ def config
49
+ Hem.project_config
50
+ end
51
+
52
+ def option key, value
53
+ @opts[key] = value
54
+ end
55
+
46
56
  def load_seed_init config
47
- Hem.project_config = DeepStruct.wrap(config)
48
- seed_init_file = File.join(config[:project_path], 'seedinit.rb')
57
+ Hem.project_config = config
58
+ seed_init_file = File.join(config.project_path, 'seedinit.rb')
49
59
  if File.exists?(seed_init_file)
50
60
  instance_eval File.read(seed_init_file), seed_init_file
51
61
  File.unlink(seed_init_file)
@@ -2,22 +2,23 @@ module Hem
2
2
  module Lib
3
3
  module Seed
4
4
  class Replacer
5
- def replace(path, tokens)
5
+ def replace(path, tokens, excludes = [])
6
6
  unless !tokens.instance_of?(Hash)
7
7
  raise "Invalid token list (expected Hash)"
8
8
  end
9
9
 
10
- return search_replace(path, tokens)
10
+ return search_replace(path, tokens, excludes)
11
11
  end
12
12
 
13
13
  private
14
14
 
15
- def search_replace(path, tokens, &block)
15
+ def search_replace(path, tokens, excludes = [])
16
16
  require 'erb'
17
17
 
18
18
  template = Template.new(tokens)
19
19
  Hem::Helper.locate('*.erb', nil, path: path, type: 'files').each do |candidate|
20
20
  next unless FileTest.file? candidate # Skip unless file
21
+ next unless excludes.select { |exclude| File.fnmatch?(exclude, candidate) }.empty?
21
22
 
22
23
  content = File.read(candidate)
23
24
  next unless content.force_encoding("UTF-8").valid_encoding? # Skip unless file can be valid UTF-8
data/lib/hem/paths.rb CHANGED
@@ -3,12 +3,15 @@ module Hem
3
3
  attr_accessor :project_path
4
4
 
5
5
  def config_path
6
- config_paths = [ File.join(ENV['HOME'], '.hem'), File.join(ENV['HOME'], '.hobo') ]
7
- config_paths.each do |path|
8
- return path if File.exists? File.join(path, 'config.yaml')
9
- end
6
+ @config_path ||= begin
7
+ config_paths = [ File.join(ENV['HOME'], '.hem'), File.join(ENV['HOME'], '.hobo') ]
8
+ config_paths.each do |path|
9
+ return path if File.exists? File.join(path, 'config.yaml')
10
+ end
10
11
 
11
- return config_paths.first
12
+ FileUtils.mkdir_p(config_paths.first)
13
+ config_paths.first
14
+ end
12
15
  end
13
16
 
14
17
  def seed_cache_path
data/lib/hem/setup.rb CHANGED
@@ -7,7 +7,11 @@ end
7
7
  require_relative 'version'
8
8
  require_relative 'plugins'
9
9
 
10
- gem 'hem', Hem::VERSION unless ENV['HEM_OMNIBUS']
10
+ if ENV['HEM_OMNIBUS']
11
+ $:.push File.expand_path(File.join("..", ".."), __FILE__)
12
+ else
13
+ gem 'hem', Hem::VERSION
14
+ end
11
15
 
12
16
  require 'bundler'
13
17
  require 'hem'
data/lib/hem/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Hem
2
- VERSION = '1.1.2'
2
+ VERSION = '1.2.0'
3
3
 
4
4
  class << self
5
5
  def require_version *requirements
@@ -1,16 +1,24 @@
1
+ OldFile = File
1
2
 
2
3
  describe Hem::Lib::Seed::Replacer do
3
4
  before do
4
5
  FakeFS.activate!
5
- Dir.mkdir("bin")
6
- Dir.mkdir("dir")
6
+ def File.fnmatch?(pattern, path)
7
+ OldFile.fnmatch?(pattern, path)
8
+ end
9
+
10
+ Dir.mkdir('/project')
11
+ Dir.mkdir('/project/bin')
12
+ Dir.mkdir('/project/dir')
13
+ Dir.chdir('/project')
14
+
7
15
  {
8
- "./test1.erb" => "some <%= config.test %> is here",
9
- "./test2.erb" => "no test is here",
10
- "./dir/test.erb" => "subdir <%= config.test %>",
11
- "./dir/nested.erb" => "nested <%= config.nested.test %>",
12
- "./dir/no-utf.erb" => "\xc2 <%= config.test %>", # invalid utf should be skipped
13
- "./bin/test" => "<%= config.test %>" # non-ERB files should be ignored
16
+ "test1.erb" => "some <%= config.test %> is here",
17
+ "test2.erb" => "no test is here",
18
+ "dir/test.erb" => "subdir <%= config.test %>",
19
+ "dir/nested.erb" => "nested <%= config.nested.test %>",
20
+ "dir/no-utf.erb" => "\xc2 <%= config.test %>", # invalid utf should be skipped
21
+ "bin/test" => "<%= config.test %>" # non-ERB files should be ignored
14
22
  }.each do |name, content|
15
23
  File.write(name, content)
16
24
  end
@@ -41,4 +49,12 @@ describe Hem::Lib::Seed::Replacer do
41
49
 
42
50
  File.read("./dir/nested").should eq "nested nested"
43
51
  end
52
+
53
+ it "should exclude excluded patterns" do
54
+ @replacer.replace(".", DeepStruct.wrap({ :test => 'badger' }), ['dir/**'])
55
+
56
+ File.read("./test1").should eq "some badger is here"
57
+ File.read("./dir/test.erb").should eq "subdir <%= config.test %>"
58
+ File.exist?("./dir/test").should be_false
59
+ end
44
60
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hem
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Simons
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-06-14 00:00:00.000000000 Z
12
+ date: 2016-06-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk