service_contract-generator 0.0.1 → 0.0.2

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: aac254fa739ca42d88359f79b44b92bf3d559bbc
4
- data.tar.gz: 39682e2aaed1f30826270b2e62f8f3516026f44c
3
+ metadata.gz: 4332265d8952d7ebb35e44a3dad5d148d7de7410
4
+ data.tar.gz: 7ac0bc89a60c4323db6fc867279990f909bcce56
5
5
  SHA512:
6
- metadata.gz: d2a55257ef07c152234f3a0903b8df8e9068dc8d9388c008f03ea0351708836c57af18166979e835d96a0b00d10e246767300756b9da03230e09dc6a1a10e45a
7
- data.tar.gz: 9695cc60f495f88ca4523bcfec491e09d0ba7522335d2c79ee37e97597b2230791b6d5a8bb5af01fb5887a3f4aa518cfca795732c1ae15c827c5592a70cda865
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 "new CONTRACT_NAME", "bootstraps a new service_contract"
10
- def new(contract_name)
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}"
@@ -1,5 +1,5 @@
1
1
  module ServiceContract
2
2
  module Generator
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -0,0 +1,11 @@
1
+ @namespace("<%= namespace %>")
2
+
3
+ protocol <%= protocol_name %> {
4
+
5
+ /** The main class for this protocol */
6
+ record <%= protocol_name %> {
7
+ /** The primary key */
8
+ int id;
9
+ }
10
+
11
+ }
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.1
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: