localconfig 0.3.1 → 0.3.2

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: 8e26ec55b463e0162a17d6fab1a6654ad99b6c75
4
- data.tar.gz: b03ebd9c14f8a0a5b6ddc50bb8a947a81e821b8e
3
+ metadata.gz: 7fd04212aecdab757b1aa37c66c20ec31fe57a6c
4
+ data.tar.gz: 3e59657314b77fbff2777edf7569ffb6119f9c50
5
5
  SHA512:
6
- metadata.gz: 8ffbf1f251062ece9f395b3dcc2ff0bbd047d5f6f4d807da5cac41dfac2cba56e1f1af3d3d411a4e9e2ac21ae2f5bbec91297e41da164680cc02ff047fa8462b
7
- data.tar.gz: 0a4ce2810cb3f7ba03c4d35405c6a21010289b35dfad76a85b5cf784c5e91a554d2cdab0d547877e9256fb7fb4c2e7a5f4a7b0d3992bf6ee0cc8fbbbbe373b64
6
+ metadata.gz: 85e43f62c8d096c22234ee1935d36e744ee5ed7ff7a48bb45244aff0c220a798cfe661aabdf2e9f45aa27c427ba9de24eee9976fc00b3de2610352c07cc0ba74
7
+ data.tar.gz: f8438f461329489edfd3aefe46ee27820b280a0a4bbf32eb94f0a8dbe9655caddc60e2d7544bbaab7d84711cf1537276b544c87645f134357b7427ba7f564023
data/README.md CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  File : README.md
4
4
  Maintainer : Felix C. Stegerman <flx@obfusk.net>
5
- Date : 2014-10-22
5
+ Date : 2014-10-30
6
6
 
7
7
  Copyright : Copyright (C) 2014 Felix C. Stegerman
8
- Version : v0.3.1
8
+ Version : v0.3.2
9
9
 
10
10
  []: }}}1
11
11
 
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # File : localconfig/config.rb
4
4
  # Maintainer : Felix C. Stegerman <flx@obfusk.net>
5
- # Date : 2014-10-22
5
+ # Date : 2014-10-30
6
6
  #
7
7
  # Copyright : Copyright (C) 2014 Felix C. Stegerman
8
8
  # Licence : LGPLv3+
@@ -24,8 +24,7 @@ module LocalConfig
24
24
  # configuration
25
25
  class Config # {{{1
26
26
 
27
- # something went wrong calling `system`
28
- class RunError < StandardError; end
27
+ class Error < StandardError; end
29
28
 
30
29
  # dir
31
30
  attr_accessor :dir
@@ -148,22 +147,30 @@ module LocalConfig
148
147
  #
149
148
  # <!-- }}}2 -->
150
149
  def git_repo(path, url, opts = {}) # {{{2
150
+ %w{ branch rev tag }.count { |x| opts.has_key? x.to_sym } <= 1 \
151
+ or raise ArgumentError,
152
+ "You can't use more than one of :rev, :tag, :branch"
151
153
  q = opts.fetch(:quiet, true) ? %w{ --quiet } : []
154
+ s = opts.fetch(:quiet, true) ?
155
+ -> *a { _sys *a } :
156
+ -> *a { puts "$ #{a*' '}"; _sys *a }
152
157
  b = opts[:branch]; b = "origin/#{b}" if b && !b['/']
153
158
  rev = opts[:rev] || opts[:tag]
154
159
  ref = rev || b || 'origin/master'
155
160
  dest = path path
156
161
  if File.exist? dest
157
162
  Dir.chdir(dest) do
158
- _sys *(%w{ git fetch --force --tags } + q) \
163
+ _git_dir_check
164
+ s[*(%w{ git fetch --force --tags } + q)] \
159
165
  unless rev && %x[ git rev-parse HEAD ] ==
160
166
  %x[ git rev-parse --revs-only #{rev}^0 -- ]
161
167
  end
162
168
  else
163
- _sys *(%w{ git clone } + q + [url, dest])
169
+ s[*(%w{ git clone } + q + [url, dest])]
164
170
  end
165
171
  Dir.chdir(dest) do
166
- _sys *(%w{ git reset --hard } + q + [ref] + %w{ -- })
172
+ _git_dir_check
173
+ s[*(%w{ git reset --hard } + q + [ref] + %w{ -- })]
167
174
  end
168
175
  end # }}}2
169
176
 
@@ -198,10 +205,15 @@ module LocalConfig
198
205
  nil
199
206
  end # }}}2
200
207
 
208
+ # check for .git/
209
+ def _git_dir_check
210
+ File.exist? '.git/' or raise Error, 'not a git dir'
211
+ end
212
+
201
213
  # run!
202
214
  def _sys(cmd, *args)
203
215
  system([cmd, cmd], *args) or \
204
- raise RunError, "failed to run command #{[cmd]+args} (#$?)"
216
+ raise Error, "failed to run command #{[cmd]+args} (#$?)"
205
217
  end
206
218
 
207
219
  end # }}}1
@@ -1,4 +1,4 @@
1
1
  module LocalConfig
2
- VERSION = '0.3.1'
3
- DATE = '2014-10-22'
2
+ VERSION = '0.3.2'
3
+ DATE = '2014-10-30'
4
4
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # File : localconfig/config_spec.rb
4
4
  # Maintainer : Felix C. Stegerman <flx@obfusk.net>
5
- # Date : 2014-10-21
5
+ # Date : 2014-10-30
6
6
  #
7
7
  # Copyright : Copyright (C) 2014 Felix C. Stegerman
8
8
  # Licence : LGPLv3+
@@ -60,9 +60,9 @@ describe lcc do
60
60
  end # }}}1
61
61
 
62
62
  context 'glob' do # {{{1
63
- it '* -> init.rb pg.json x.yaml' do
63
+ it '* -> bar foo init.rb pg.json' do
64
64
  expect(test1.glob('*').sort).to eq \
65
- %w{ init.rb pg.json x.yaml }
65
+ %w{ bar foo init.rb pg.json }
66
66
  end
67
67
  it '*.json -> pg.json' do
68
68
  expect(test1.glob('*.json').sort).to eq %w{ pg.json }
@@ -87,12 +87,22 @@ describe lcc do
87
87
  end # }}}1
88
88
 
89
89
  context 'load_yaml' do # {{{1
90
- it 'loads x.yaml' do
91
- x = test1.dup; x.load_yaml 'x.yaml'
92
- expect(x.x.to_hash).to eq({ 'foo' => 99, 'bar' => 'hi!' })
90
+ it 'loads foo/x.yaml' do
91
+ x = test1.dup; x.load_yaml 'foo/x.yaml'
92
+ expect(x[:foo].x.to_hash).to eq({ 'foo' => 99, 'bar' => 'hi!' })
93
93
  end
94
94
  end # }}}1
95
95
 
96
+ context 'load_dir' do # {{{1
97
+ it 'loads bar/y.yml' do
98
+ x = test1.dup; x.load_dir 'bar'
99
+ expect(x.bar.y.to_hash).to \
100
+ eq({ 'spam' => true, 'eggs' => false })
101
+ end
102
+ end # }}}1
103
+
104
+ # TODO: git_repo
105
+
96
106
  end
97
107
 
98
108
  # vim: set tw=70 sw=2 sts=2 et fdm=marker :
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localconfig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix C. Stegerman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-22 00:00:00.000000000 Z
11
+ date: 2014-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie