populus 0.0.1.pre → 0.0.1.pre3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: edc20e9a4061255902b97873edee88653f00276c
4
- data.tar.gz: a3563011eab5ab5bebe4fdf3e06c40fa8cef3dbe
3
+ metadata.gz: b0b59e4ac86d6d258766507d44cc26045420690e
4
+ data.tar.gz: 146bdb3308470befc1145bb9a67d26778568bb17
5
5
  SHA512:
6
- metadata.gz: 8a63b91fb3ac998963fe28bb2af903b30cd0e0f282453491c6b6dbc098b48b31c957e2b3583e67ede1012be68bffd18919be03a5ab071a5a5d284c489f6bbead
7
- data.tar.gz: c080a836542f47574368e027b612fff8f4c16fae08bd725abda080f43c3321806abd088d1f57a50a68e67080bbb223d3e6ee168cf6cd868cbb3c85e6059270ea
6
+ metadata.gz: 0ff3f1f915b797f0bb519bf12ed99d44cf52db9d228dfe97dd8b57445f1fdeed22e9f26c7fc24ac923173a394c867e59a65aa744cd55bcfb8362df80e720b8d3
7
+ data.tar.gz: 9abc728c5c1b032cc8a9cc43c478afde83cf16b13c93a3dca74c7a431cc26d81befcded09ee1b1eb1af9a01b90ebea81b06b932c862be363b0b88e39a26a70f0
data/.gitignore CHANGED
@@ -12,3 +12,6 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+
16
+ *~
17
+ \#*
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
@@ -0,0 +1,7 @@
1
+ # -*- mode: ruby -*-
2
+
3
+ Populus.watch 'node' do
4
+ on_receive do |json|
5
+ p json
6
+ end
7
+ end
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Populus
2
- VERSION = "0.0.1.pre"
2
+ VERSION = "0.0.1.pre3"
3
3
  end
@@ -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
- require "populus/version"
1
+ module Populus; end
2
2
 
3
- module Populus
4
- # Your code goes here...
5
- end
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.pre
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: