valise 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,53 @@
1
+ require 'valise/errors'
2
+
3
+ module Valise
4
+ module Strategies
5
+ class Set
6
+ class << self
7
+ def root_class(&block)
8
+ if superclass == Valise::Strategies::Set
9
+ instance_eval(&block)
10
+ elsif self == Valise::Strategies::Set
11
+ raise "Complete class hierarchy fail"
12
+ else
13
+ superclass.root_class(&block)
14
+ end
15
+ end
16
+
17
+ def classes
18
+ root_class{@classes ||= {}}
19
+ end
20
+
21
+ def instances
22
+ root_class{@instances ||= {}}
23
+ end
24
+
25
+ def [](index)
26
+ classes[index]
27
+ end
28
+
29
+ def register(index)
30
+ classes[index] = self
31
+ end
32
+
33
+ def set_default(klass)
34
+ classes.default = klass
35
+ end
36
+
37
+ def default
38
+ set_default(self)
39
+ end
40
+
41
+ def check!(type)
42
+ classes.fetch(type)
43
+ rescue KeyError
44
+ raise Errors::UnregisteredStrategy.new(self.name, type)
45
+ end
46
+
47
+ def instance(type, options = nil)
48
+ instances[[type, options]] ||= classes[type].new(options)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
data/lib/valise/utils.rb CHANGED
@@ -17,12 +17,40 @@ module Valise
17
17
  module_function :align
18
18
  end
19
19
 
20
+ #XXX This has been overtaken by std-lib Pathname and should be mostly
21
+ #refactored out
20
22
  module Unpath
21
23
  def string_to_segments(string)
22
24
  return string if string.empty?
23
25
  string.split(::File::Separator)
24
26
  end
25
27
 
28
+ def file_from_backtrace(line)
29
+ /(.*):\d+/.match(line)[1]
30
+ end
31
+
32
+ def from_here(rel_path, base_path = nil)
33
+ base_path ||= file_from_backtrace(caller[0])
34
+ collapse(unpath(base_path) + unpath(rel_path))
35
+ end
36
+
37
+ def up_to(up_to = nil, base_path = nil)
38
+ base_path ||= file_from_backtrace(caller[0])
39
+ up_to ||= "lib"
40
+
41
+ abs_path = File::expand_path(base_path)
42
+ base_path = unpath(base_path)
43
+ until base_path.empty? or base_path.last == up_to
44
+ base_path.pop
45
+ end
46
+
47
+ if base_path.empty?
48
+ raise "Relative root #{up_to.inspect} not found in #{abs_path.inspect}"
49
+ end
50
+
51
+ return base_path
52
+ end
53
+
26
54
  def unpath(parts)
27
55
  if Array === parts and parts.length == 1
28
56
  parts = parts[0]
@@ -58,8 +86,16 @@ module Valise
58
86
  segments.each do |segment|
59
87
  case segment
60
88
  when '.'
89
+ when ""
90
+ if collapsed.empty?
91
+ collapsed.push segment
92
+ end
61
93
  when '..'
62
- collapsed.pop
94
+ if collapsed.empty?
95
+ collapsed.push segment
96
+ else
97
+ collapsed.pop
98
+ end
63
99
  else
64
100
  collapsed.push segment
65
101
  end
@@ -75,5 +111,8 @@ module Valise
75
111
  return segments
76
112
  end
77
113
  end
114
+
115
+ module_function :from_here, :up_to
116
+ public :from_here, :up_to
78
117
  end
79
118
  end
data/lib/valise.rb CHANGED
@@ -1,8 +1,17 @@
1
1
  require 'valise/set'
2
2
  require 'valise/errors'
3
+ require 'valise/adapters'
3
4
 
4
5
  module Valise
5
6
  def self.define(&block)
6
7
  Valise::Set.define(&block)
7
8
  end
9
+
10
+ def self.read_only(*dirs)
11
+ Valise::Set.define do
12
+ dirs.each do |dir|
13
+ ro dir
14
+ end
15
+ end
16
+ end
8
17
  end
data/spec/addable.rb CHANGED
@@ -10,32 +10,38 @@ describe Valise do
10
10
  sandbox.new :directory => ".conductor"
11
11
  sandbox.new :directory => "spec"
12
12
  sandbox.new :file => "home/.conductor/existed", :with_contents => "TEST"
13
- one = Valise::Set.define do
13
+ end
14
+
15
+ let :one do
16
+ Valise::Set.define do
14
17
  handle "test", :yaml
15
18
  rw ".conductor"
16
19
  end
20
+ end
17
21
 
18
- two = Valise::Set.define do
22
+ let :two do
23
+ Valise::Set.define do
19
24
  handle "test", nil, :hash_merge
20
25
  defaults do
21
26
  end
22
27
  end
23
-
24
- @sum = one + two
25
28
  end
26
29
 
30
+ let :sum do
31
+ one + two
32
+ end
27
33
 
28
34
  it "should be addable" do
29
- @sum.should be_an_instance_of(Valise::Set)
35
+ sum.should be_an_instance_of(Valise::Set)
30
36
  end
31
37
 
32
38
  it "should add in order" do
33
- @sum[0].should be_an_instance_of(Valise::SearchRoot)
34
- @sum[1].should be_an_instance_of(Valise::DefinedDefaults)
39
+ sum[0].should be_an_instance_of(Valise::SearchRoot)
40
+ sum[1].should be_an_instance_of(Valise::DefinedDefaults)
35
41
  end
36
42
 
37
43
  it "should combine file handlers" do
38
- @sum.merge_diff("test").should == Valise::MergeDiff::HashMerge
39
- @sum.serialization("test").should == Valise::Serialization::YAML
44
+ sum.get("test").merge_diff.should be_a(Valise::Strategies::MergeDiff::HashMerge)
45
+ sum.get("test").dump_load.should be_a(Valise::Strategies::Serialization::YAML)
40
46
  end
41
47
  end
data/spec/fileset.rb CHANGED
@@ -53,22 +53,6 @@ describe Valise do
53
53
  @valise.find(:text).contents.should == "Other text"
54
54
  @valise.find("text").contents.should == "Other text"
55
55
  end
56
-
57
- # it "should get yaml files named with strings" do
58
- # @valise.find(:yaml).contents.should == {:one => 1}
59
- # @valise.find("yaml").contents.should == {:one => 1}
60
- # end
61
-
62
- # it "should get yaml files from the filesystem" do
63
- # sandbox.new :file => "home/.conductor/yaml", :with_contents => "--- \n- Coo\n"
64
- # @valise.find(:yaml).contents.should == ["Coo"]
65
- # @valise.find("yaml").contents.should == ["Coo"]
66
- # end
67
-
68
- # it "should get yaml files named with symbols" do
69
- # @valise.find(:other).contents.should == [3,4,5]
70
- # @valise.find("other").contents.should == [3,4,5]
71
- # end
72
56
  end
73
57
 
74
58
  share_examples_for "a populating Valise" do
@@ -150,31 +134,3 @@ describe Valise do
150
134
  end
151
135
  end
152
136
  end
153
-
154
- describe Valise, " - the unpath method: " do
155
- before do
156
- @search_root = Valise::SearchRoot.new("")
157
- end
158
-
159
- it 'state => ["state"]' do
160
- @search_root.unpath("state").should == %w{state}
161
- end
162
-
163
- it '["step", "step/step"] => ["step", "step", "step"]' do
164
- @search_root.unpath(["step", "step/step"]).should == %w{step step step}
165
- end
166
-
167
- it '/etc/configs => ["", "etc", "configs"]' do
168
- @search_root.unpath("/etc/configs").should == [""] + %w{etc configs}
169
- end
170
-
171
- it '["", "etc", "configs"] => ["", "etc", "configs"]' do
172
- @search_root.unpath(["", "etc", "configs"]).should == [""] + %w{etc configs}
173
- end
174
-
175
- it 'a File => #path' do
176
- @file = File.new(__FILE__)
177
- @path = __FILE__.split("/")
178
- @search_root.unpath(@file)
179
- end
180
- end
@@ -0,0 +1,44 @@
1
+ require 'valise'
2
+ require 'file-sandbox'
3
+
4
+ describe Valise, "glob handling" do
5
+ include FileSandbox
6
+
7
+ let :valise do
8
+ sandbox.new :directory => "base/test"
9
+ Valise::Set.define do
10
+ handle "test/full", :yaml
11
+ handle "**/*.file", :yaml
12
+ handle "path/*.path", :yaml
13
+ rw "base"
14
+ end
15
+ end
16
+
17
+ it "should not recognize unmatched path" do
18
+ valise.get("not_matched/full").dump_load.should_not be_a(Valise::Strategies::Serialization::YAML)
19
+ end
20
+
21
+ it "should not recognize path like a path glob" do
22
+ valise.get("path/full.notpath").should_not be_a(Valise::Strategies::Serialization::YAML)
23
+ end
24
+
25
+ it "should recognize based on a full path" do
26
+ valise.get("test/full").dump_load.should be_a(Valise::Strategies::Serialization::YAML)
27
+ end
28
+
29
+ it "should recognize base on a file glob" do
30
+ valise.get("test/by.file").dump_load.should be_a(Valise::Strategies::Serialization::YAML)
31
+ end
32
+
33
+ it "should recognize simple files based on glob" do
34
+ valise.get("by.file").dump_load.should be_a(Valise::Strategies::Serialization::YAML)
35
+ end
36
+
37
+ it "should recognize deep files based on glob" do
38
+ valise.get("a/b/c/d/e/by.file").dump_load.should be_a(Valise::Strategies::Serialization::YAML)
39
+ end
40
+
41
+ it "should recognize based on a path glob" do
42
+ valise.get("path/by.path").dump_load.should be_a(Valise::Strategies::Serialization::YAML)
43
+ end
44
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-23 00:00:00.000000000 Z
12
+ date: 2013-03-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: corundum
16
- requirement: &82482560 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,12 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *82482560
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  description: ! " Valise provides an API for accessing configuration and data files
26
31
  for your\n application, including the population of default values, and managing
27
32
  search\n paths. Written to encourage a cross-platform approach to maintaining
@@ -31,6 +36,7 @@ email:
31
36
  executables: []
32
37
  extensions: []
33
38
  extra_rdoc_files:
39
+ - doc/overview-diagram.svg
34
40
  - doc/README
35
41
  - doc/Specification
36
42
  - doc/Specifications
@@ -100,30 +106,39 @@ files:
100
106
  - doc/Specification
101
107
  - doc/Specifications
102
108
  - lib/valise.rb
109
+ - lib/valise/item-enum.rb
103
110
  - lib/valise/debugging.rb
104
- - lib/valise/set/definer.rb
105
- - lib/valise/set.rb
111
+ - lib/valise/utils.rb
106
112
  - lib/valise/errors.rb
107
- - lib/valise/item.rb
113
+ - lib/valise/adapters.rb
114
+ - lib/valise/strategies/set.rb
115
+ - lib/valise/strategies/merge-diff.rb
116
+ - lib/valise/strategies/serialization.rb
117
+ - lib/valise/adapters/tilt.rb
108
118
  - lib/valise/path-matcher.rb
109
119
  - lib/valise/search-root.rb
120
+ - lib/valise/set.rb
121
+ - lib/valise/set/definer.rb
122
+ - lib/valise/set/extensions-decorator.rb
110
123
  - lib/valise/stack.rb
124
+ - lib/valise/stack/extensions-decorator.rb
111
125
  - lib/valise/stem-decorator.rb
112
- - lib/valise/utils.rb
126
+ - lib/valise/item.rb
113
127
  - spec/addable.rb
114
- - spec/dump_load.rb
115
- - spec/error_handling.rb
128
+ - spec/dump-load.rb
129
+ - spec/error-handling.rb
116
130
  - spec/fileset.rb
117
- - spec/glob_handling.rb
131
+ - spec/glob-handling.rb
118
132
  - spec/item.rb
119
- - spec/merge_diff.rb
133
+ - spec/merge-diff.rb
120
134
  - spec/population.rb
121
- - spec/search_root.rb
135
+ - spec/search-root.rb
122
136
  - spec/stemming.rb
123
137
  - spec_help/file-sandbox.rb
124
138
  - spec_help/gem_test_suite.rb
125
139
  - spec_help/spec_helper.rb
126
140
  - spec_help/ungemmer.rb
141
+ - doc/overview-diagram.svg
127
142
  - doc/coverage/lib-fileset-utils_rb.html
128
143
  - doc/coverage/rcov.js
129
144
  - doc/coverage/jquery-1.3.2.min.js
@@ -188,13 +203,13 @@ files:
188
203
  homepage: http://valise.rubyforge.org/
189
204
  licenses:
190
205
  - MIT
191
- post_install_message: Another tidy package brought to you by Judson
206
+ post_install_message:
192
207
  rdoc_options:
193
208
  - --inline-source
194
209
  - --main
195
210
  - doc/README
196
211
  - --title
197
- - valise-0.8.2 RDoc
212
+ - valise-0.9.0 RDoc
198
213
  require_paths:
199
214
  - lib/
200
215
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -205,7 +220,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
205
220
  version: '0'
206
221
  segments:
207
222
  - 0
208
- hash: 1028994253
223
+ hash: -29894543
209
224
  required_rubygems_version: !ruby/object:Gem::Requirement
210
225
  none: false
211
226
  requirements:
@@ -214,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
229
  version: '0'
215
230
  requirements: []
216
231
  rubyforge_project: valise
217
- rubygems_version: 1.8.15
232
+ rubygems_version: 1.8.24
218
233
  signing_key:
219
234
  specification_version: 3
220
235
  summary: Manage configuration and data files simply
@@ -1,28 +0,0 @@
1
- require 'valise'
2
- require 'file-sandbox'
3
-
4
- describe Valise, "glob handling" do
5
- include FileSandbox
6
-
7
- let :valise do
8
- sandbox.new :directory => "base/test"
9
- Valise::Set.define do
10
- handle "test/full", :yaml
11
- handle "**/*.file", :yaml
12
- handle "path/*.path", :yaml
13
- rw "base"
14
- end
15
- end
16
-
17
- it "should recognize based on a full path" do
18
- valise.serialization("test/full").should == Valise::Serialization::YAML
19
- end
20
-
21
- it "should recognize base on a file glob" do
22
- valise.serialization("test/by.file").should == Valise::Serialization::YAML
23
- end
24
-
25
- it "should recognize based on a path glob" do
26
- valise.serialization("path/by.path").should == Valise::Serialization::YAML
27
- end
28
- end
File without changes
File without changes
File without changes
File without changes