valise 1.1.4 → 1.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: 455879a100dafe54e0baa03a50d495b22bc34e78
4
- data.tar.gz: 3fb179de644e34d38e4680bd50f730fc824c0cc3
3
+ metadata.gz: 43aa7bebaf1a29a47ba022062399b53bac5c6428
4
+ data.tar.gz: aa6e0e3491bc16a2e8d09383cc5d255a65eef84d
5
5
  SHA512:
6
- metadata.gz: b35098b0c0587b040bb0bbeee1f7e1b2c2f41d9c28e4bf5f7753449a88909a969297f3d7fb887ed1690034f12a9cf557748d3c4af5b88a8ea9f09bde296ba19f
7
- data.tar.gz: e1acc62569e4318f638ef414753380f88ca4a250db916ca4cdb67138ee2204b5090a4be3ab5195d7b02d0b0f01d08f745d5bcc2b98ab5ae0d2eab9f3d1138d45
6
+ metadata.gz: 9715824ab262db5a6b001d123191d51afc33df8e6136de77cb3f08f77c4b98ec3eb716cdc8718dbef2957cc0b157a5d10eb50855a17378f4fbe8d9eeaebea456
7
+ data.tar.gz: 05e6ba644e9408c95a676f87e5bce891a465d9ae500bc3317577c41594fea0574953a1da78b5af6131b91b2403b613935747ee4abe8cd251a27ab3dfa5bbd7e2
@@ -5,16 +5,57 @@ module Valise
5
5
  include Unpath
6
6
  include Enumerable
7
7
 
8
- def self.build(path, value = true)
8
+ class Pattern
9
+ FLAG_NAMES = {
10
+ :extended => File::FNM_EXTGLOB,
11
+ :noextended => ~File::FNM_EXTGLOB,
12
+ :case => ~File::FNM_CASEFOLD,
13
+ :nocase => File::FNM_CASEFOLD,
14
+ :pathname => File::FNM_PATHNAME,
15
+ :nopathname => ~File::FNM_PATHNAME,
16
+ :escape => ~File::FNM_NOESCAPE,
17
+ :noescape => File::FNM_NOESCAPE,
18
+ :dotmatch => File::FNM_DOTMATCH,
19
+ :nodotmatch => ~File::FNM_DOTMATCH,
20
+ }
21
+
22
+ def initialize(match, include, flags)
23
+ @match, @include = match, include
24
+ @flags = 0
25
+ set_flags(flags)
26
+ end
27
+ attr_accessor :match, :include, :flags
28
+
29
+ def set_flags(flags)
30
+ if flags.is_a?(Array)
31
+ flags = flags.reduce(0) do |flags, name|
32
+ flag = FLAG_NAMES.fetch(name) do
33
+ raise "Path match flag name #{name.inspect} not in recognized list: #{FLAG_NAMES.keys.inspect}"
34
+ end
35
+ if flag < 0
36
+ flags & flag
37
+ else
38
+ flags | flag
39
+ end
40
+ end
41
+ end
42
+ @flags = flags
43
+ end
44
+ end
45
+
46
+ def self.build(path, value = true, flags = nil)
9
47
  return path if PathMatcher === path
10
48
  path = Unpath::make_pathname(path).to_s
11
- self.new(path, value)
49
+ self.new(path, value, flags)
12
50
  end
13
51
 
14
- def initialize(first_pattern=nil, first_value=true)
52
+ DEFAULT_FLAGS = File::FNM_EXTGLOB
53
+ def initialize(first_pattern=nil, first_value=true, first_flags = nil)
15
54
  @pattern_pairs = []
16
- set(first_pattern, first_value) unless first_pattern.nil?
55
+ @default_flags = DEFAULT_FLAGS
56
+ set(first_pattern, first_value, first_flags) unless first_pattern.nil?
17
57
  end
58
+ attr_accessor :default_flags
18
59
 
19
60
  def ===(path)
20
61
  path = make_pathname(path)
@@ -25,9 +66,9 @@ module Valise
25
66
  end
26
67
 
27
68
  def fetch(path)
28
- @pattern_pairs.each do |pattern, value|
29
- if path.fnmatch?(pattern)
30
- return value
69
+ @pattern_pairs.each do |pattern|
70
+ if path.fnmatch?(pattern.match, pattern.flags || default_flags)
71
+ return pattern.include
31
72
  end
32
73
  end
33
74
  raise KeyError, "No pattern matches #{path.to_s}"
@@ -39,23 +80,25 @@ module Valise
39
80
  nil
40
81
  end
41
82
 
42
- def set(pattern, value)
43
- @pattern_pairs.delete_if do |old_pattern, _|
44
- pattern == old_pattern
45
- end
46
- @pattern_pairs << [pattern.to_s, value]
83
+ def set(pattern, value, flags = nil)
84
+ add_pattern(Pattern.new(pattern.to_s, value, flags))
47
85
  end
48
86
  alias []= set
49
87
 
50
- def each_pair
51
- @pattern_pairs.each do |pattern, value|
52
- yield pattern, value
88
+ def add_pattern(pattern)
89
+ @pattern_pairs.delete_if do |old_pattern|
90
+ pattern.match == old_pattern.match
53
91
  end
92
+ @pattern_pairs << pattern
93
+ end
94
+
95
+ def each(&block)
96
+ @pattern_pairs.each(&block)
54
97
  end
55
98
 
56
99
  def merge!(other)
57
- other.each_pair do |pattern, value|
58
- set(pattern, value)
100
+ other.each do |pattern|
101
+ add_pattern(pattern)
59
102
  end
60
103
  end
61
104
  end
@@ -0,0 +1,35 @@
1
+ require 'valise/path-matcher'
2
+
3
+ module Valise
4
+ class SetFilter
5
+ def initialize
6
+ @path_matcher = PathMatcher.new
7
+ @set = nil
8
+ end
9
+ attr_reader :path_matcher
10
+ attr_accessor :set
11
+
12
+ def include(pattern, flags = nil)
13
+ path_matcher.set(pattern, true, flags)
14
+ end
15
+
16
+ def exclude(pattern, flags = nil)
17
+ path_matcher.set(pattern, false, flags)
18
+ end
19
+
20
+ def files
21
+ visited = {}
22
+ set.each do |root|
23
+ root.each do |segments|
24
+ next unless path_matcher === segments
25
+ unless visited.has_key?(segments)
26
+ item = set.get(segments).present.first
27
+ visited[segments] = item
28
+ yield(item)
29
+ end
30
+ end
31
+ end
32
+ return visited
33
+ end
34
+ end
35
+ end
data/lib/valise/set.rb CHANGED
@@ -7,6 +7,7 @@ require 'valise/path-matcher'
7
7
  require 'valise/stem-decorator'
8
8
  require 'valise/set/definer'
9
9
  require 'valise/set/extensions-decorator'
10
+ require 'valise/set-filter'
10
11
 
11
12
  module Valise
12
13
  class Set
@@ -184,28 +185,25 @@ module Valise
184
185
  search_roots.each(&block)
185
186
  end
186
187
 
187
- def glob(path_matcher)
188
+ def filter(glob = nil, flags = nil)
189
+ filter = SetFilter.new
190
+ filter.set = self
191
+ unless glob.nil?
192
+ filter.include(glob, flags)
193
+ end
194
+ yield filter if block_given?
195
+ return filter
196
+ end
197
+
198
+ def glob(path_matcher, &block)
188
199
  unless block_given?
189
200
  return self.enum_for(:glob, path_matcher)
190
201
  end
191
202
 
192
- visited = {}
193
- path_matcher = PathMatcher.build(path_matcher)
194
-
195
- search_roots.each do |root|
196
- root.each do |segments|
197
- next unless path_matcher === segments
198
- unless visited.has_key?(segments)
199
- item = get(segments).present.first
200
- visited[segments] = item
201
- yield(item)
202
- end
203
- end
204
- end
205
- return visited
203
+ filter(path_matcher).files(&block)
206
204
  end
207
205
 
208
- ALL_FILES = PathMatcher.build("**")
206
+ ALL_FILES = "**"
209
207
  def files(&block)
210
208
  glob(ALL_FILES, &block)
211
209
  end
data/lib/valise/stack.rb CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  require 'valise/utils'
2
3
  require 'valise/item-enum'
3
4
  require 'valise/strategies/merge-diff'
data/spec/fileset.rb CHANGED
@@ -55,7 +55,7 @@ describe Valise do
55
55
  end
56
56
  end
57
57
 
58
- share_examples_for "a populating Valise" do
58
+ shared_examples_for "a populating Valise" do
59
59
  it "should create files on populate" do
60
60
  pending
61
61
 
data/spec/item.rb CHANGED
@@ -17,18 +17,18 @@ describe "Invidual items in the set" do
17
17
 
18
18
  subject { set.find("item") }
19
19
 
20
- its (:full_path) { should == "root/item" }
20
+ it { expect(subject.full_path).to eq "root/item" }
21
21
 
22
22
  describe "#contents=" do
23
- its (:contents) { should == "testing" }
23
+ it { expect(subject.contents).to eq "testing" }
24
24
 
25
25
  it "raw_file" do
26
- subject.raw_file.path.should == "root/item"
26
+ expect(subject.raw_file.path).to eq "root/item"
27
27
  end
28
28
 
29
29
  it "should make contents available" do
30
30
  subject.open do |file|
31
- file.read.should == "testing"
31
+ expect(file.read).to eq "testing"
32
32
  end
33
33
  end
34
34
  end
data/spec/search-root.rb CHANGED
@@ -15,10 +15,10 @@ describe Valise::SearchRoot do
15
15
  end
16
16
 
17
17
  it "should find a file in the root" do
18
- search_root.present?(%w{file}).should be_true
18
+ expect(search_root.present?(%w{file})).to eq true
19
19
  end
20
20
 
21
21
  it "should raise PathNotInRoot if path isn't in root" do
22
- search_root.present?(%w{nothere}).should be_false
22
+ expect(search_root.present?(%w{nothere})).to eq false
23
23
  end
24
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valise
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Judson Lester
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-06 00:00:00.000000000 Z
11
+ date: 2016-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: corundum
@@ -102,27 +102,91 @@ extra_rdoc_files:
102
102
  files:
103
103
  - doc/README
104
104
  - doc/Specification
105
+ - doc/Specifications
106
+ - doc/coverage/assets/0.5.3/app.js
107
+ - doc/coverage/assets/0.5.3/fancybox/blank.gif
108
+ - doc/coverage/assets/0.5.3/fancybox/fancy_close.png
109
+ - doc/coverage/assets/0.5.3/fancybox/fancy_loading.png
110
+ - doc/coverage/assets/0.5.3/fancybox/fancy_nav_left.png
111
+ - doc/coverage/assets/0.5.3/fancybox/fancy_nav_right.png
112
+ - doc/coverage/assets/0.5.3/fancybox/fancy_shadow_e.png
113
+ - doc/coverage/assets/0.5.3/fancybox/fancy_shadow_n.png
114
+ - doc/coverage/assets/0.5.3/fancybox/fancy_shadow_ne.png
115
+ - doc/coverage/assets/0.5.3/fancybox/fancy_shadow_nw.png
116
+ - doc/coverage/assets/0.5.3/fancybox/fancy_shadow_s.png
117
+ - doc/coverage/assets/0.5.3/fancybox/fancy_shadow_se.png
118
+ - doc/coverage/assets/0.5.3/fancybox/fancy_shadow_sw.png
119
+ - doc/coverage/assets/0.5.3/fancybox/fancy_shadow_w.png
120
+ - doc/coverage/assets/0.5.3/fancybox/fancy_title_left.png
121
+ - doc/coverage/assets/0.5.3/fancybox/fancy_title_main.png
122
+ - doc/coverage/assets/0.5.3/fancybox/fancy_title_over.png
123
+ - doc/coverage/assets/0.5.3/fancybox/fancy_title_right.png
124
+ - doc/coverage/assets/0.5.3/fancybox/fancybox-x.png
125
+ - doc/coverage/assets/0.5.3/fancybox/fancybox-y.png
126
+ - doc/coverage/assets/0.5.3/fancybox/fancybox.png
127
+ - doc/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.css
128
+ - doc/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.pack.js
129
+ - doc/coverage/assets/0.5.3/favicon_green.png
130
+ - doc/coverage/assets/0.5.3/favicon_red.png
131
+ - doc/coverage/assets/0.5.3/favicon_yellow.png
132
+ - doc/coverage/assets/0.5.3/highlight.css
133
+ - doc/coverage/assets/0.5.3/highlight.pack.js
134
+ - doc/coverage/assets/0.5.3/jquery-1.6.2.min.js
135
+ - doc/coverage/assets/0.5.3/jquery.dataTables.min.js
136
+ - doc/coverage/assets/0.5.3/jquery.timeago.js
137
+ - doc/coverage/assets/0.5.3/jquery.url.js
138
+ - doc/coverage/assets/0.5.3/loading.gif
139
+ - doc/coverage/assets/0.5.3/magnify.png
140
+ - doc/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png
141
+ - doc/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_75_ffffff_40x100.png
142
+ - doc/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png
143
+ - doc/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_65_ffffff_1x400.png
144
+ - doc/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_dadada_1x400.png
145
+ - doc/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png
146
+ - doc/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png
147
+ - doc/coverage/assets/0.5.3/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png
148
+ - doc/coverage/assets/0.5.3/smoothness/images/ui-icons_222222_256x240.png
149
+ - doc/coverage/assets/0.5.3/smoothness/images/ui-icons_2e83ff_256x240.png
150
+ - doc/coverage/assets/0.5.3/smoothness/images/ui-icons_454545_256x240.png
151
+ - doc/coverage/assets/0.5.3/smoothness/images/ui-icons_888888_256x240.png
152
+ - doc/coverage/assets/0.5.3/smoothness/images/ui-icons_cd0a0a_256x240.png
153
+ - doc/coverage/assets/0.5.3/smoothness/jquery-ui-1.8.4.custom.css
154
+ - doc/coverage/assets/0.5.3/stylesheet.css
155
+ - doc/coverage/index.html
156
+ - doc/coverage/jquery-1.3.2.min.js
157
+ - doc/coverage/jquery.tablesorter.min.js
158
+ - doc/coverage/lib-fileset-errors_rb.html
159
+ - doc/coverage/lib-fileset-item_rb.html
160
+ - doc/coverage/lib-fileset-populator_rb.html
161
+ - doc/coverage/lib-fileset-search-root_rb.html
162
+ - doc/coverage/lib-fileset-utils_rb.html
163
+ - doc/coverage/lib-fileset_rb.html
164
+ - doc/coverage/print.css
165
+ - doc/coverage/rcov.js
166
+ - doc/coverage/screen.css
167
+ - doc/overview-diagram.svg
105
168
  - lib/valise.rb
106
- - lib/valise/item-enum.rb
107
- - lib/valise/utils.rb
108
- - lib/valise/errors.rb
109
169
  - lib/valise/adapters.rb
110
- - lib/valise/cache.rb
111
- - lib/valise/strategies/set.rb
112
- - lib/valise/strategies/merge-diff.rb
113
- - lib/valise/strategies/serialization.rb
114
170
  - lib/valise/adapters/tilt.rb
171
+ - lib/valise/cache.rb
172
+ - lib/valise/errors.rb
173
+ - lib/valise/item-enum.rb
174
+ - lib/valise/item.rb
115
175
  - lib/valise/path-matcher.rb
116
176
  - lib/valise/search-root.rb
177
+ - lib/valise/set-filter.rb
117
178
  - lib/valise/set.rb
118
179
  - lib/valise/set/definer.rb
119
180
  - lib/valise/set/extensions-decorator.rb
120
181
  - lib/valise/stack.rb
121
182
  - lib/valise/stack/decorator.rb
122
- - lib/valise/stack/prefixes-decorator.rb
123
183
  - lib/valise/stack/extensions-decorator.rb
184
+ - lib/valise/stack/prefixes-decorator.rb
124
185
  - lib/valise/stem-decorator.rb
125
- - lib/valise/item.rb
186
+ - lib/valise/strategies/merge-diff.rb
187
+ - lib/valise/strategies/serialization.rb
188
+ - lib/valise/strategies/set.rb
189
+ - lib/valise/utils.rb
126
190
  - spec/addable.rb
127
191
  - spec/dump-load.rb
128
192
  - spec/error-handling.rb
@@ -137,69 +201,6 @@ files:
137
201
  - spec_help/gem_test_suite.rb
138
202
  - spec_help/spec_helper.rb
139
203
  - spec_help/ungemmer.rb
140
- - doc/overview-diagram.svg
141
- - doc/Specifications
142
- - doc/coverage/lib-fileset-utils_rb.html
143
- - doc/coverage/rcov.js
144
- - doc/coverage/jquery-1.3.2.min.js
145
- - doc/coverage/index.html
146
- - doc/coverage/jquery.tablesorter.min.js
147
- - doc/coverage/assets/0.5.3/highlight.css
148
- - doc/coverage/assets/0.5.3/favicon_yellow.png
149
- - doc/coverage/assets/0.5.3/jquery.dataTables.min.js
150
- - doc/coverage/assets/0.5.3/stylesheet.css
151
- - doc/coverage/assets/0.5.3/fancybox/fancy_shadow_sw.png
152
- - doc/coverage/assets/0.5.3/fancybox/fancy_shadow_e.png
153
- - doc/coverage/assets/0.5.3/fancybox/blank.gif
154
- - doc/coverage/assets/0.5.3/fancybox/fancy_shadow_n.png
155
- - doc/coverage/assets/0.5.3/fancybox/fancy_shadow_s.png
156
- - doc/coverage/assets/0.5.3/fancybox/fancy_shadow_w.png
157
- - doc/coverage/assets/0.5.3/fancybox/fancy_title_over.png
158
- - doc/coverage/assets/0.5.3/fancybox/fancy_close.png
159
- - doc/coverage/assets/0.5.3/fancybox/fancy_loading.png
160
- - doc/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.pack.js
161
- - doc/coverage/assets/0.5.3/fancybox/fancybox-x.png
162
- - doc/coverage/assets/0.5.3/fancybox/fancybox-y.png
163
- - doc/coverage/assets/0.5.3/fancybox/fancy_nav_right.png
164
- - doc/coverage/assets/0.5.3/fancybox/fancybox.png
165
- - doc/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.css
166
- - doc/coverage/assets/0.5.3/fancybox/fancy_title_right.png
167
- - doc/coverage/assets/0.5.3/fancybox/fancy_title_left.png
168
- - doc/coverage/assets/0.5.3/fancybox/fancy_shadow_ne.png
169
- - doc/coverage/assets/0.5.3/fancybox/fancy_title_main.png
170
- - doc/coverage/assets/0.5.3/fancybox/fancy_shadow_nw.png
171
- - doc/coverage/assets/0.5.3/fancybox/fancy_nav_left.png
172
- - doc/coverage/assets/0.5.3/fancybox/fancy_shadow_se.png
173
- - doc/coverage/assets/0.5.3/favicon_green.png
174
- - doc/coverage/assets/0.5.3/magnify.png
175
- - doc/coverage/assets/0.5.3/smoothness/jquery-ui-1.8.4.custom.css
176
- - doc/coverage/assets/0.5.3/smoothness/images/ui-icons_888888_256x240.png
177
- - doc/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png
178
- - doc/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_75_ffffff_40x100.png
179
- - doc/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png
180
- - doc/coverage/assets/0.5.3/smoothness/images/ui-icons_2e83ff_256x240.png
181
- - doc/coverage/assets/0.5.3/smoothness/images/ui-icons_454545_256x240.png
182
- - doc/coverage/assets/0.5.3/smoothness/images/ui-icons_cd0a0a_256x240.png
183
- - doc/coverage/assets/0.5.3/smoothness/images/ui-icons_222222_256x240.png
184
- - doc/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_dadada_1x400.png
185
- - doc/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png
186
- - doc/coverage/assets/0.5.3/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png
187
- - doc/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_65_ffffff_1x400.png
188
- - doc/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png
189
- - doc/coverage/assets/0.5.3/jquery.url.js
190
- - doc/coverage/assets/0.5.3/app.js
191
- - doc/coverage/assets/0.5.3/favicon_red.png
192
- - doc/coverage/assets/0.5.3/highlight.pack.js
193
- - doc/coverage/assets/0.5.3/jquery.timeago.js
194
- - doc/coverage/assets/0.5.3/loading.gif
195
- - doc/coverage/assets/0.5.3/jquery-1.6.2.min.js
196
- - doc/coverage/lib-fileset-item_rb.html
197
- - doc/coverage/lib-fileset-search-root_rb.html
198
- - doc/coverage/lib-fileset_rb.html
199
- - doc/coverage/lib-fileset-errors_rb.html
200
- - doc/coverage/lib-fileset-populator_rb.html
201
- - doc/coverage/screen.css
202
- - doc/coverage/print.css
203
204
  homepage: http://valise.rubyforge.org/
204
205
  licenses:
205
206
  - MIT
@@ -210,7 +211,7 @@ rdoc_options:
210
211
  - --main
211
212
  - doc/README
212
213
  - --title
213
- - valise-1.1.4 RDoc
214
+ - valise-1.2.0 RDoc
214
215
  require_paths:
215
216
  - lib/
216
217
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -225,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
226
  version: '0'
226
227
  requirements: []
227
228
  rubyforge_project: valise
228
- rubygems_version: 2.0.14
229
+ rubygems_version: 2.4.8
229
230
  signing_key:
230
231
  specification_version: 3
231
232
  summary: Manage configuration and data files simply