service_contract-generator 0.0.1 → 0.0.2
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4332265d8952d7ebb35e44a3dad5d148d7de7410
|
4
|
+
data.tar.gz: 7ac0bc89a60c4323db6fc867279990f909bcce56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9227711cf96d8460bf7480de456d244e69c54417fc49c16d97413757b1a04d71baa13739a602e2a42534617fcc5f93d6f8ad2f9288cd7615dd6da24fcbe7db0
|
7
|
+
data.tar.gz: 08c7615d430ae3875d67415d023ff5e6d1fdfef7e1448503d4a0976dcbdf13f38144233dda063de4fc7d1b24ffc0d5fbd431db0a35a5866d4c609821b96c9fb4
|
@@ -0,0 +1,66 @@
|
|
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
|
@@ -6,8 +6,20 @@ module ServiceContract
|
|
6
6
|
module Generator
|
7
7
|
class CLI < Thor
|
8
8
|
|
9
|
-
desc "
|
10
|
-
def
|
9
|
+
desc "protocol NAMESPACE PROTOCOL_NAME VERSION", "generate a new protocol"
|
10
|
+
def protocol(namespace, protocol_name, version)
|
11
|
+
folder = File.join("contracts", version, "source")
|
12
|
+
FileUtils.mkdir_p(folder)
|
13
|
+
output_file = File.join(folder, "#{ActiveSupport::Inflector.underscore(protocol_name)}.avdl")
|
14
|
+
b = binding()
|
15
|
+
erb = ERB.new(File.read(File.expand_path("../../../../template/protocol.avdl.erb", __FILE__)))
|
16
|
+
File.open(output_file, 'w') do |file|
|
17
|
+
file.write(erb.result(b))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "gem CONTRACT_NAME", "bootstraps a new service_contract"
|
22
|
+
def gem(contract_name)
|
11
23
|
path = contract_name.gsub("-", "/")
|
12
24
|
module_name = ActiveSupport::Inflector.camelize(path)
|
13
25
|
|
@@ -48,22 +60,12 @@ module ServiceContract
|
|
48
60
|
File.open(gemspec, "w") do |file|
|
49
61
|
file.write(output)
|
50
62
|
end
|
51
|
-
# if match = dependency_line.match(/(\d+):([^\.]+)\.add_de/)
|
52
|
-
# line_number = match[1]
|
53
|
-
# new_line = %{#{match[2]}.add_dependency "service_contract"}
|
54
|
-
# gemspec_contents = ""
|
55
|
-
|
56
|
-
# puts new_line
|
57
|
-
# command = %{sed -i '#{line_number}i\\ #{new_line}' #{gemspec}}
|
58
|
-
# puts command
|
59
|
-
# # `#{command}`
|
60
|
-
# end
|
61
63
|
|
62
64
|
# template files
|
63
65
|
path_to_root = (Array.new(2 + module_name.split("::").length) {".."}).join("/")
|
64
66
|
service_name = ActiveSupport::Inflector.humanize(contract_name)
|
65
67
|
b = binding()
|
66
|
-
Dir.glob(File.expand_path("../../../../template/*.erb", __FILE__)).each do |template|
|
68
|
+
Dir.glob(File.expand_path("../../../../template/*.rb.erb", __FILE__)).each do |template|
|
67
69
|
erb = ERB.new(File.read(template))
|
68
70
|
output_file = File.join(contract_name, 'lib', path, File.basename(template, ".erb"))
|
69
71
|
puts "writing template: #{output_file}"
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Ching
|
@@ -83,9 +83,11 @@ 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
|
86
87
|
- lib/service_contract/generator/version.rb
|
87
88
|
- service_contract-generator.gemspec
|
88
89
|
- template/documentation.rb.erb
|
90
|
+
- template/protocol.avdl.erb
|
89
91
|
- template/service.rb.erb
|
90
92
|
homepage: ''
|
91
93
|
licenses:
|