petite-lettre 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.textile +52 -0
- data/VERSION.yml +4 -0
- data/lib/petite_lettre.rb +24 -0
- data/spec/petite_lettre_spec.rb +18 -0
- data/spec/sample_client.rb +5 -0
- data/spec/spec_helper.rb +9 -0
- metadata +61 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Thibaut Barrère
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
Petite-lettre is a little gem allowing YAML communication between a process and the child it launches.
|
2
|
+
|
3
|
+
h1. USAGE
|
4
|
+
|
5
|
+
The parent process launches its child and passes it a message using this kind of code:
|
6
|
+
|
7
|
+
PetiteLettre.call("ruby child_program.rb", { :command => :start_sale, :isbn => "1234567", :price => 12.4 })
|
8
|
+
|
9
|
+
The child process read the parent message using this kind of code:
|
10
|
+
|
11
|
+
PetiteLettre.receive do |message|
|
12
|
+
response = {}
|
13
|
+
if message[:command] == :start_sale
|
14
|
+
# do something here
|
15
|
+
raise "Price is too low" if message[:price] < 15.0
|
16
|
+
response[:status] = "OK"
|
17
|
+
response[:transaction_id] = "1235"
|
18
|
+
else
|
19
|
+
raise "Unknown command '#{message[:command]}'"
|
20
|
+
end
|
21
|
+
response
|
22
|
+
end
|
23
|
+
|
24
|
+
Petite-lettre uses $stdin and $stdout by default, although these can be customized with PetiteLettre.receive(input,output).
|
25
|
+
|
26
|
+
h1. MORE USAGE
|
27
|
+
|
28
|
+
Nothing stops you from writing a child process in another language (ie: C#, Java), as long as it knows how to read YAML from $stdin and output YAML on $stdout. Just the same - you can write a parent process in another language.
|
29
|
+
|
30
|
+
See petite_lettre.rb for implementation details.
|
31
|
+
|
32
|
+
h1. HISTORY
|
33
|
+
|
34
|
+
Petite-lettre is born out of the need to communicate between a MRI/Shoes front-end and a JRuby/Celerity back-end.
|
35
|
+
|
36
|
+
I'm pretty sure there is something already available out there to do that kind of things already. I just could not find them in a reasonable amount of time.
|
37
|
+
|
38
|
+
If it's the case, please mail me so I can bury petite-lettre for ever.
|
39
|
+
|
40
|
+
h1. CREDITS
|
41
|
+
|
42
|
+
I think I got that idea after using CouchDB for a while. I believe CouchDB uses JSON to communicate between its processes.
|
43
|
+
|
44
|
+
h1. IDEAS
|
45
|
+
|
46
|
+
* create a C# or Java client
|
47
|
+
* allow continuous communication (à la server)
|
48
|
+
* throw petite-lettre to the bin if I discover something that does the same thing at the same level of simplicity
|
49
|
+
|
50
|
+
h1. COPYRIGHT
|
51
|
+
|
52
|
+
Copyright (c) 2008 Thibaut Barrère. See LICENSE for details.
|
data/VERSION.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module PetiteLettre
|
4
|
+
def self.call(command,message)
|
5
|
+
IO.popen(command,mode='r+') do |io|
|
6
|
+
io.write(YAML::dump(message))
|
7
|
+
io.close_write
|
8
|
+
result = YAML::load(io.read)
|
9
|
+
raise result[:error][:message] if result.is_a?(Hash) && result[:error]
|
10
|
+
result
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.receive(input=$stdin,output=$stdout)
|
15
|
+
message = YAML::load(input.read)
|
16
|
+
result = nil
|
17
|
+
begin
|
18
|
+
result = yield message
|
19
|
+
rescue => e
|
20
|
+
result = { :error => { :message => e.message } }
|
21
|
+
end
|
22
|
+
output.write(YAML::dump(result))
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
CLIENT = File.dirname(__FILE__) + "/sample_client.rb"
|
4
|
+
|
5
|
+
describe PetiteLettre do
|
6
|
+
def response_for(hash)
|
7
|
+
PetiteLettre.call("ruby #{CLIENT}",hash)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "allows to send a simple message and get an answer" do
|
11
|
+
response_for({ :a => 5, :b => 2.0 }).should == 5/2.0
|
12
|
+
end
|
13
|
+
|
14
|
+
it "understands errors" do
|
15
|
+
lambda { response_for({ :a => 5, :b => 0}) }.should raise_error("divided by 0")
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: petite-lettre
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Thibaut Barr\xC3\xA8re"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-29 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: TODO
|
17
|
+
email: thibaut.barrere@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.textile
|
24
|
+
- LICENSE
|
25
|
+
files:
|
26
|
+
- README.textile
|
27
|
+
- VERSION.yml
|
28
|
+
- lib/petite_lettre.rb
|
29
|
+
- spec/petite_lettre_spec.rb
|
30
|
+
- spec/sample_client.rb
|
31
|
+
- spec/spec_helper.rb
|
32
|
+
- LICENSE
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/thbar/petite-lettre
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options:
|
37
|
+
- --inline-source
|
38
|
+
- --charset=UTF-8
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
requirements: []
|
54
|
+
|
55
|
+
rubyforge_project: petite-lettre
|
56
|
+
rubygems_version: 1.3.1
|
57
|
+
signing_key:
|
58
|
+
specification_version: 2
|
59
|
+
summary: YAML-based inter-process communication
|
60
|
+
test_files: []
|
61
|
+
|