hx 0.14.0 → 0.15.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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.14.0
1
+ 0.15.0
data/lib/hx.rb CHANGED
@@ -158,9 +158,7 @@ module CircumfixPath
158
158
  @input = input
159
159
  @prefix = options[:prefix]
160
160
  @suffix = options[:suffix]
161
- prefix = Regexp.quote(@prefix.to_s)
162
- suffix = Regexp.quote(@suffix.to_s)
163
- @regexp = Regexp.new("^#{prefix}(.*)#{suffix}$")
161
+ @regexp = Path.make_circumfix_re(@prefix, @suffix)
164
162
  end
165
163
 
166
164
  private
@@ -184,9 +182,9 @@ class AddPath
184
182
  end
185
183
 
186
184
  def each_entry_path(selector)
187
- @input.each_entry_path(Path::ALL) do |path|
188
- path = add_circumfix(path)
189
- yield path if selector.accept_path? path
185
+ selector = selector.assume_circumfix(@prefix, @suffix)
186
+ @input.each_entry_path(selector) do |path|
187
+ yield add_circumfix(path)
190
188
  end
191
189
  self
192
190
  end
@@ -208,9 +206,9 @@ class StripPath
208
206
  end
209
207
 
210
208
  def each_entry_path(selector)
211
- @input.each_entry_path(Path::ALL) do |path|
212
- path = strip_circumfix(path)
213
- yield path if path and selector.accept_path? path
209
+ selector = selector.elide_circumfix(@prefix, @suffix)
210
+ @input.each_entry_path(selector) do |path|
211
+ yield strip_circumfix(path)
214
212
  end
215
213
  self
216
214
  end
@@ -32,8 +32,8 @@ class RawFiles
32
32
 
33
33
  def initialize(input, options)
34
34
  @entry_dir = Hx.get_pathname(options, :entry_dir)
35
- @post_edit = options[:post_edit]
36
- @post_edit = @post_edit.split(/\s+/) if @post_edit
35
+ @postedit_cmd = options[:postedit_cmd]
36
+ @postedit_cmd = @postedit_cmd.split(/\s+/) if @postedit_cmd
37
37
  end
38
38
 
39
39
  def path_to_pathname(path) ; @entry_dir + path ; end
@@ -54,7 +54,7 @@ class RawFiles
54
54
  end
55
55
  text = yield text
56
56
  Hx.write_file(pathname, text)
57
- system *(@post_edit + [pathname]) if @post_edit
57
+ system *(@postedit_cmd + [pathname]) if @postedit_cmd
58
58
  self
59
59
  end
60
60
 
data/lib/hx/path.rb CHANGED
@@ -38,7 +38,15 @@ module Selector
38
38
  end
39
39
 
40
40
  def ~()
41
- Negation.new(self)
41
+ Negation.build(self)
42
+ end
43
+
44
+ def assume_circumfix(prefix, suffix)
45
+ AssumeCircumfix.build(self, prefix, suffix)
46
+ end
47
+
48
+ def elide_circumfix(prefix, suffix)
49
+ ElideCircumfix.build(self, prefix, suffix)
42
50
  end
43
51
  end
44
52
 
@@ -124,6 +132,10 @@ end
124
132
  class Negation
125
133
  include Selector
126
134
 
135
+ def self.build(selector)
136
+ new(selector)
137
+ end
138
+
127
139
  def initialize(selector)
128
140
  @selector = selector
129
141
  end
@@ -133,5 +145,49 @@ class Negation
133
145
  end
134
146
  end
135
147
 
148
+ class AssumeCircumfix
149
+ include Selector
150
+
151
+ def self.build(selector, prefix, suffix)
152
+ case selector
153
+ when All; ALL
154
+ else; new(selector, prefix, suffix)
155
+ end
156
+ end
157
+
158
+ def initialize(selector, prefix, suffix)
159
+ @selector = selector
160
+ @prefix = prefix
161
+ @suffix = suffix
162
+ end
163
+
164
+ def accept_path?(path)
165
+ @selector.accept_path?("#{@prefix}#{path}#{@suffix}")
166
+ end
167
+ end
168
+
169
+ def self.make_circumfix_re(prefix, suffix)
170
+ quoted_prefix = Regexp.quote(prefix.to_s)
171
+ quoted_suffix = Regexp.quote(suffix.to_s)
172
+ @circumfix_re = /^#{quoted_prefix}(.*)#{quoted_suffix}$/
173
+ end
174
+
175
+ class ElideCircumfix
176
+ include Selector
177
+
178
+ def self.build(selector, prefix, suffix)
179
+ new(selector, prefix, suffix)
180
+ end
181
+
182
+ def initialize(selector, prefix, suffix)
183
+ @selector = selector
184
+ @circumfix_re = Path.make_circumfix_re(prefix, suffix)
185
+ end
186
+
187
+ def accept_path?(path)
188
+ !!(path =~ @circumfix_re and @selector.accept_path?($1))
189
+ end
190
+ end
191
+
136
192
  end
137
193
  end
@@ -83,3 +83,21 @@ describe "Hx::Path::Selector conjunctions" do
83
83
  (Hx::Path::ALL & Hx::Path::ALL).should equal(Hx::Path::ALL)
84
84
  end
85
85
  end
86
+
87
+ describe "Hx::Path::Selector" do
88
+ it "should be able to elide specific circumfixes" do
89
+ filter = Hx::Path.parse_pattern("foo").elide_circumfix("XXX", "YYY")
90
+ filter.should accept_path("XXXfooYYY")
91
+ filter.should_not accept_path("foo")
92
+ filter.should_not accept_path("XXXfoo")
93
+ filter.should_not accept_path("fooYYY")
94
+ end
95
+
96
+ it "should be able to assume specific circumfixes" do
97
+ filter = Hx::Path.parse_pattern("XXXfooYYY").assume_circumfix("XXX", "YYY")
98
+ filter.should accept_path("foo")
99
+ filter.should_not accept_path("XXXfoo")
100
+ filter.should_not accept_path("fooYYY")
101
+ filter.should_not accept_path("XXXfooYYY")
102
+ end
103
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hx
3
3
  version: !ruby/object:Gem::Version
4
- hash: 39
4
+ hash: 35
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 14
8
+ - 15
9
9
  - 0
10
- version: 0.14.0
10
+ version: 0.15.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - MenTaLguY
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-04 00:00:00 -08:00
18
+ date: 2011-03-06 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency