dressmaker 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/dressmaker +4 -0
- data/lib/dressmaker/configuration.rb +18 -12
- data/lib/dressmaker/configuration/delegators.rb +40 -0
- data/lib/dressmaker/configuration/directory_matcher.rb +25 -0
- data/lib/dressmaker/configuration/directory_rule.rb +24 -17
- data/lib/dressmaker/configuration/file_matcher.rb +22 -0
- data/lib/dressmaker/configuration/file_rule.rb +42 -0
- data/lib/dressmaker/configuration/matcher.rb +16 -0
- data/lib/dressmaker/configuration/rule.rb +18 -0
- data/lib/dressmaker/tasks.rb +0 -0
- data/spec/fixtures/template-test/Pattern +7 -2
- data/spec/fixtures/template-test/bin/runner +1 -0
- data/spec/generate_spec.rb +1 -0
- metadata +9 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/bin/dressmaker
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
class Dressmaker
|
2
2
|
class Configuration
|
3
3
|
|
4
|
-
autoload :
|
4
|
+
autoload :Delegators, File.join(File.dirname(__FILE__), 'configuration', 'delegators')
|
5
|
+
autoload :Rule, File.join(File.dirname(__FILE__), 'configuration', 'rule')
|
6
|
+
autoload :FileRule, File.join(File.dirname(__FILE__), 'configuration', 'file_rule')
|
7
|
+
autoload :DirectoryRule, File.join(File.dirname(__FILE__), 'configuration', 'directory_rule')
|
8
|
+
autoload :Matcher, File.join(File.dirname(__FILE__), 'configuration', 'matcher')
|
9
|
+
autoload :FileMatcher, File.join(File.dirname(__FILE__), 'configuration', 'file_matcher')
|
10
|
+
autoload :DirectoryMatcher, File.join(File.dirname(__FILE__), 'configuration', 'directory_matcher')
|
5
11
|
|
6
12
|
attr_accessor :description_holder
|
7
|
-
attr_reader :options
|
13
|
+
attr_reader :options, :rules
|
8
14
|
|
9
15
|
def self.load(file, options)
|
10
16
|
configuration = new(options)
|
@@ -17,19 +23,19 @@ class Dressmaker
|
|
17
23
|
@rules = []
|
18
24
|
end
|
19
25
|
|
20
|
-
def directory
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
@rules << rule
|
26
|
+
def directory
|
27
|
+
DirectoryMatcher.new(self)
|
28
|
+
end
|
29
|
+
|
30
|
+
def files
|
31
|
+
FileMatcher.new(self)
|
27
32
|
end
|
28
33
|
|
29
34
|
def process!(target)
|
30
|
-
|
31
|
-
|
32
|
-
|
35
|
+
rules.each do |rule|
|
36
|
+
Dir.glob("#{target}/**/*") do |file|
|
37
|
+
rel_file = file[target.size, file.size]
|
38
|
+
rule.inform && rule.execute!(file) if rule.matches?(target, rel_file)
|
33
39
|
end
|
34
40
|
end
|
35
41
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "delegate"
|
2
|
+
|
3
|
+
class Dressmaker
|
4
|
+
class Configuration
|
5
|
+
class Delegators
|
6
|
+
|
7
|
+
class DirectoryDelegator < SimpleDelegator
|
8
|
+
def for(pattern)
|
9
|
+
Dir["#{__getobj__.path}/#{pattern}"].each {|e| Delegators.with(e) {|wrapper_e| yield wrapper_e}}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class FileDelegator < SimpleDelegator
|
14
|
+
def gsub!(pattern, replace = nil, &block)
|
15
|
+
contents = self.read.gsub(pattern, replace, &block)
|
16
|
+
File.open(self.path, 'w') {|f| f << contents }
|
17
|
+
end
|
18
|
+
|
19
|
+
def chmod(mode)
|
20
|
+
File.chmod(mode, self.path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def make_executable!
|
24
|
+
chmod(0755)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.with(target)
|
29
|
+
target = target.path unless target.is_a?(String)
|
30
|
+
if File.directory?(target)
|
31
|
+
yield DirectoryDelegator.new(File.open(target))
|
32
|
+
elsif File.file?(target)
|
33
|
+
yield FileDelegator.new(File.open(target))
|
34
|
+
else
|
35
|
+
yield target
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Dressmaker
|
2
|
+
class Configuration
|
3
|
+
class DirectoryMatcher < Matcher
|
4
|
+
|
5
|
+
attr_reader :configuration
|
6
|
+
|
7
|
+
def initialize(configuration)
|
8
|
+
@configuration = configuration
|
9
|
+
end
|
10
|
+
|
11
|
+
def matches(pattern, &block)
|
12
|
+
rule = DirectoryRule::Pattern.new(pattern, &block)
|
13
|
+
update_description_on_rule(rule)
|
14
|
+
configuration.rules << rule
|
15
|
+
end
|
16
|
+
|
17
|
+
def all(&block)
|
18
|
+
rule = DirectoryRule::All.new(&block)
|
19
|
+
update_description_on_rule(rule)
|
20
|
+
configuration.rules << rule
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -3,32 +3,39 @@ require "delegate"
|
|
3
3
|
|
4
4
|
class Dressmaker
|
5
5
|
class Configuration
|
6
|
-
class DirectoryRule
|
6
|
+
class DirectoryRule < Rule
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
class All < DirectoryRule
|
9
|
+
|
10
|
+
def matches?(base, target)
|
11
|
+
File.directory?(File.join(base, target))
|
12
|
+
end
|
10
13
|
|
11
|
-
def initialize(directory, &action)
|
12
|
-
@directory = directory
|
13
|
-
@action = action
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
class Pattern < DirectoryRule
|
17
|
+
|
18
|
+
attr_reader :pattern, :action
|
19
|
+
|
20
|
+
def initialize(pattern, &action)
|
21
|
+
@pattern = pattern
|
22
|
+
@action = action
|
23
|
+
end
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
+
def matches?(base, target)
|
26
|
+
File.directory?(File.join(base, target)) && File.fnmatch(pattern, target)
|
27
|
+
end
|
28
|
+
|
25
29
|
end
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
31
|
+
attr_accessor :description, :name
|
32
|
+
|
33
|
+
def execute!(target)
|
34
|
+
Delegators.with(File.join(target)) do |dir|
|
35
|
+
action.call(dir)
|
30
36
|
end
|
31
37
|
end
|
38
|
+
|
32
39
|
end
|
33
40
|
end
|
34
41
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Dressmaker
|
2
|
+
class Configuration
|
3
|
+
class FileMatcher < Matcher
|
4
|
+
|
5
|
+
def initialize(configuration)
|
6
|
+
@configuration = configuration
|
7
|
+
end
|
8
|
+
|
9
|
+
def matches(pattern, &block)
|
10
|
+
rule = FileRule.new(pattern, &block)
|
11
|
+
configuration.rules << rule
|
12
|
+
end
|
13
|
+
|
14
|
+
def all(&block)
|
15
|
+
rule = FileRule::All.new(&block)
|
16
|
+
update_description_on_rule(rule)
|
17
|
+
configuration.rules << rule
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'ftools'
|
2
|
+
require "delegate"
|
3
|
+
|
4
|
+
class Dressmaker
|
5
|
+
class Configuration
|
6
|
+
class FileRule < Rule
|
7
|
+
|
8
|
+
class All < FileRule
|
9
|
+
|
10
|
+
def initialize(&action)
|
11
|
+
@action = action
|
12
|
+
end
|
13
|
+
|
14
|
+
def matches?(base, target)
|
15
|
+
File.file?(File.join(base, target))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_reader :directory, :action
|
20
|
+
attr_accessor :description, :name
|
21
|
+
|
22
|
+
class Pattern
|
23
|
+
def initialize(pattern, &action)
|
24
|
+
@pattern = pattern
|
25
|
+
@action = action
|
26
|
+
end
|
27
|
+
|
28
|
+
def matches?(base, target)
|
29
|
+
File.file?(File.join(base, target)) and File.fnmatch(pattern, File.join(base, target))
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def execute!(target)
|
35
|
+
Delegators.with(target) do |file|
|
36
|
+
action.call(file)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Dressmaker
|
2
|
+
class Configuration
|
3
|
+
class Matcher
|
4
|
+
|
5
|
+
attr_reader :configuration
|
6
|
+
|
7
|
+
def update_description_on_rule(rule)
|
8
|
+
if rule.respond_to?(:description=)
|
9
|
+
rule.description = configuration.description_holder
|
10
|
+
configuration.description_holder = nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Dressmaker
|
2
|
+
class Configuration
|
3
|
+
class Rule
|
4
|
+
|
5
|
+
attr_accessor :description, :informed
|
6
|
+
|
7
|
+
def inform
|
8
|
+
Dressmaker.inform(self, description) if description && !informed
|
9
|
+
self.informed = true
|
10
|
+
end
|
11
|
+
|
12
|
+
def informed?
|
13
|
+
informed
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
File without changes
|
@@ -1,6 +1,11 @@
|
|
1
1
|
desc "make executable"
|
2
|
-
directory
|
2
|
+
directory.matches('/bin') do |dir|
|
3
3
|
dir.for('*') { |f|
|
4
|
-
|
4
|
+
f.make_executable!
|
5
5
|
}
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "replace __FILE__ with everyone"
|
9
|
+
files.all do |file|
|
10
|
+
file.gsub!('__FILE__', 'everyone')
|
6
11
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
this is my __FILE__ for lovin'
|
data/spec/generate_spec.rb
CHANGED
@@ -17,6 +17,7 @@ describe 'Dressmaker' do
|
|
17
17
|
File.exist?(File.expand_path(File.join(File.dirname(__FILE__), 'output', 'template-test', 'bin', 'runner'))).should be_true
|
18
18
|
File.executable?(File.expand_path(File.join(File.dirname(__FILE__), 'output', 'template-test', 'bin', 'runner'))).should be_true
|
19
19
|
File.executable?(File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'template-test', 'bin', 'runner'))).should be_false
|
20
|
+
File.read(File.expand_path(File.join(File.dirname(__FILE__), 'output', 'template-test', 'bin', 'runner'))).should == "this is my everyone for lovin'"
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dressmaker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Hull
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-16 00:00:00 -05:00
|
13
13
|
default_executable: dressmaker
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -28,7 +28,14 @@ files:
|
|
28
28
|
- VERSION
|
29
29
|
- lib/dressmaker.rb
|
30
30
|
- lib/dressmaker/configuration.rb
|
31
|
+
- lib/dressmaker/configuration/delegators.rb
|
32
|
+
- lib/dressmaker/configuration/directory_matcher.rb
|
31
33
|
- lib/dressmaker/configuration/directory_rule.rb
|
34
|
+
- lib/dressmaker/configuration/file_matcher.rb
|
35
|
+
- lib/dressmaker/configuration/file_rule.rb
|
36
|
+
- lib/dressmaker/configuration/matcher.rb
|
37
|
+
- lib/dressmaker/configuration/rule.rb
|
38
|
+
- lib/dressmaker/tasks.rb
|
32
39
|
- spec/fixtures/template-test/Pattern
|
33
40
|
- spec/fixtures/template-test/bin/runner
|
34
41
|
- spec/fixtures/template-test/bin/script
|