babascript 0.2.6 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8273f8ae9cc284e08bbd9150f757d26ed6384619
4
- data.tar.gz: ac3b267018cf20434db213f0dbcd02a6f8e3e4ce
3
+ metadata.gz: a293bf20186ddf403fc4022f152840758f7f5b81
4
+ data.tar.gz: d5bbc70c8519861c00a77a7e723a8cae27ba8a1e
5
5
  SHA512:
6
- metadata.gz: 6145693ba511ba2f1f8f6d92ff1c78b8a51c242a982fccf1c03e0d038e95644eb79a4fd71cdac00bad2b5bb9b49d761e6d7a419ca7e64a0f2137f14e3f13cfbc
7
- data.tar.gz: 7de8891b5566e5809a8276d726f7a675d61fbcd38c74b0ea082c8022c3fbaecdcaff0a1bdeb7aecc0231c5e5c84854471525c78de7e8ac89bba013f0f6069ce1
6
+ metadata.gz: 63efbea184e3b2cf66ac5dbb0a068cc6db2099a260092bc4edd87f94d40bde0a5ec70e25d5b0612a52c8a8565e16fa0f4d8ac0eb2a1d64decc1ed8a8f235a3ca
7
+ data.tar.gz: a8b7f2692fbda07a7865b5e7fba70e180436b4cdc1dda2e76b6bb004e8afb567dfaaffb037529eac4e0159f3c85bfd6dab36cc83d7ef4a251da4e97fa45be533
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.3.0 2013-09-22
2
+
3
+ * select TupleSpace in "BabaScript.baba do"
4
+
1
5
  === 0.2.6 2013-08-13
2
6
 
3
7
  * bugfix callback if block given in babascript-code
data/README.md CHANGED
@@ -52,20 +52,49 @@ end
52
52
 
53
53
  ### switch BABA
54
54
  BabaScriptはジョブ通知に[Linda](https://gihtub.com/shokai/linda-base)を使っています。
55
- 環境変数BABAのデフォルト値は"takumibaba"で、彼のジョブは http://linda.masuilab.org/takumibaba/notifications で確認できます。
56
55
 
57
- % export BABA=shokai
56
+ クエリーを書き込むタプルスペースのデフォルト値は"takumibaba"で、彼のジョブは http://linda.masuilab.org/takumibaba/notifications で確認できます。
58
57
 
59
- 環境変数BABAを"shokai"に切り替えると、以後のジョブの通知先が http://linda.masuilab.org/shokai/notifications になります。
58
+ % baba --base http://example.com --space shokai
59
+
60
+ タプルスペース名を"shokai"に、Lindaサーバーをexample.comに切り替えると、以後のジョブの通知先が http://example.com/shokai/notifications になります。
61
+
62
+
63
+ ruby上での書き込み先の変更方法
64
+ ```ruby
65
+ BabaScript.baba :base => "http://example.com", :space => "shokai" do
66
+ puts そろそろ起きたほうがいいのでは?
67
+ end
68
+
69
+ ```
60
70
 
61
71
 
62
72
  Test
63
73
  ----
64
74
 
75
+ ### Install Dependencies
76
+
65
77
  % gem install bundler
66
78
  % bundle install
79
+
80
+ ### Manual Test
81
+
82
+ Start VM
83
+
84
+ % bundle exec bin/baba-vm --space test
85
+
86
+ Run samples
87
+
88
+ % bundle exec ruby samples/sample.rb
89
+
90
+ ### Unit Test
91
+
67
92
  % bundle exec rake test
68
93
 
94
+ or
95
+
96
+ % LINDA_BASE=http://localhost:5000 LINDA_SPACE=test bundle exec rake test
97
+
69
98
 
70
99
  Contributing
71
100
  ------------
data/bin/baba CHANGED
@@ -6,9 +6,15 @@ $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
6
6
  require 'babascript'
7
7
 
8
8
  args = ArgsParser.parse ARGV do
9
- arg :e, "one line of script"
9
+ arg :eval, "evaluate one line script", :alias => :e
10
+ arg :base, "Linda-Base URL", :default => BabaScript::DEFAULTS[:base]
11
+ arg :space, "Linda-Space Name", :default => BabaScript::DEFAULTS[:space]
10
12
  arg :version, "show version", :alias => :v
11
13
  arg :help, "show help", :alias => :h
14
+
15
+ validate :base, "invalid URL" do |v|
16
+ v =~ /^https?:\/\/.+$/
17
+ end
12
18
  end
13
19
 
14
20
  binname = File.basename(__FILE__)
@@ -18,6 +24,7 @@ if args.has_option? :help
18
24
  STDERR.puts "e.g:"
19
25
  STDERR.puts " % #{binname} filename.bb"
20
26
  STDERR.puts " % #{binname} -e 'アイス買ってきてよ'"
27
+ STDERR.puts " % #{binname} filename.bb -base http://linda-base.example.com -space test"
21
28
  exit 1
22
29
  end
23
30
 
@@ -26,15 +33,16 @@ if args.has_option? :version
26
33
  exit 1
27
34
  end
28
35
 
29
- if args.has_param? :e
30
- puts args[:e]
31
- BabaScript.baba do
32
- puts instance_eval args[:e]
36
+ if args.has_param? :eval
37
+ puts args[:eval]
38
+ BabaScript.baba :base => args[:base], :space => args[:space] do
39
+ puts instance_eval args[:eval]
33
40
  end
34
41
  else
35
42
  args.argv.each do |fname|
36
43
  File.open(fname) do |f|
37
- BabaScript::Baba.run f.read
44
+ baba = BabaScript::Baba.new(:base => args[:base], :space => args[:space])
45
+ baba.run f.read
38
46
  end
39
47
  end
40
- end
48
+ end
data/bin/baba-vm CHANGED
@@ -6,8 +6,14 @@ $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
6
6
  require 'babascript'
7
7
 
8
8
  args = ArgsParser.parse ARGV do
9
+ arg :base, "Linda-Base URL", :default => BabaScript::DEFAULTS[:base]
10
+ arg :space, "Linda-Space Name", :default => BabaScript::DEFAULTS[:space]
9
11
  arg :version, "show version", :alias => :v
10
12
  arg :help, "show help", :alias => :h
13
+
14
+ validate :base, "invalid URL" do |v|
15
+ v =~ /^https?:\/\/.+$/
16
+ end
11
17
  end
12
18
 
13
19
  binname = File.basename(__FILE__)
@@ -22,11 +28,11 @@ if args.has_option? :version
22
28
  exit 1
23
29
  end
24
30
 
25
- STDERR.puts "(connecting..)"
31
+ STDERR.puts "(connecting to #{args[:base]}/#{args[:space]})"
26
32
 
27
33
  EM::run do
28
- linda = EM::RocketIO::Linda::Client.new BabaScript.LINDA_BASE
29
- ts = linda.tuplespace[ BabaScript.LINDA_SPACE ]
34
+ linda = EM::RocketIO::Linda::Client.new args[:base]
35
+ ts = linda.tuplespace[ args[:space] ]
30
36
 
31
37
  def take_task_and_run(ts)
32
38
  ts.take [:babascript, :eval] do |tuple|
data/bin/ibb CHANGED
@@ -6,10 +6,15 @@ require 'babascript'
6
6
  load "#{ENV['HOME']}/.ibbrc" if File.exists? "#{ENV['HOME']}/.ibbrc"
7
7
 
8
8
  args = ArgsParser.parse ARGV do
9
+ arg :base, "Linda-Base URL", :default => BabaScript::DEFAULTS[:base]
10
+ arg :space, "Linda-Space Name", :default => BabaScript::DEFAULTS[:space]
9
11
  arg :version, "show version", :alias => :v
10
12
  arg :help, "show help", :alias => :h
11
- end
12
13
 
14
+ validate :base, "invalid URL" do |v|
15
+ v =~ /^https?:\/\/.+$/
16
+ end
17
+ end
13
18
 
14
19
  binname = File.basename(__FILE__)
15
20
  if args.has_option? :help
@@ -23,19 +28,21 @@ if args.has_option? :version
23
28
  exit 1
24
29
  end
25
30
 
26
- STDERR.puts "(connecting..)"
31
+ STDERR.puts "(connecting to #{args[:base]}/#{args[:space]})"
27
32
 
28
33
  EM::run do
29
- BabaScript::Baba.linda.io.on :connect do
34
+ baba = BabaScript::Baba.new :base => args[:base], :space => args[:space]
35
+
36
+ baba.linda.io.on :connect do
30
37
  STDERR.puts "(#{type} connect!)"
31
38
  end
32
39
 
33
- BabaScript::Baba.linda.io.on :disconnect do
40
+ baba.linda.io.on :disconnect do
34
41
  STDERR.puts
35
42
  STDERR.puts "(#{type} closed)"
36
43
  end
37
44
 
38
- BabaScript.baba do
45
+ baba.run do
39
46
  print "[IBB] > "
40
47
  while line = STDIN.gets do
41
48
  line.strip!
@@ -1,24 +1,30 @@
1
1
  module BabaScript
2
- def self.baba(&block)
3
- self::Baba.run &block if block_given?
2
+ def self.baba(opts={}, &block)
3
+ self::Baba.new(opts).run &block if block_given?
4
4
  end
5
5
 
6
6
  class Baba
7
7
 
8
- def self.linda
9
- @@linda ||= EM::RocketIO::Linda::Client.new BabaScript.LINDA_BASE
8
+ def initialize(opts)
9
+ @base = opts[:base] || "http://linda.masuilab.org"
10
+ @space = opts[:space] || "takumibaba"
10
11
  end
11
12
 
12
- def self.run(code=nil, &block)
13
+ def linda
14
+ @linda ||= EM::RocketIO::Linda::Client.new @base
15
+ end
16
+
17
+ def run(code=nil, &block)
13
18
  raise ArgumentError "block or code require" unless block_given? or code.kind_of? String
14
19
  already_eventmachine_running = EM::reactor_running?
20
+ this = self
15
21
  EM::run do
16
22
  linda.io.once :connect do
17
23
  EM::defer do
18
24
  if block_given?
19
- ::BabaScript::Baba.instance_eval &block
25
+ this.instance_eval &block
20
26
  else
21
- ::BabaScript::Baba.instance_eval code
27
+ this.instance_eval code
22
28
  end
23
29
  unless already_eventmachine_running
24
30
  EM::add_timer 1 do
@@ -30,10 +36,10 @@ module BabaScript
30
36
  end
31
37
  end
32
38
 
33
- def self.method_missing(name, *args, &block)
39
+ def method_missing(name, *args, &block)
34
40
  cid = __create_callback_id
35
41
  tuple = [:babascript, :eval, name, args, {:callback => cid}]
36
- ts = linda.tuplespace[BabaScript.LINDA_SPACE]
42
+ ts = linda.tuplespace[@space]
37
43
  ts.write tuple
38
44
  if block_given?
39
45
  ts.take [:babascript, :return, cid] do |result|
@@ -47,7 +53,7 @@ module BabaScript
47
53
  end
48
54
 
49
55
  private
50
- def self.__create_callback_id
56
+ def __create_callback_id
51
57
  Digest::MD5.hexdigest "#{Time.now.to_i}_#{Time.now.usec}_#{rand 100000}"
52
58
  end
53
59
  end
@@ -1,9 +1,6 @@
1
1
  module BabaScript
2
- def self.LINDA_BASE
3
- ENV["LINDA_BASE"] || "http://linda.masuilab.org"
4
- end
5
-
6
- def self.LINDA_SPACE
7
- ENV["BABA"] || "takumibaba"
8
- end
2
+ DEFAULTS = {
3
+ :base => "http://linda.masuilab.org",
4
+ :space => "takumibaba"
5
+ }
9
6
  end
@@ -1,3 +1,3 @@
1
1
  module BabaScript
2
- VERSION = "0.2.6"
2
+ VERSION = "0.3.0"
3
3
  end
data/samples/sample.rb CHANGED
@@ -4,7 +4,7 @@ require 'rubygems'
4
4
  $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
5
5
  require 'babascript'
6
6
 
7
- BabaScript.baba do
7
+ BabaScript.baba :base => "http://localhost:5000", :space => "test" do
8
8
  if Time.now.hour < 12
9
9
  puts そろそろ起きたほうがいいのでは?
10
10
  else
@@ -3,14 +3,14 @@ require File.expand_path 'test_helper', File.dirname(__FILE__)
3
3
 
4
4
  class TestBabaScript < MiniTest::Test
5
5
 
6
- ENV["BABA"] = "test"
7
-
8
6
  def test_eval_write_tuple
7
+ base = ENV["LINDA_BASE"] || BabaScript::DEFAULTS[:base]
8
+ space = ENV["LINDA_SPACE"] || BabaScript::DEFAULTS[:space]
9
9
  tuple_ = nil
10
10
  res_ = nil
11
11
  EM::run do
12
- linda = EM::RocketIO::Linda::Client.new BabaScript.LINDA_BASE
13
- ts = linda.tuplespace[ BabaScript.LINDA_SPACE ]
12
+ linda = EM::RocketIO::Linda::Client.new base
13
+ ts = linda.tuplespace[ space ]
14
14
  linda.io.once :connect do
15
15
  ts.take [:babascript, :eval] do |tuple|
16
16
  tuple_ = tuple
@@ -21,7 +21,7 @@ class TestBabaScript < MiniTest::Test
21
21
  end
22
22
  end
23
23
 
24
- BabaScript.baba do
24
+ BabaScript.baba :base => base, :space => space do
25
25
  res_ = テスト 1, 2, "かずすけ"
26
26
  end
27
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: babascript
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sho Hashimoto
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-12 00:00:00.000000000 Z
12
+ date: 2013-09-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: em-rocketio-linda-client