populus 0.0.1.pre → 0.0.1.pre3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/bin/populus +17 -0
- data/examples/echo.popl +7 -0
- data/lib/populus/do.rb +25 -0
- data/lib/populus/dsl.rb +26 -0
- data/lib/populus/version.rb +1 -1
- data/lib/populus/watch/node.rb +23 -0
- data/lib/populus.rb +4 -4
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0b59e4ac86d6d258766507d44cc26045420690e
|
4
|
+
data.tar.gz: 146bdb3308470befc1145bb9a67d26778568bb17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ff3f1f915b797f0bb519bf12ed99d44cf52db9d228dfe97dd8b57445f1fdeed22e9f26c7fc24ac923173a394c867e59a65aa744cd55bcfb8362df80e720b8d3
|
7
|
+
data.tar.gz: 9abc728c5c1b032cc8a9cc43c478afde83cf16b13c93a3dca74c7a431cc26d81befcded09ee1b1eb1af9a01b90ebea81b06b932c862be363b0b88e39a26a70f0
|
data/bin/populus
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- mode: ruby -*-
|
3
|
+
|
4
|
+
require 'populus'
|
5
|
+
|
6
|
+
mode = ARGV[0] # This is for forward compatibility
|
7
|
+
if mode != 'accept'
|
8
|
+
puts "Unknown arg: #{mode}"
|
9
|
+
exit 127
|
10
|
+
end
|
11
|
+
|
12
|
+
setting = ARGV[1]
|
13
|
+
|
14
|
+
Populus.eval_setting setting
|
15
|
+
|
16
|
+
data = STDIN.read
|
17
|
+
Populus::Do.accept data
|
data/examples/echo.popl
ADDED
data/lib/populus/do.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Populus
|
5
|
+
class Do
|
6
|
+
include Singleton
|
7
|
+
def objects
|
8
|
+
@objects ||= []
|
9
|
+
end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def register_object(o)
|
13
|
+
instance.objects << o
|
14
|
+
puts "Registered: #{o.inspect}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def accept(input)
|
18
|
+
json = JSON.parse(input)
|
19
|
+
instance.objects.each do |o|
|
20
|
+
o.accept json
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/populus/dsl.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'populus/do'
|
2
|
+
require 'populus/watch/node'
|
3
|
+
|
4
|
+
module Populus
|
5
|
+
module DSL
|
6
|
+
def watch(arg, &b)
|
7
|
+
watching = find_watch_obj(arg)
|
8
|
+
watching.instance_eval(&b)
|
9
|
+
Do.register_object watching
|
10
|
+
end
|
11
|
+
|
12
|
+
def find_watch_obj(arg)
|
13
|
+
const = arg.gsub(/(^.|_.)/) {|c| c.tr('_', '').upcase }
|
14
|
+
Watch.const_get(const).new
|
15
|
+
end
|
16
|
+
|
17
|
+
def eval_setting(path)
|
18
|
+
load path
|
19
|
+
rescue => e
|
20
|
+
STDERR.puts "Invalid setting format! #{path}", "error is:", e
|
21
|
+
exit 1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
extend DSL
|
26
|
+
end
|
data/lib/populus/version.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Populus
|
2
|
+
module Watch
|
3
|
+
class Node
|
4
|
+
def initialize
|
5
|
+
@on_receive_hooks = []
|
6
|
+
end
|
7
|
+
|
8
|
+
def on_receive(&b)
|
9
|
+
@on_receive_hooks << b
|
10
|
+
end
|
11
|
+
|
12
|
+
def accept(json)
|
13
|
+
@on_receive_hooks.each do |hook|
|
14
|
+
begin
|
15
|
+
hook.call(json)
|
16
|
+
rescue => e
|
17
|
+
puts e, "Ignore."
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/populus.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
1
|
+
module Populus; end
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require "populus/do"
|
4
|
+
require "populus/dsl"
|
5
|
+
require "populus/version"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: populus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.pre3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uchio, KONDO
|
@@ -55,7 +55,8 @@ dependencies:
|
|
55
55
|
description: Consul event definition DSL
|
56
56
|
email:
|
57
57
|
- udzura@udzura.jp
|
58
|
-
executables:
|
58
|
+
executables:
|
59
|
+
- populus
|
59
60
|
extensions: []
|
60
61
|
extra_rdoc_files: []
|
61
62
|
files:
|
@@ -65,8 +66,13 @@ files:
|
|
65
66
|
- LICENSE.txt
|
66
67
|
- README.md
|
67
68
|
- Rakefile
|
69
|
+
- bin/populus
|
70
|
+
- examples/echo.popl
|
68
71
|
- lib/populus.rb
|
72
|
+
- lib/populus/do.rb
|
73
|
+
- lib/populus/dsl.rb
|
69
74
|
- lib/populus/version.rb
|
75
|
+
- lib/populus/watch/node.rb
|
70
76
|
- populus.gemspec
|
71
77
|
homepage: https://github.com/udzura/populus
|
72
78
|
licenses:
|