service_contract-generator 0.0.2 → 0.0.3
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2140ab1d446df2a7a91e633c4a8dc3d9eea06f80
|
4
|
+
data.tar.gz: b6ec2abd59d37878109217fe1a75898858913462
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c451cb4a8428cc7a95a4c41620bcdfe5899a910a63d60faa0d06782aeac6796f944a4848c90751e344b7380055dae16e3ad3cd4c9ee173e4b5e082c9ea8567a7
|
7
|
+
data.tar.gz: 2a268a1139c712ebc2357fdba23b02bbefcb5503af27cbd6da9f9ebba34ee74a5901bc79d17de7384065d05114dc4e73b6cfab66f9690f14463c4fb286f51798
|
@@ -12,16 +12,14 @@ module ServiceContract
|
|
12
12
|
FileUtils.mkdir_p(folder)
|
13
13
|
output_file = File.join(folder, "#{ActiveSupport::Inflector.underscore(protocol_name)}.avdl")
|
14
14
|
b = binding()
|
15
|
-
|
16
|
-
File.open(output_file, 'w') do |file|
|
17
|
-
file.write(erb.result(b))
|
18
|
-
end
|
15
|
+
write_template("protocol.avdl.erb", output_file, b)
|
19
16
|
end
|
20
17
|
|
21
18
|
desc "gem CONTRACT_NAME", "bootstraps a new service_contract"
|
22
19
|
def gem(contract_name)
|
23
20
|
path = contract_name.gsub("-", "/")
|
24
21
|
module_name = ActiveSupport::Inflector.camelize(path)
|
22
|
+
module_names = module_name.split("::")
|
25
23
|
|
26
24
|
# create directory structure
|
27
25
|
commands = [
|
@@ -65,13 +63,22 @@ module ServiceContract
|
|
65
63
|
path_to_root = (Array.new(2 + module_name.split("::").length) {".."}).join("/")
|
66
64
|
service_name = ActiveSupport::Inflector.humanize(contract_name)
|
67
65
|
b = binding()
|
68
|
-
|
69
|
-
erb = ERB.new(File.read(template))
|
66
|
+
%w(documentation.rb.erb service.rb.erb).each do |template|
|
70
67
|
output_file = File.join(contract_name, 'lib', path, File.basename(template, ".erb"))
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
68
|
+
write_template(template, output_file, b)
|
69
|
+
end
|
70
|
+
|
71
|
+
write_template("module.rb.erb", File.join(contract_name, "lib", "#{path}.rb"), b)
|
72
|
+
end
|
73
|
+
|
74
|
+
protected
|
75
|
+
|
76
|
+
def write_template(name, output_file, bind)
|
77
|
+
template_folder = File.expand_path("../../../../template", __FILE__)
|
78
|
+
input = File.join(template_folder, name)
|
79
|
+
erb = ERB.new(File.read(input))
|
80
|
+
File.open(output_file, 'w') do |file|
|
81
|
+
file.write(erb.result(bind))
|
75
82
|
end
|
76
83
|
end
|
77
84
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: service_contract-generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Ching
|
@@ -83,10 +83,10 @@ files:
|
|
83
83
|
- lib/service_contract-generator.rb
|
84
84
|
- lib/service_contract/generator.rb
|
85
85
|
- lib/service_contract/generator/cli.rb
|
86
|
-
- lib/service_contract/generator/cli/contract.rb
|
87
86
|
- lib/service_contract/generator/version.rb
|
88
87
|
- service_contract-generator.gemspec
|
89
88
|
- template/documentation.rb.erb
|
89
|
+
- template/module.rb.erb
|
90
90
|
- template/protocol.avdl.erb
|
91
91
|
- template/service.rb.erb
|
92
92
|
homepage: ''
|
@@ -1,66 +0,0 @@
|
|
1
|
-
module ServiceContract
|
2
|
-
module Generator
|
3
|
-
module CLI
|
4
|
-
class Contract < Thor
|
5
|
-
desc "new"
|
6
|
-
|
7
|
-
desc "gem CONTRACT_NAME", "bootstraps a new service_contract"
|
8
|
-
def gem(contract_name)
|
9
|
-
path = contract_name.gsub("-", "/")
|
10
|
-
module_name = ActiveSupport::Inflector.camelize(path)
|
11
|
-
|
12
|
-
# create directory structure
|
13
|
-
commands = [
|
14
|
-
# create gem stub
|
15
|
-
%{bundle gem #{contract_name}},
|
16
|
-
|
17
|
-
# create contracts folder
|
18
|
-
%{mkdir -p #{contract_name}/contracts/},
|
19
|
-
%{touch #{contract_name}/contracts/},
|
20
|
-
|
21
|
-
# append tasks to Rakefile
|
22
|
-
%{echo "require 'service_contract/tasks'" >> #{contract_name}/Rakefile}
|
23
|
-
]
|
24
|
-
commands.each do |command|
|
25
|
-
puts command
|
26
|
-
`#{command}`
|
27
|
-
end
|
28
|
-
|
29
|
-
# add service_contract to .gemspec
|
30
|
-
gemspec = "#{contract_name}/#{contract_name}.gemspec"
|
31
|
-
dependency_line = `grep -m 1 -n '.add_de' #{gemspec}`
|
32
|
-
matched = false
|
33
|
-
output = ""
|
34
|
-
File.open(gemspec, "r") do |file|
|
35
|
-
file.each_line do |line|
|
36
|
-
puts line
|
37
|
-
if !matched && match = line.match(/([^\.]+)\.add_de/)
|
38
|
-
puts "matched"
|
39
|
-
output += %{#{match[1]}.add_dependency "service_contract"\n}
|
40
|
-
matched = true
|
41
|
-
end
|
42
|
-
output += line
|
43
|
-
end
|
44
|
-
end
|
45
|
-
puts output
|
46
|
-
File.open(gemspec, "w") do |file|
|
47
|
-
file.write(output)
|
48
|
-
end
|
49
|
-
|
50
|
-
# template files
|
51
|
-
path_to_root = (Array.new(2 + module_name.split("::").length) {".."}).join("/")
|
52
|
-
service_name = ActiveSupport::Inflector.humanize(contract_name)
|
53
|
-
b = binding()
|
54
|
-
Dir.glob(File.expand_path("../../../../template/*.erb", __FILE__)).each do |template|
|
55
|
-
erb = ERB.new(File.read(template))
|
56
|
-
output_file = File.join(contract_name, 'lib', path, File.basename(template, ".erb"))
|
57
|
-
puts "writing template: #{output_file}"
|
58
|
-
File.open(output_file, 'w') do |file|
|
59
|
-
file.write(erb.result(b))
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|