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 +4 -4
- data/README.md +3 -2
- data/lib/codegen/generators/java_pojo.rb +1 -1
- data/lib/codegen/generators/java_simple_api.rb +59 -0
- data/lib/codegen/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 803c722784aedd3dcf62d5c62ced7e9c95df8a44
|
4
|
+
data.tar.gz: 6ce1d3f375bc5c61ad8d06537966b1bc67b81829
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
31
|
-
- Make
|
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.
|
@@ -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
|
data/lib/codegen/version.rb
CHANGED
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.
|
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-
|
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
|