melomel 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +3 -0
- data/README.md +2 -97
- data/lib/melomel/object_proxy.rb +0 -3
- data/lib/melomel/version.rb +1 -1
- data/test/test_integration.rb +6 -0
- data/test/test_object_proxy.rb +0 -5
- metadata +4 -4
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -5,9 +5,9 @@ melomel.rb -- A Ruby interface to Melomel
|
|
5
5
|
|
6
6
|
Melomel.rb is a library that allows Ruby to communicate with an application
|
7
7
|
running within the Flash virtual machine. For more information on Melomel,
|
8
|
-
visit the Melomel
|
8
|
+
visit the Melomel site:
|
9
9
|
|
10
|
-
http://
|
10
|
+
http://melomel.info
|
11
11
|
|
12
12
|
Melomel.rb follows the rules of [Semantic Versioning](http://semver.org/) and
|
13
13
|
uses [TomDoc](http://tomdoc.org/) for inline documentation.
|
@@ -23,101 +23,6 @@ Melomel needs to be embedded and running in the application you're trying to
|
|
23
23
|
connect to. Please see the Melomel repository for instructions on installation.
|
24
24
|
|
25
25
|
|
26
|
-
## GETTING STARTED
|
27
|
-
|
28
|
-
The first step to using Melomel is to install the Flash SWC in your application.
|
29
|
-
Once the SWC is in your application, setup in your Ruby project is simple.
|
30
|
-
|
31
|
-
In your Ruby file, simply call the `connect()` method on `Melomel`:
|
32
|
-
|
33
|
-
require 'melomel'
|
34
|
-
Melomel.connect()
|
35
|
-
|
36
|
-
The `connect()` method is a blocking method so it won't proceed until it's done.
|
37
|
-
After it's connected, there are several actions you can perform:
|
38
|
-
|
39
|
-
1. Create Object
|
40
|
-
1. Get Class
|
41
|
-
1. Get Property
|
42
|
-
1. Set Property
|
43
|
-
1. Invoke Method
|
44
|
-
1. Invoke Function
|
45
|
-
|
46
|
-
|
47
|
-
## API
|
48
|
-
|
49
|
-
### Overview
|
50
|
-
|
51
|
-
Melomel communicates to the Flash virtual machine over a socket connection
|
52
|
-
using XML. The protocol is simple and is meant to proxy all data access calls
|
53
|
-
to the Flash virtual machine. This means that only primitives (strings, numbers
|
54
|
-
and booleans) are copied but all objects are accessed by reference. By proxying
|
55
|
-
objects, all data stays in the Flash virtual machine and there are no syncing
|
56
|
-
issues.
|
57
|
-
|
58
|
-
### Create Object
|
59
|
-
|
60
|
-
To create an object, use the `create_object()` method on `Melomel`:
|
61
|
-
|
62
|
-
point = Melomel.create_object('flash.geom.Point')
|
63
|
-
|
64
|
-
The object returned is a proxy object so any actions performed on it in Ruby
|
65
|
-
will be performed on the ActionScript object in the Flash virtual machine.
|
66
|
-
|
67
|
-
### Get Class
|
68
|
-
|
69
|
-
You can retrieve a class to call static methods and properties. Since classes
|
70
|
-
are objects in ActionScript, they work identically in Melomel.
|
71
|
-
|
72
|
-
app = Melomel.get_class('mx.core.FlexGlobals')
|
73
|
-
app.topLevelApplication.name = 'Melomel App!'
|
74
|
-
|
75
|
-
This Flex 4 example updates the name of the application to "Melomel App!".
|
76
|
-
|
77
|
-
### Get Property & Set Property
|
78
|
-
|
79
|
-
Getting and setting properties is handled transparently when using the object
|
80
|
-
proxies.
|
81
|
-
|
82
|
-
point = Melomel.create_object('flash.geom.Point')
|
83
|
-
point.x = 30
|
84
|
-
point.set_property('y') = 40
|
85
|
-
p "pos: #{point.x}, #{point.y}"
|
86
|
-
p "length: #{point.get_property('length')}"
|
87
|
-
|
88
|
-
Property accessors on an object proxy are automatically used to retrieve the
|
89
|
-
property value of the Flash object. You can also use the `get_property()`
|
90
|
-
method when accessing properties and the `set_property()` method when mutating
|
91
|
-
properties.
|
92
|
-
|
93
|
-
### Invoke Method
|
94
|
-
|
95
|
-
Invoking methods is also handled transparently when using object proxies.
|
96
|
-
|
97
|
-
_IMPORTANT: There a catch! Methods without any parameters must have a bang
|
98
|
-
(`!`) character appended to their method name when calling directly on an
|
99
|
-
object proxy._
|
100
|
-
|
101
|
-
clipboard = Melomel.get_class('flash.desktop.Clipboard').generalClipboard
|
102
|
-
data = clipboard.getData('air:text')
|
103
|
-
data = clipboard.invoke_method('getData', 'air:text')
|
104
|
-
clipboard.clear!()
|
105
|
-
clipboard.invoke_method('clear')
|
106
|
-
|
107
|
-
In this example, the `getData` method could be called on the object directly
|
108
|
-
because it had more than one argument. The `clear` method, however, required
|
109
|
-
that a bang character be appended to the name or that the `invoke_method` be
|
110
|
-
used.
|
111
|
-
|
112
|
-
### Invoke Function
|
113
|
-
|
114
|
-
Invoking package level functions is also handled transparently.
|
115
|
-
|
116
|
-
className = Melomel.invoke_function('flash.utils.getQualifiedClassName', "Some string.")
|
117
|
-
|
118
|
-
The className will contain "String".
|
119
|
-
|
120
|
-
|
121
26
|
## HACKING
|
122
27
|
|
123
28
|
To get started with working with the source, start by running Bundler to get all
|
data/lib/melomel/object_proxy.rb
CHANGED
@@ -46,9 +46,6 @@ module Melomel
|
|
46
46
|
# Methods with arguments are methods
|
47
47
|
elsif args.length > 0
|
48
48
|
return invoke_method(method_name, *args)
|
49
|
-
# Methods ending in '!' are methods
|
50
|
-
elsif last_char == '!'
|
51
|
-
return invoke_method(method_name.chop, *args)
|
52
49
|
# Methods with no arguments are aliased to get_property
|
53
50
|
else
|
54
51
|
return get_property(method_name)
|
data/lib/melomel/version.rb
CHANGED
data/test/test_integration.rb
CHANGED
@@ -20,6 +20,12 @@ class IntegrationTestCase < RunnerTestCase
|
|
20
20
|
assert_equal 'bar', runner.foo
|
21
21
|
end
|
22
22
|
|
23
|
+
# Tests the ability for a get_property to call a no-arg method if unavailable.
|
24
|
+
def test_should_get_property_passthrough
|
25
|
+
app = Melomel.get_class('mx.core.FlexGlobals').topLevelApplication
|
26
|
+
assert_equal 'ok', app.test()
|
27
|
+
end
|
28
|
+
|
23
29
|
def test_should_set_property
|
24
30
|
runner = Melomel.get_class('MelomelRunner')
|
25
31
|
runner.name = 'Susy'
|
data/test/test_object_proxy.rb
CHANGED
@@ -40,9 +40,4 @@ class ObjectProxyTestCase < MiniTest::Unit::TestCase
|
|
40
40
|
@proxy.expects(:invoke_method).with('foo', 'bar', 'baz')
|
41
41
|
@proxy.foo('bar', 'baz')
|
42
42
|
end
|
43
|
-
|
44
|
-
def test_should_alias_methods_ending_in_bang_to_invoke_method
|
45
|
-
@proxy.expects(:invoke_method).with('foo')
|
46
|
-
@proxy.foo!()
|
47
|
-
end
|
48
43
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: melomel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ben Johnson
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-27 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|