localconfig 0.3.2 → 0.3.3

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: 7fd04212aecdab757b1aa37c66c20ec31fe57a6c
4
- data.tar.gz: 3e59657314b77fbff2777edf7569ffb6119f9c50
3
+ metadata.gz: f1f47500d4493602aedc393fd4bcc262a7e96fb4
4
+ data.tar.gz: 25bba6b9bda29087ab830d5612c06b9cef3c3831
5
5
  SHA512:
6
- metadata.gz: 85e43f62c8d096c22234ee1935d36e744ee5ed7ff7a48bb45244aff0c220a798cfe661aabdf2e9f45aa27c427ba9de24eee9976fc00b3de2610352c07cc0ba74
7
- data.tar.gz: f8438f461329489edfd3aefe46ee27820b280a0a4bbf32eb94f0a8dbe9655caddc60e2d7544bbaab7d84711cf1537276b544c87645f134357b7427ba7f564023
6
+ metadata.gz: fe400e50bdcef853cd6e43572ec5fac537fbb173d83413bd1fa43f8dd03fc90c8c68cfbc19c3bd0595a58a5ca88f6f5aec3831d22a72daa586af39f9bc2fa534
7
+ data.tar.gz: 0325860c175d06b6c5fc9036c048c0ebcacf92d156cc46058a4a44840e19353c93b1d76dbf3874453f7e6c5d0fea867efa5606eb64c0efabcdc1af72b0969956
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  Date : 2014-10-30
6
6
 
7
7
  Copyright : Copyright (C) 2014 Felix C. Stegerman
8
- Version : v0.3.2
8
+ Version : v0.3.3
9
9
 
10
10
  []: }}}1
11
11
 
@@ -35,6 +35,8 @@
35
35
  ## Examples
36
36
  []: {{{1
37
37
 
38
+ ### Rails
39
+
38
40
  ```ruby
39
41
  # Gemfile
40
42
  gem 'localconfig', require: 'localconfig/rails'
@@ -48,6 +50,11 @@ LocalConfig['rails'].configure do |c|
48
50
  c.require 'init.rb'
49
51
 
50
52
  c.load_json 'pg.json'
53
+ puts c.pg.username
54
+
55
+ c.load_yaml 'foo/bar/baz.json'
56
+ puts c.foo.bar.baz.some_value
57
+
51
58
  c.load_yaml 'git.yml' # repo:, branch:
52
59
  c.git_repo 'more', c.git.repo, branch: c.git.branch
53
60
  c.load_dir 'more' # more/foo.yml, more/bar.json
@@ -62,12 +69,35 @@ LocalConfig['rails'].configure do |c|
62
69
  end
63
70
  ```
64
71
 
72
+ ### Standalone
73
+
74
+ ```ruby
75
+ require 'localconfig' # loads config/localconfig.rb
76
+ ```
77
+
78
+ or:
79
+
80
+ ```ruby
81
+ require 'localconfig/config'
82
+ LocalConfig['foo'].configure do |c|
83
+ # ...
84
+ end
85
+ ```
86
+
87
+ ### Rake
88
+
89
+ ```ruby
90
+ require 'localconfig'
91
+ ManifestDL::Rake.define_tasks
92
+ ```
93
+
65
94
  []: }}}1
66
95
 
67
96
  ## Specs & Docs
68
97
 
69
98
  ```bash
70
99
  rake spec
100
+ rake coverage
71
101
  rake docs
72
102
  ```
73
103
 
data/Rakefile CHANGED
@@ -13,6 +13,11 @@ task 'spec:less' do
13
13
  sh 'rspec -cfd --tty | less -R'
14
14
  end
15
15
 
16
+ desc 'Run specs w/ coverage'
17
+ task :coverage do
18
+ ENV['COVERAGE'] = 'yes'; Rake::Task['spec'].execute
19
+ end
20
+
16
21
  desc 'Check for warnings'
17
22
  task :warn do
18
23
  reqs = %w{ config }.map { |x| "-r localconfig/#{x}" } * ' '
@@ -42,7 +47,7 @@ end
42
47
 
43
48
  desc 'Cleanup'
44
49
  task :clean do
45
- sh 'rm -rf .yardoc/ doc/ *.gem'
50
+ sh 'rm -rf .yardoc/ coverage/ doc/ *.gem'
46
51
  end
47
52
 
48
53
  desc 'Build SNAPSHOT gem'
@@ -34,9 +34,19 @@ module LocalConfig
34
34
 
35
35
  # set dir to ~/.apps, derive name
36
36
  def initialize(opts = {})
37
- @config = {}
38
- @dir = opts[:dir] || "#{Dir.home}/.apps"
39
- @name = opts[:name] || derive_name
37
+ # use Mash: has deep .dup
38
+ @config = Hashie::Mash.new(opts[:config] || {})
39
+ @dir = opts[:dir] || "#{Dir.home}/.apps"
40
+ @name = opts[:name] || derive_name
41
+ @getters = @config.keys.select { |x| !respond_to?(x) }
42
+ @getters.each { |x| define_singleton_method(x) { @config[x] } }
43
+ end
44
+
45
+ alias_method :_dup, :dup
46
+
47
+ # deep duplicate
48
+ def dup
49
+ self.class.new config: @config, dir: @dir.dup, name: @name.dup
40
50
  end
41
51
 
42
52
  # access setting by key
@@ -162,8 +172,7 @@ module LocalConfig
162
172
  Dir.chdir(dest) do
163
173
  _git_dir_check
164
174
  s[*(%w{ git fetch --force --tags } + q)] \
165
- unless rev && %x[ git rev-parse HEAD ] ==
166
- %x[ git rev-parse --revs-only #{rev}^0 -- ]
175
+ unless rev && _git_rev('HEAD') == _git_rev(rev)
167
176
  end
168
177
  else
169
178
  s[*(%w{ git clone } + q + [url, dest])]
@@ -199,8 +208,10 @@ module LocalConfig
199
208
  pre.each { |x| o[x] ||= Hashie::Mash.new; o = o[x] }
200
209
  raise "self.#{(pre+[k])*'.'} already set" if o[k]
201
210
  o[k] = Hashie::Mash.new parse[File.read(f[:path])]
202
- define_singleton_method(c_k) { @config[c_k] } \
203
- unless self.respond_to? c_k
211
+ unless respond_to? c_k
212
+ define_singleton_method(c_k) { @config[c_k] }
213
+ @getters << c_k
214
+ end
204
215
  end
205
216
  nil
206
217
  end # }}}2
@@ -216,6 +227,12 @@ module LocalConfig
216
227
  raise Error, "failed to run command #{[cmd]+args} (#$?)"
217
228
  end
218
229
 
230
+ # get hash for revision or tag
231
+ def _git_rev(rev)
232
+ hash = %x[ git rev-parse --revs-only #{rev}^0 -- 2>/dev/null ]
233
+ $?.success? ? hash.chomp : nil
234
+ end
235
+
219
236
  end # }}}1
220
237
 
221
238
  # --
@@ -1,4 +1,4 @@
1
1
  module LocalConfig
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.3'
3
3
  DATE = '2014-10-30'
4
4
  end
@@ -7,8 +7,6 @@ Gem::Specification.new do |s|
7
7
 
8
8
  s.description = <<-END.gsub(/^ {4}/, '')
9
9
  local configuration for ruby (web) apps
10
-
11
- ...
12
10
  END
13
11
 
14
12
  s.version = LocalConfig::VERSION
@@ -27,6 +25,8 @@ Gem::Specification.new do |s|
27
25
  s.add_runtime_dependency 'rake'
28
26
 
29
27
  s.add_development_dependency 'rspec'
28
+ s.add_development_dependency 'simplecov', '~> 0.9.0' # TODO
29
+ s.add_development_dependency 'yard'
30
30
 
31
31
  s.required_ruby_version = '>= 1.9.1'
32
32
  end
@@ -11,8 +11,14 @@
11
11
 
12
12
  require 'localconfig/config'
13
13
 
14
+ require 'fileutils'
15
+ require 'tmpdir'
16
+
14
17
  lcc = LocalConfig::Config
15
18
 
19
+ gist1 = 'https://gist.github.com/009eae662748f8778bed.git'
20
+ gist2 = 'https://gist.github.com/80edcd5455d348f9ccb7.git'
21
+
16
22
  describe lcc do
17
23
 
18
24
  apps = "#{Dir.pwd}/test/apps"
@@ -101,7 +107,62 @@ describe lcc do
101
107
  end
102
108
  end # }}}1
103
109
 
104
- # TODO: git_repo
110
+ context 'git_repo' do # {{{1
111
+ before(:all) do
112
+ @pwd = Dir.pwd; @dir = Dir.mktmpdir
113
+ FileUtils.mkdir_p "#{@dir}/foo"
114
+ FileUtils.mkdir_p "#{@dir}/apps/foo"
115
+ FileUtils.mkdir_p "#{@dir}/apps/foo/not_a_git_dir"
116
+ Dir.chdir "#{@dir}/foo"
117
+ end
118
+
119
+ before(:each) do
120
+ @lc = lcc.new dir: "#{@dir}/apps"
121
+ end
122
+
123
+ after(:all) do
124
+ Dir.chdir @pwd; FileUtils.remove_entry_secure @dir
125
+ end
126
+
127
+ it 'clones (& .branch is OK)' do
128
+ @lc.git_repo 'lc_gist', gist1
129
+ @lc.load_dir 'lc_gist'
130
+ expect(@lc.lc_gist.foo.to_hash) .to \
131
+ eq({ 'x' => 42, 'y' => 37 })
132
+ expect(@lc.lc_gist.bar.to_hash) .to \
133
+ eq({ 'spam' => true, 'eggs' => false })
134
+ expect(@lc.lc_gist.baz.to_hash) .to \
135
+ eq({ 'answer' => 42 })
136
+ Dir.chdir("#{@dir}/apps/foo/lc_gist") do
137
+ expect(LocalConfig.branch).to eq('master')
138
+ end
139
+ end
140
+ it 'resets' do
141
+ @lc.git_repo 'lc_gist', gist1, rev: 'ba232fd'
142
+ @lc.load_dir 'lc_gist'
143
+ expect(@lc.lc_gist.foo.to_hash) .to \
144
+ eq({ 'x' => 42, 'y' => 99 })
145
+ end
146
+ it 'fetches' do
147
+ Dir.chdir("#{@dir}/apps/foo/lc_gist") do
148
+ system *(%w{ git remote set-url origin } + [gist2]) \
149
+ or raise 'OOPS'
150
+ end
151
+ @lc.git_repo 'lc_gist', gist2, tag: 'tag_2'
152
+ @lc.load_dir 'lc_gist'
153
+ expect(@lc.lc_gist.foo.to_hash) .to \
154
+ eq({ 'x' => 42, 'y' => 37, 'z' => true })
155
+ end
156
+ it 'complains w/ tag + branch' do
157
+ expect { @lc.git_repo 'dummy', gist1, tag: 'foo', branch: 'bar' } \
158
+ .to raise_error(ArgumentError,
159
+ "You can't use more than one of :rev, :tag, :branch")
160
+ end
161
+ it 'complains w/o .git' do
162
+ expect { @lc.git_repo 'not_a_git_dir', gist1 } \
163
+ .to raise_error(lcc::Error, 'not a git dir')
164
+ end
165
+ end # }}}1
105
166
 
106
167
  end
107
168
 
@@ -0,0 +1,4 @@
1
+ if ENV['COVERAGE'] == 'yes'
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localconfig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix C. Stegerman
@@ -52,10 +52,36 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description: |
56
84
  local configuration for ruby (web) apps
57
-
58
- ...
59
85
  email:
60
86
  - flx@obfusk.net
61
87
  executables: []
@@ -73,6 +99,7 @@ files:
73
99
  - lib/localconfig/version.rb
74
100
  - localconfig.gemspec
75
101
  - spec/localconfig/config_spec.rb
102
+ - spec/spec_helper.rb
76
103
  homepage: https://github.com/obfusk/rb-localconfig
77
104
  licenses:
78
105
  - LGPLv3+