ing 0.1.1
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/.gitignore +5 -0
- data/GENERATORS.md +2 -0
- data/LICENSE +18 -0
- data/OPTIONS.md +2 -0
- data/README.md +251 -0
- data/TASKS.md +21 -0
- data/bin/ing +5 -0
- data/examples/rspec_convert.rb +102 -0
- data/ing.gemspec +29 -0
- data/ing.rb +102 -0
- data/lib/ing.rb +78 -0
- data/lib/ing/actions/create_file.rb +105 -0
- data/lib/ing/actions/create_link.rb +57 -0
- data/lib/ing/actions/directory.rb +98 -0
- data/lib/ing/actions/empty_directory.rb +155 -0
- data/lib/ing/actions/file_manipulation.rb +308 -0
- data/lib/ing/actions/inject_into_file.rb +109 -0
- data/lib/ing/commands/boot.rb +76 -0
- data/lib/ing/commands/generate.rb +64 -0
- data/lib/ing/commands/help.rb +87 -0
- data/lib/ing/commands/implicit.rb +59 -0
- data/lib/ing/commands/list.rb +108 -0
- data/lib/ing/dispatcher.rb +132 -0
- data/lib/ing/files.rb +190 -0
- data/lib/ing/lib_trollop.rb +782 -0
- data/lib/ing/shell.rb +390 -0
- data/lib/ing/trollop/parser.rb +17 -0
- data/lib/ing/util.rb +61 -0
- data/lib/ing/version.rb +3 -0
- data/lib/thor/actions/file_manipulation.rb +30 -0
- data/lib/thor/shell/basic.rb +44 -0
- data/test/acceptance/ing_run_tests.rb +164 -0
- data/test/actions/create_file_spec.rb +209 -0
- data/test/actions/create_link_spec.rb +90 -0
- data/test/actions/directory_spec.rb +167 -0
- data/test/actions/empty_directory_spec.rb +146 -0
- data/test/actions/file_manipulation_spec.rb +433 -0
- data/test/actions/inject_into_file_spec.rb +147 -0
- data/test/fixtures/application.rb +2 -0
- data/test/fixtures/app{1}/README +3 -0
- data/test/fixtures/bundle/execute.rb +6 -0
- data/test/fixtures/bundle/main.thor +1 -0
- data/test/fixtures/doc/%file_name%.rb.tt +1 -0
- data/test/fixtures/doc/COMMENTER +10 -0
- data/test/fixtures/doc/README +3 -0
- data/test/fixtures/doc/block_helper.rb +3 -0
- data/test/fixtures/doc/components/.empty_directory +0 -0
- data/test/fixtures/doc/config.rb +1 -0
- data/test/fixtures/doc/config.yaml.tt +1 -0
- data/test/fixtures/group.ing.rb +76 -0
- data/test/fixtures/invok.ing.rb +50 -0
- data/test/fixtures/namespace.ing.rb +52 -0
- data/test/fixtures/require.ing.rb +7 -0
- data/test/fixtures/task.ing.rb +36 -0
- data/test/fixtures/task.thor +10 -0
- data/test/spec_helper.rb +2 -0
- data/test/test_helper.rb +41 -0
- data/todo.yml +7 -0
- metadata +147 -0
@@ -0,0 +1,147 @@
|
|
1
|
+
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
|
+
require File.expand_path("../../lib/ing/files", File.dirname(__FILE__))
|
3
|
+
|
4
|
+
describe Ing::Files::InjectIntoFile do
|
5
|
+
include SpecHelpers
|
6
|
+
|
7
|
+
def reset
|
8
|
+
::FileUtils.rm_rf(destination_root)
|
9
|
+
::FileUtils.cp_r(source_root, destination_root)
|
10
|
+
end
|
11
|
+
|
12
|
+
def invoker(options={})
|
13
|
+
@invoker ||= begin
|
14
|
+
i = MyCounter.new(options)
|
15
|
+
i.destination_root = destination_root
|
16
|
+
i.call 1,2
|
17
|
+
i
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def revoker
|
22
|
+
@revoker ||= begin
|
23
|
+
r = MyCounter.new({:revoke => true})
|
24
|
+
r.destination_root = destination_root
|
25
|
+
r.call 1,2
|
26
|
+
r
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def invoke!(*args, &block)
|
31
|
+
capture(:stdout){ invoker.insert_into_file(*args, &block) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def revoke!(*args, &block)
|
35
|
+
capture(:stdout){ revoker.insert_into_file(*args, &block) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def file
|
39
|
+
File.join(destination_root, "doc/README")
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#invoke!" do
|
43
|
+
before { reset }
|
44
|
+
|
45
|
+
it "changes the file adding content after the flag" do
|
46
|
+
invoke! "doc/README", "\nmore content", :after => "__start__"
|
47
|
+
assert_equal "__start__\nmore content\nREADME\n__end__\n", File.read(file)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "changes the file adding content before the flag" do
|
51
|
+
invoke! "doc/README", "more content\n", :before => "__end__"
|
52
|
+
assert_equal "__start__\nREADME\nmore content\n__end__\n", File.read(file)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "accepts data as a block" do
|
56
|
+
invoke! "doc/README", :before => "__end__" do
|
57
|
+
"more content\n"
|
58
|
+
end
|
59
|
+
assert_equal "__start__\nREADME\nmore content\n__end__\n", File.read(file)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "logs status" do
|
63
|
+
assert_equal " insert doc/README\n",
|
64
|
+
invoke!("doc/README", "\nmore content", :after => "__start__")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "does not change the file if pretending" do
|
68
|
+
invoker :pretend => true
|
69
|
+
invoke! "doc/README", "\nmore content", :after => "__start__"
|
70
|
+
assert_equal "__start__\nREADME\n__end__\n", File.read(file)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "does not change the file if already include content" do
|
74
|
+
invoke! "doc/README", :before => "__end__" do
|
75
|
+
"more content\n"
|
76
|
+
end
|
77
|
+
assert_equal "__start__\nREADME\nmore content\n__end__\n", File.read(file)
|
78
|
+
|
79
|
+
invoke! "doc/README", :before => "__end__" do
|
80
|
+
"more content\n"
|
81
|
+
end
|
82
|
+
assert_equal "__start__\nREADME\nmore content\n__end__\n", File.read(file)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "does change the file if already include content and :force == true" do
|
86
|
+
invoke! "doc/README", :before => "__end__" do
|
87
|
+
"more content\n"
|
88
|
+
end
|
89
|
+
assert_equal "__start__\nREADME\nmore content\n__end__\n", File.read(file)
|
90
|
+
|
91
|
+
invoke! "doc/README", :before => "__end__", :force => true do
|
92
|
+
"more content\n"
|
93
|
+
end
|
94
|
+
assert_equal "__start__\nREADME\nmore content\nmore content\n__end__\n", File.read(file)
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "#revoke!" do
|
100
|
+
before { reset }
|
101
|
+
|
102
|
+
it "substracts the destination file after injection" do
|
103
|
+
invoke! "doc/README", "\nmore content", :after => "__start__"
|
104
|
+
revoke! "doc/README", "\nmore content", :after => "__start__"
|
105
|
+
assert_equal "__start__\nREADME\n__end__\n", File.read(file)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "substracts the destination file before injection" do
|
109
|
+
invoke! "doc/README", "more content\n", :before => "__start__"
|
110
|
+
revoke! "doc/README", "more content\n", :before => "__start__"
|
111
|
+
assert_equal "__start__\nREADME\n__end__\n", File.read(file)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "substracts even with double after injection" do
|
115
|
+
invoke! "doc/README", "\nmore content", :after => "__start__"
|
116
|
+
invoke! "doc/README", "\nanother stuff", :after => "__start__"
|
117
|
+
revoke! "doc/README", "\nmore content", :after => "__start__"
|
118
|
+
assert_equal "__start__\nanother stuff\nREADME\n__end__\n", File.read(file)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "substracts even with double before injection" do
|
122
|
+
invoke! "doc/README", "more content\n", :before => "__start__"
|
123
|
+
invoke! "doc/README", "another stuff\n", :before => "__start__"
|
124
|
+
revoke! "doc/README", "more content\n", :before => "__start__"
|
125
|
+
assert_equal "another stuff\n__start__\nREADME\n__end__\n", File.read(file)
|
126
|
+
end
|
127
|
+
|
128
|
+
it "substracts when prepending" do
|
129
|
+
invoke! "doc/README", "more content\n", :after => /\A/
|
130
|
+
invoke! "doc/README", "another stuff\n", :after => /\A/
|
131
|
+
revoke! "doc/README", "more content\n", :after => /\A/
|
132
|
+
assert_equal "another stuff\n__start__\nREADME\n__end__\n", File.read(file)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "substracts when appending" do
|
136
|
+
invoke! "doc/README", "more content\n", :before => /\z/
|
137
|
+
invoke! "doc/README", "another stuff\n", :before => /\z/
|
138
|
+
revoke! "doc/README", "more content\n", :before => /\z/
|
139
|
+
assert_equal "__start__\nREADME\n__end__\nanother stuff\n", File.read(file)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "shows progress information to the user" do
|
143
|
+
invoke!("doc/README", "\nmore content", :after => "__start__")
|
144
|
+
assert_equal " subtract doc/README\n", revoke!("doc/README", "\nmore content", :after => "__start__")
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'execute')
|
@@ -0,0 +1 @@
|
|
1
|
+
FOO = <%= "FOO" %>
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
class <%= @klass %>; end
|
@@ -0,0 +1 @@
|
|
1
|
+
--- Hi from yaml
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Note: these are Ing::Files fixtures
|
2
|
+
# used in actions specs adapted from Thor
|
3
|
+
|
4
|
+
class MyCounter
|
5
|
+
|
6
|
+
def self.specify_options(expect)
|
7
|
+
expect.opt :third, "The third argument", :type => :numeric, :default => 3,
|
8
|
+
:short => "t"
|
9
|
+
expect.opt :fourth, "The fourth argument", :type => :numeric
|
10
|
+
expect.banner "This generator runs three tasks: one, two and three."
|
11
|
+
end
|
12
|
+
|
13
|
+
include Ing::Files
|
14
|
+
|
15
|
+
def source_root
|
16
|
+
File.expand_path(File.dirname(__FILE__))
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_accessor :destination_root, :options, :first, :second, :shell
|
20
|
+
|
21
|
+
def shell
|
22
|
+
@shell ||= Ing.shell_class.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(options)
|
26
|
+
self.options = options
|
27
|
+
end
|
28
|
+
|
29
|
+
def call(*args)
|
30
|
+
self.first, self.second = args.shift, args.shift
|
31
|
+
one; two; three
|
32
|
+
end
|
33
|
+
|
34
|
+
def one
|
35
|
+
first
|
36
|
+
end
|
37
|
+
|
38
|
+
def two
|
39
|
+
second
|
40
|
+
end
|
41
|
+
|
42
|
+
def three
|
43
|
+
options[:third]
|
44
|
+
end
|
45
|
+
|
46
|
+
def world(&block)
|
47
|
+
result = capture(&block)
|
48
|
+
concat(result.strip + " world!")
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
class WhinyGenerator
|
55
|
+
include Ing::Files
|
56
|
+
|
57
|
+
def source_root
|
58
|
+
File.expand_path(File.dirname(__FILE__))
|
59
|
+
end
|
60
|
+
|
61
|
+
attr_accessor :destination_root, :options, :shell
|
62
|
+
|
63
|
+
def shell
|
64
|
+
@shell ||= Ing.shell_class.new
|
65
|
+
end
|
66
|
+
|
67
|
+
def initialize(options)
|
68
|
+
self.options = options
|
69
|
+
end
|
70
|
+
|
71
|
+
def call(*args)
|
72
|
+
end
|
73
|
+
|
74
|
+
def wrong_arity(required)
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Translates Thor's example
|
2
|
+
# https://github.com/wycats/thor/wiki/Invocations
|
3
|
+
#
|
4
|
+
module Invoking
|
5
|
+
|
6
|
+
class Counter
|
7
|
+
|
8
|
+
def initialize(options); end
|
9
|
+
|
10
|
+
def one
|
11
|
+
puts 1
|
12
|
+
Ing.invoke self.class, :two
|
13
|
+
Ing.invoke self.class, :three
|
14
|
+
end
|
15
|
+
|
16
|
+
def two
|
17
|
+
puts 2
|
18
|
+
Ing.invoke self.class, :three
|
19
|
+
end
|
20
|
+
|
21
|
+
def three
|
22
|
+
puts 3
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
module Executing
|
29
|
+
|
30
|
+
class Counter
|
31
|
+
|
32
|
+
def initialize(options); end
|
33
|
+
|
34
|
+
def one
|
35
|
+
puts 1
|
36
|
+
Ing.execute self.class, :two
|
37
|
+
Ing.execute self.class, :three
|
38
|
+
end
|
39
|
+
|
40
|
+
def two
|
41
|
+
puts 2
|
42
|
+
Ing.execute self.class, :three
|
43
|
+
end
|
44
|
+
|
45
|
+
def three
|
46
|
+
puts 3
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module SomeBaseNamespace
|
2
|
+
|
3
|
+
module One
|
4
|
+
|
5
|
+
module Two
|
6
|
+
|
7
|
+
module Three
|
8
|
+
|
9
|
+
class Echo
|
10
|
+
|
11
|
+
def initialize(options); end
|
12
|
+
|
13
|
+
def call(arg)
|
14
|
+
puts arg
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
module One
|
28
|
+
module Two
|
29
|
+
module Three
|
30
|
+
class Echo
|
31
|
+
|
32
|
+
def initialize(options); end
|
33
|
+
|
34
|
+
def call(arg)
|
35
|
+
puts "wrong"
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Echo
|
45
|
+
|
46
|
+
def initialize(options); end
|
47
|
+
|
48
|
+
def call(arg)
|
49
|
+
puts "also wrong"
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
class CountArgs
|
3
|
+
|
4
|
+
attr_accessor :options
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
self.options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(*args)
|
11
|
+
puts "#{self.class} called with #{args.length} args"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
class Amazing
|
17
|
+
|
18
|
+
def self.specify_options(expect)
|
19
|
+
expect.banner "describe NAME"
|
20
|
+
expect.text "say that someone is amazing"
|
21
|
+
expect.opt :forcefully
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_accessor :options
|
25
|
+
|
26
|
+
def initialize(options)
|
27
|
+
self.options = options
|
28
|
+
end
|
29
|
+
|
30
|
+
def describe(name)
|
31
|
+
ret = "#{name} is amazing"
|
32
|
+
puts options[:forcefully] ? ret.upcase : ret
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
data/test/spec_helper.rb
ADDED