rpcoder 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/lib/rpcoder/param.rb CHANGED
@@ -15,6 +15,14 @@ module RPCoder
15
15
  options[:array?]
16
16
  end
17
17
 
18
+ def array_or_type
19
+ if array?
20
+ "Array"
21
+ else
22
+ type
23
+ end
24
+ end
25
+
18
26
  def original_type?
19
27
  Param.original_types.include?(type.to_sym)
20
28
  end
data/lib/rpcoder.rb CHANGED
@@ -50,19 +50,29 @@ module RPCoder
50
50
  class_dir = dir_to_export_classes(dir)
51
51
  FileUtils.mkdir_p(class_dir)
52
52
 
53
- export_functions(File.join(class_dir, api_class_name.split('.').last + ".as"))
53
+ [
54
+ {:path => File.join(class_dir, api_class_name.split('.').last + "Interface.as"), :content => render_functions_interface},
55
+ {:path => File.join(class_dir, api_class_name.split('.').last + ".as"), :content => render_functions},
56
+ {:path => File.join(class_dir, api_class_name.split('.').last + "Dummy.as"), :content => render_functions_dummy},
57
+ ].each do |hash|
58
+ puts "API: #{hash[:path]}"
59
+ File.open(hash[:path], "w") { |file| file << hash[:content] }
60
+ end
54
61
  types.each { |type| export_type(type, File.join(class_dir, "#{type.name}.as")) }
55
62
  end
56
63
 
57
- def export_functions(path)
58
- puts "API: #{path}"
59
- File.open(path, "w") { |file| file << render_functions }
64
+ def render_functions_interface
65
+ render_erb('APIInterface.erb', binding)
60
66
  end
61
67
 
62
68
  def render_functions
63
69
  render_erb('API.erb', binding)
64
70
  end
65
71
 
72
+ def render_functions_dummy
73
+ render_erb('APIDummy.erb', binding)
74
+ end
75
+
66
76
  def export_type(type, path)
67
77
  puts "Type: #{path}"
68
78
  File.open(path, "w") { |file| file << render_type(type) }
@@ -9,7 +9,7 @@ package <%= name_space %>
9
9
  import mx.rpc.http.HTTPService;
10
10
  import com.adobe.serialization.json.JSON;
11
11
 
12
- public class <%= api_class_name %>
12
+ public class <%= api_class_name %> implements <%= api_class_name %>Interface
13
13
  {
14
14
  public static const CONTINUE :int = 100;
15
15
  public static const SWITCHING_PROTOCOLS :int = 101;
@@ -0,0 +1,63 @@
1
+ /* generated by rpcoder */
2
+
3
+ package <%= name_space %>
4
+ {
5
+ import mx.rpc.events.FaultEvent;
6
+
7
+ public class <%= api_class_name %>Dummy implements <%= api_class_name %>Interface
8
+ {
9
+ var _errors:Array = new Array();
10
+ var _dummy_success:Array = new Array();
11
+
12
+ public function setDummySuccess(function_name:String, success:Array):void
13
+ {
14
+ _dummy_success[function_name] = success;
15
+ }
16
+
17
+ private function getDummySuccess(function_name:String):Array
18
+ {
19
+ return _dummy_success[function_name];
20
+ }
21
+
22
+ public function setError(function_name:String, is_error:Boolean):void
23
+ {
24
+ _errors[function_name] = is_error;
25
+ }
26
+
27
+ private function isError(function_name:String):Boolean
28
+ {
29
+ return _errors[function_name];
30
+ }
31
+
32
+ <%- functions.each do |func| -%>
33
+ /**
34
+ * <%= func.description %>
35
+ *
36
+ <%- func.params.each do |param| -%>
37
+ * @<%= param.name %>:<%= param.type %> <%= param.options[:expect] %> <%= param.options[:description] %>
38
+ <%- end -%>
39
+ * @success:Function
40
+ * @error:Function
41
+ */
42
+ <%-
43
+ params = func.params.map{|i| [i.name, i.type].join(':') } + ['success:Function', 'error:Function']
44
+ -%>
45
+ public function <%= func.name %>(<%= params.join(', ') %>):void
46
+ {
47
+ requestDummy('<%= func.name %>', success, error);
48
+ }
49
+
50
+ <%- end -%>
51
+ public function requestDummy(function_name:String, success:Function, error:Function):void
52
+ {
53
+ if ( isError(function_name) )
54
+ {
55
+ error(new FaultEvent("dummy fault"));
56
+ }
57
+ else
58
+ {
59
+ success.apply(this, getDummySuccess(function_name));
60
+ }
61
+ }
62
+ }
63
+ }
@@ -0,0 +1,24 @@
1
+ /* generated by rpcoder */
2
+
3
+ package <%= name_space %>
4
+ {
5
+ public interface <%= api_class_name %>Interface
6
+ {
7
+ <%- functions.each do |func| -%>
8
+ /**
9
+ * <%= func.description %>
10
+ *
11
+ <%- func.params.each do |param| -%>
12
+ * @<%= param.name %>:<%= param.type %> <%= param.options[:expect] %> <%= param.options[:description] %>
13
+ <%- end -%>
14
+ * @success:Function
15
+ * @error:Function
16
+ */
17
+ <%-
18
+ params = func.params.map{|i| [i.name, i.type].join(':') } + ['success:Function', 'error:Function']
19
+ -%>
20
+ function <%= func.name %>(<%= params.join(', ') %>):void;
21
+
22
+ <%- end -%>
23
+ }
24
+ }
@@ -5,11 +5,11 @@ package <%= name_space %>
5
5
  public class <%= type.name %>
6
6
  {
7
7
  <%- type.fields.each do |field| -%>
8
- private var _<%= field.name %>:<%= field.type %>;
8
+ private var _<%= field.name %>:<%= field.array_or_type %>;
9
9
  <%- end -%>
10
10
 
11
11
  <%- type.fields.each do |field| -%>
12
- public function get <%= field.name %>():<%= field.type %>
12
+ public function get <%= field.name %>():<%= field.array_or_type %>
13
13
  {
14
14
  return _<%= field.name %>;
15
15
  }
data/rpcoder.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rpcoder}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["jugyo", "Toshiyuki Hirooka"]
12
- s.date = %q{2011-05-09}
12
+ s.date = %q{2011-05-11}
13
13
  s.description = %q{Simple JSON HTTP RPC generator for as3}
14
14
  s.email = %q{toshi.hirooka@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -28,9 +28,13 @@ Gem::Specification.new do |s|
28
28
  "lib/rpcoder/param.rb",
29
29
  "lib/rpcoder/type.rb",
30
30
  "lib/templates/API.erb",
31
+ "lib/templates/APIDummy.erb",
32
+ "lib/templates/APIInterface.erb",
31
33
  "lib/templates/Type.erb",
32
34
  "rpcoder.gemspec",
33
35
  "spec/fixtures/foo/bar/API.as",
36
+ "spec/fixtures/foo/bar/APIDummy.as",
37
+ "spec/fixtures/foo/bar/APIInterface.as",
34
38
  "spec/fixtures/foo/bar/Mail.as",
35
39
  "spec/rpcoder/function_spec.rb",
36
40
  "spec/rpcoder/param_spec.rb",
@@ -9,7 +9,7 @@ package foo.bar
9
9
  import mx.rpc.http.HTTPService;
10
10
  import com.adobe.serialization.json.JSON;
11
11
 
12
- public class API
12
+ public class API implements APIInterface
13
13
  {
14
14
  public static const CONTINUE :int = 100;
15
15
  public static const SWITCHING_PROTOCOLS :int = 101;
@@ -0,0 +1,70 @@
1
+ /* generated by rpcoder */
2
+
3
+ package foo.bar
4
+ {
5
+ import mx.rpc.events.FaultEvent;
6
+
7
+ public class APIDummy implements APIInterface
8
+ {
9
+ var _errors:Array = new Array();
10
+ var _dummy_success:Array = new Array();
11
+
12
+ public function setDummySuccess(function_name:String, success:Array):void
13
+ {
14
+ _dummy_success[function_name] = success;
15
+ }
16
+
17
+ private function getDummySuccess(function_name:String):Array
18
+ {
19
+ return _dummy_success[function_name];
20
+ }
21
+
22
+ public function setError(function_name:String, is_error:Boolean):void
23
+ {
24
+ _errors[function_name] = is_error;
25
+ }
26
+
27
+ private function isError(function_name:String):Boolean
28
+ {
29
+ return _errors[function_name];
30
+ }
31
+
32
+ /**
33
+ * get mail
34
+ *
35
+ * @id:int
36
+ * @foo:String ["A", "B"]
37
+ * @bar:Array
38
+ * @baz:Boolean 日本の文字
39
+ * @success:Function
40
+ * @error:Function
41
+ */
42
+ public function getMail(id:int, foo:String, bar:Array, baz:Boolean, success:Function, error:Function):void
43
+ {
44
+ requestDummy('getMail', success, error);
45
+ }
46
+
47
+ /**
48
+ * get mails
49
+ *
50
+ * @success:Function
51
+ * @error:Function
52
+ */
53
+ public function getMails(success:Function, error:Function):void
54
+ {
55
+ requestDummy('getMails', success, error);
56
+ }
57
+
58
+ public function requestDummy(function_name:String, success:Function, error:Function):void
59
+ {
60
+ if ( isError(function_name) )
61
+ {
62
+ error(new FaultEvent("dummy fault"));
63
+ }
64
+ else
65
+ {
66
+ success.apply(this, getDummySuccess(function_name));
67
+ }
68
+ }
69
+ }
70
+ }
@@ -0,0 +1,28 @@
1
+ /* generated by rpcoder */
2
+
3
+ package foo.bar
4
+ {
5
+ public interface APIInterface
6
+ {
7
+ /**
8
+ * get mail
9
+ *
10
+ * @id:int
11
+ * @foo:String ["A", "B"]
12
+ * @bar:Array
13
+ * @baz:Boolean 日本の文字
14
+ * @success:Function
15
+ * @error:Function
16
+ */
17
+ function getMail(id:int, foo:String, bar:Array, baz:Boolean, success:Function, error:Function):void;
18
+
19
+ /**
20
+ * get mails
21
+ *
22
+ * @success:Function
23
+ * @error:Function
24
+ */
25
+ function getMails(success:Function, error:Function):void;
26
+
27
+ }
28
+ }
data/spec/rpcoder_spec.rb CHANGED
@@ -38,8 +38,12 @@ describe "RPCoder" do
38
38
  it { RPCoder.types.size.should == 1 }
39
39
 
40
40
  it 'should render_functions' do
41
+ expected = File.read(File.expand_path('fixtures/foo/bar/APIInterface.as', File.dirname(__FILE__)))
42
+ RPCoder.render_functions_interface.should == expected
41
43
  expected = File.read(File.expand_path('fixtures/foo/bar/API.as', File.dirname(__FILE__)))
42
44
  RPCoder.render_functions.should == expected
45
+ expected = File.read(File.expand_path('fixtures/foo/bar/APIDummy.as', File.dirname(__FILE__)))
46
+ RPCoder.render_functions_dummy.should == expected
43
47
  end
44
48
 
45
49
  it 'should render_type' do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rpcoder
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - jugyo
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-05-09 00:00:00 Z
14
+ date: 2011-05-11 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rspec
@@ -100,9 +100,13 @@ files:
100
100
  - lib/rpcoder/param.rb
101
101
  - lib/rpcoder/type.rb
102
102
  - lib/templates/API.erb
103
+ - lib/templates/APIDummy.erb
104
+ - lib/templates/APIInterface.erb
103
105
  - lib/templates/Type.erb
104
106
  - rpcoder.gemspec
105
107
  - spec/fixtures/foo/bar/API.as
108
+ - spec/fixtures/foo/bar/APIDummy.as
109
+ - spec/fixtures/foo/bar/APIInterface.as
106
110
  - spec/fixtures/foo/bar/Mail.as
107
111
  - spec/rpcoder/function_spec.rb
108
112
  - spec/rpcoder/param_spec.rb
@@ -121,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
125
  requirements:
122
126
  - - ">="
123
127
  - !ruby/object:Gem::Version
124
- hash: 26553161876268994
128
+ hash: -4580541404228971953
125
129
  segments:
126
130
  - 0
127
131
  version: "0"