codegen 0.0.7 → 0.0.8

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: 7d90cbb9b6ef4ba1b5ee6d82f0ba667d9ac1a15e
4
- data.tar.gz: ce4eaba9f69894e0019972987426742fb3d79404
3
+ metadata.gz: 803c722784aedd3dcf62d5c62ced7e9c95df8a44
4
+ data.tar.gz: 6ce1d3f375bc5c61ad8d06537966b1bc67b81829
5
5
  SHA512:
6
- metadata.gz: af211b40bc1ffbacba39c78a0f75bf34ff9b4d64cba0d2c7d3d249a79cfaa015660645c536d07798de49e9de2d72f356c89af29b05b0b0f91f19cadf3cbeda2f
7
- data.tar.gz: 681857235de46130a4d07f701bbf22f4b23c72035f2af86ff376248d085530a352168480bd86b160d2b3d5d0821f76b2ee264900831886e777f2ce7acef6dedd
6
+ metadata.gz: e0d71fd7b6e5a6687e80d0d47a3e8f2bfbe8784520e99f54fc952a1449086b36cc489d027e2c9939bb84b38ea29f43b4e4fe7cc5a8bfeb2a962ceaad8218569e
7
+ data.tar.gz: f95e21508d4813b70c1b70ce970d6d503b871afda89cff0c60eac808e918da0bca7b4cbed87abfef1e4c41ca2270d74ac496251a0b02f96407dbe01bce225fd3
data/README.md CHANGED
@@ -27,8 +27,9 @@ They don't need to be in this order:
27
27
 
28
28
  - Write full and comprehensive tests.
29
29
  - Split clearly the tests for sources and generators.
30
- - Implement CLI commands.
31
- - Make them beautiful like the Rails or Passenger ones.
30
+ - Implement "codegen.yml" and make it able to support all kinds of sources and generators.
31
+ - Make something like Rails does for code generation, showing pretty colors and prompting users.
32
+ - Support code merging, with declared sections for free user input.
32
33
  - Add other languages other than Java for generating entities.
33
34
  - Add REST API building using grape (!).
34
35
  - Add REST API comsumption for Java.
@@ -98,7 +98,7 @@ module Codegen
98
98
 
99
99
  def define_import package
100
100
  if package != nil && package != ""
101
- "import #{package};"
101
+ "package #{package};"
102
102
  else
103
103
  ""
104
104
  end
@@ -0,0 +1,59 @@
1
+ module Codegen
2
+ module Generators
3
+ class JavaSimpleApi < Base
4
+ converts_to :entity
5
+
6
+ def generate options = {}
7
+ if options[:type] == :entity
8
+ generate_entity options
9
+ end
10
+ end
11
+
12
+ private
13
+ def generate_entity options
14
+ entities = options[:entities]
15
+ package = options[:package] || ""
16
+ destination = options[:destination] || "gen/java/"
17
+
18
+ entities.each do |entity|
19
+ code = make_code_for(entity, package)
20
+ filename = make_filename_for(entity, package, destination)
21
+ save filename, code
22
+ end
23
+ end
24
+
25
+ def make_filename_for entity, package, destination
26
+ "#{destination}#{package.gsub(/\./,"/")}/#{entity.name}.java"
27
+ end
28
+
29
+ def save filename, code
30
+ dir = File.dirname(filename)
31
+ FileUtils.mkdir_p(dir)
32
+ f = File.open(filename, "w+")
33
+ f.puts code
34
+ f.flush
35
+ f.close
36
+ puts "Saved: #{filename}"
37
+ end
38
+
39
+ def make_code_for entity, package
40
+ str = ""
41
+ str << "package #{package};" unless package.is_empty?
42
+ str << """
43
+ public interface #{entity.name}Endpoint {
44
+ @GET
45
+ @Path(\"/#{entity.name.underscore}/{id}.json\")
46
+ @Produces(\"application/json\")
47
+ public #{entity.name} getById(@PathParam(\"id\") String id);
48
+
49
+ @GET
50
+ @Path(\"/#{entity.name.underscore}.json\")
51
+ @Produces(\"application/json\")
52
+ public List<#{entity.name}> getAll();
53
+ }
54
+ """
55
+ str
56
+ end
57
+ end
58
+ end
59
+ end
@@ -1,3 +1,3 @@
1
1
  module Codegen
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codegen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cristian Pereyra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-20 00:00:00.000000000 Z
11
+ date: 2013-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -112,6 +112,7 @@ files:
112
112
  - lib/codegen/generators.rb
113
113
  - lib/codegen/generators/base.rb
114
114
  - lib/codegen/generators/java_pojo.rb
115
+ - lib/codegen/generators/java_simple_api.rb
115
116
  - lib/codegen/sources.rb
116
117
  - lib/codegen/sources/active_record.rb
117
118
  - lib/codegen/sources/base.rb