swxruby 0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +21 -0
- data/LICENSE +20 -0
- data/README +143 -0
- data/Rakefile +111 -0
- data/bin/swxruby +58 -0
- data/examples/standalone/standalone.fla +0 -0
- data/examples/standalone/standalone.rb +37 -0
- data/examples/standalone/standalone.swf +0 -0
- data/init.rb +22 -0
- data/install.rb +69 -0
- data/lib/swxruby.rb +6 -0
- data/lib/swxruby/bytecode_converter.rb +139 -0
- data/lib/swxruby/core_extensions.rb +41 -0
- data/lib/swxruby/helper_module.rb +72 -0
- data/lib/swxruby/rails_integration/render_decorator.rb +20 -0
- data/lib/swxruby/rails_integration/swx.yml +18 -0
- data/lib/swxruby/rails_integration/swx_controller.rb +6 -0
- data/lib/swxruby/services/arithmetic.rb +9 -0
- data/lib/swxruby/services/discovery_service.rb +3 -0
- data/lib/swxruby/services/hello_world.rb +7 -0
- data/lib/swxruby/services/simple.rb +5 -0
- data/lib/swxruby/services/test_data_types.rb +94 -0
- data/lib/swxruby/swx_assembler.rb +138 -0
- data/lib/swxruby/swx_gateway.rb +104 -0
- data/lib/swxruby/version.rb +9 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/swxruby/bytecode_converter_spec.rb +162 -0
- data/spec/swxruby/core_extensions_spec.rb +16 -0
- data/spec/swxruby/fixtures/number_one_no_debug_compression_4.swx +0 -0
- data/spec/swxruby/fixtures/number_one_no_debug_no_compression.swx +0 -0
- data/spec/swxruby/fixtures/number_one_no_debug_no_compression_arbitrary_allow_domain.swx +0 -0
- data/spec/swxruby/fixtures/number_one_with_debug_compression_4.swx +0 -0
- data/spec/swxruby/fixtures/number_one_with_debug_no_compression.swx +0 -0
- data/spec/swxruby/rails_integration/init_spec.rb +0 -0
- data/spec/swxruby/rails_integration/render_decorator_spec.rb +73 -0
- data/spec/swxruby/rails_integration/swx_controller_spec.rb +5 -0
- data/spec/swxruby/swx_assembler_spec.rb +60 -0
- data/spec/swxruby/swx_gateway_spec.rb +160 -0
- metadata +108 -0
@@ -0,0 +1,160 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'swx_gateway'
|
3
|
+
|
4
|
+
|
5
|
+
module SwxGatewaySpecHelper
|
6
|
+
def configure_swx_gateway
|
7
|
+
SwxGateway.app_root = './'
|
8
|
+
SwxGateway.swx_config = {
|
9
|
+
'services_path' => File.join('./', 'lib', 'swxruby', 'services'),
|
10
|
+
'allow_domain' => true,
|
11
|
+
'compression_level' => 4
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'SwxGateway#init_service_class' do
|
17
|
+
include SwxGatewaySpecHelper
|
18
|
+
|
19
|
+
before do
|
20
|
+
configure_swx_gateway
|
21
|
+
SwxGateway.init_service_classes
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should initialize the classes within the SwxServiceClasses namespace' do
|
25
|
+
lambda { SwxServiceClasses::HelloWorld }.should_not raise_error(NameError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should not initialize the service classes in the top-level namespace' do
|
29
|
+
lambda { HelloWorld }.should raise_error(NameError)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should initialize all of the service classes in the service classes folder' do
|
33
|
+
lambda { SwxServiceClasses::HelloWorld }.should_not raise_error(NameError)
|
34
|
+
lambda { SwxServiceClasses::TestDataTypes }.should_not raise_error(NameError)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'SwxGateway#json_to_ruby' do
|
39
|
+
include SwxGatewaySpecHelper
|
40
|
+
|
41
|
+
before do
|
42
|
+
configure_swx_gateway
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should convert a JSON string to a native Ruby object' do
|
46
|
+
SwxGateway.json_to_ruby(%q([1,2,{"a":3.141},false,true,null,"4..10"])).should == [1, 2, {"a"=>3.141}, false, true, nil, "4..10"]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'SwxGateway#nillify_nulls' do
|
51
|
+
it 'should convert "null" to nil' do
|
52
|
+
SwxGateway.nillify_nulls([1, 'null', 'a string', 'another string', 'null']).should == [1, nil, 'a string', 'another string', nil]
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should return nil if the args array only contains nil values' do
|
56
|
+
SwxGateway.nillify_nulls(['null']).should == nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'SwxGateway#process' do
|
61
|
+
include SwxGatewaySpecHelper
|
62
|
+
|
63
|
+
before do
|
64
|
+
configure_swx_gateway
|
65
|
+
|
66
|
+
mock(SwxServiceClasses)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should process a hash of params with no args param and call SwxAssembler#write_swf with them' do
|
70
|
+
hello_world = mock(SwxServiceClasses::HelloWorld)
|
71
|
+
|
72
|
+
hello_world.should_receive(:send).with('just_say_the_words').and_return('Hello World!')
|
73
|
+
SwxServiceClasses::HelloWorld.should_receive(:new).and_return(hello_world)
|
74
|
+
|
75
|
+
SwxAssembler.should_receive(:write_swf).with('Hello World!', false, 4, nil, true)
|
76
|
+
|
77
|
+
SwxGateway.process(:serviceClass => 'HelloWorld', :method => 'justSayTheWords')
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should process a hash of params with an args param containing only "[null]" and call SwxAssembler#write_swf with them' do
|
81
|
+
hello_world = mock(SwxServiceClasses::HelloWorld)
|
82
|
+
|
83
|
+
hello_world.should_receive(:send).with('just_say_the_words').and_return('Hello World!')
|
84
|
+
SwxServiceClasses::HelloWorld.should_receive(:new).and_return(hello_world)
|
85
|
+
|
86
|
+
SwxAssembler.should_receive(:write_swf).with('Hello World!', false, 4, nil, true)
|
87
|
+
|
88
|
+
SwxGateway.process(:serviceClass => 'HelloWorld', :method => 'justSayTheWords', :args => '[null]')
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
it 'should process a hash of params with an args param containing only "[]" and call SwxAssembler#write_swf with them' do
|
93
|
+
hello_world = mock(SwxServiceClasses::HelloWorld)
|
94
|
+
|
95
|
+
hello_world.should_receive(:send).with('just_say_the_words').and_return('Hello World!')
|
96
|
+
SwxServiceClasses::HelloWorld.should_receive(:new).and_return(hello_world)
|
97
|
+
|
98
|
+
SwxAssembler.should_receive(:write_swf).with('Hello World!', false, 4, nil, true)
|
99
|
+
|
100
|
+
SwxGateway.process(:serviceClass => 'HelloWorld', :method => 'justSayTheWords', :args => '[null]')
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should process a hash of params with an args param and call SwxAssembler#write_swf with them' do
|
104
|
+
arithmetic = mock(SwxServiceClasses::Arithmetic)
|
105
|
+
arithmetic.should_receive(:send).with('addition', 1, 2).and_return(3)
|
106
|
+
SwxServiceClasses::Arithmetic.should_receive(:new).and_return(arithmetic)
|
107
|
+
|
108
|
+
SwxAssembler.should_receive(:write_swf).with(3, false, 4, nil, true)
|
109
|
+
|
110
|
+
SwxGateway.process(:serviceClass => 'Arithmetic', :method => 'addition', :args => '[1, 2]')
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should convert a "true" string in the debug param to a boolean' do
|
114
|
+
SwxAssembler.should_receive(:write_swf).with(3, true, 4, nil, true)
|
115
|
+
SwxGateway.process(:serviceClass => 'Arithmetic', :method => 'addition', :args => '[1, 2]', :debug => 'true')
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should convert a "false" string in the debug param to a boolean' do
|
119
|
+
SwxAssembler.should_receive(:write_swf).with(3, false, 4, nil, true)
|
120
|
+
SwxGateway.process(:serviceClass => 'Arithmetic', :method => 'addition', :args => '[1, 2]', :debug => 'false')
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should default debugging to false if no debug param is supplied' do
|
124
|
+
SwxAssembler.should_receive(:write_swf).with(3, false, 4, nil, true)
|
125
|
+
SwxGateway.process(:serviceClass => 'Arithmetic', :method => 'addition', :args => '[1, 2]')
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'should raise a NoMethodError when attempting to call methods that the service class inherited from Object' do
|
129
|
+
lambda { SwxGateway.process(:serviceClass => 'TestDataTypes', :method => 'instance_eval', :args => '["@foo"]') }.should raise_error(NoMethodError)
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should raise an ArgumentError if any of the arguments in params[:args] equal "undefined"' do
|
133
|
+
lambda { SwxGateway.process(:serviceClass => 'MyNiftyClass', :method => 'method_requiring_args', :args => '["undefined"]') }.should raise_error(ArgumentError)
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should convert "null" strings in the args param to nil before calling SwxAssembler#write_swf' do
|
137
|
+
arithmetic = mock(SwxServiceClasses::Arithmetic)
|
138
|
+
arithmetic.should_receive(:send).with('addition', 1, nil).and_return(3)
|
139
|
+
SwxServiceClasses::Arithmetic.should_receive(:new).and_return(arithmetic)
|
140
|
+
|
141
|
+
SwxAssembler.should_receive(:write_swf).with(3, false, 4, nil, true)
|
142
|
+
|
143
|
+
SwxGateway.process(:serviceClass => 'Arithmetic', :method => 'addition', :args => '[1, "null"]')
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'should raise a NameError when passed an invalid constant name as a service class' do
|
148
|
+
lambda { SwxGateway.process(:serviceClass => 'arithmetic', :method => 'addition', :args => '[1, 2]') }.should raise_error(NameError)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe 'SwxGateway#validate_service_class_name' do
|
153
|
+
it 'should raise a NameError when passed an invalid constant name' do
|
154
|
+
lambda { SwxGateway.validate_service_class_name('invalid name') }.should raise_error(NameError)
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should not raise an error when passed a valid constant name' do
|
158
|
+
lambda { SwxGateway.validate_service_class_name('ValidConstantName') }.should_not raise_error
|
159
|
+
end
|
160
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: swxruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.7"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jed Hurt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-03-12 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json_pure
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
version:
|
24
|
+
description: "SWX Ruby: The Ruby Implementation of SWX RPC"
|
25
|
+
email: jed.hurt@gmail.com
|
26
|
+
executables:
|
27
|
+
- swxruby
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README
|
32
|
+
- LICENSE
|
33
|
+
- CHANGELOG
|
34
|
+
files:
|
35
|
+
- LICENSE
|
36
|
+
- README
|
37
|
+
- Rakefile
|
38
|
+
- CHANGELOG
|
39
|
+
- init.rb
|
40
|
+
- install.rb
|
41
|
+
- bin/swxruby
|
42
|
+
- spec/spec.opts
|
43
|
+
- spec/spec_helper.rb
|
44
|
+
- spec/swxruby
|
45
|
+
- spec/swxruby/bytecode_converter_spec.rb
|
46
|
+
- spec/swxruby/core_extensions_spec.rb
|
47
|
+
- spec/swxruby/fixtures
|
48
|
+
- spec/swxruby/fixtures/number_one_no_debug_compression_4.swx
|
49
|
+
- spec/swxruby/fixtures/number_one_no_debug_no_compression.swx
|
50
|
+
- spec/swxruby/fixtures/number_one_no_debug_no_compression_arbitrary_allow_domain.swx
|
51
|
+
- spec/swxruby/fixtures/number_one_with_debug_compression_4.swx
|
52
|
+
- spec/swxruby/fixtures/number_one_with_debug_no_compression.swx
|
53
|
+
- spec/swxruby/rails_integration
|
54
|
+
- spec/swxruby/rails_integration/init_spec.rb
|
55
|
+
- spec/swxruby/rails_integration/render_decorator_spec.rb
|
56
|
+
- spec/swxruby/rails_integration/swx_controller_spec.rb
|
57
|
+
- spec/swxruby/swx_assembler_spec.rb
|
58
|
+
- spec/swxruby/swx_gateway_spec.rb
|
59
|
+
- lib/swxruby
|
60
|
+
- lib/swxruby/bytecode_converter.rb
|
61
|
+
- lib/swxruby/core_extensions.rb
|
62
|
+
- lib/swxruby/helper_module.rb
|
63
|
+
- lib/swxruby/rails_integration
|
64
|
+
- lib/swxruby/rails_integration/render_decorator.rb
|
65
|
+
- lib/swxruby/rails_integration/swx.yml
|
66
|
+
- lib/swxruby/rails_integration/swx_controller.rb
|
67
|
+
- lib/swxruby/services
|
68
|
+
- lib/swxruby/services/arithmetic.rb
|
69
|
+
- lib/swxruby/services/discovery_service.rb
|
70
|
+
- lib/swxruby/services/hello_world.rb
|
71
|
+
- lib/swxruby/services/simple.rb
|
72
|
+
- lib/swxruby/services/test_data_types.rb
|
73
|
+
- lib/swxruby/swx_assembler.rb
|
74
|
+
- lib/swxruby/swx_gateway.rb
|
75
|
+
- lib/swxruby/version.rb
|
76
|
+
- lib/swxruby.rb
|
77
|
+
- examples/standalone
|
78
|
+
- examples/standalone/standalone.fla
|
79
|
+
- examples/standalone/standalone.rb
|
80
|
+
- examples/standalone/standalone.swf
|
81
|
+
has_rdoc: true
|
82
|
+
homepage: http://swxruby.org
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 1.8.4
|
93
|
+
version:
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: "0"
|
99
|
+
version:
|
100
|
+
requirements:
|
101
|
+
- install the json gem to get faster json parsing
|
102
|
+
rubyforge_project: swxruby
|
103
|
+
rubygems_version: 1.0.1
|
104
|
+
signing_key:
|
105
|
+
specification_version: 2
|
106
|
+
summary: "SWX Ruby: The Ruby Implementation of SWX RPC"
|
107
|
+
test_files: []
|
108
|
+
|