flack 0.4.0 → 0.9.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/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+
2
+ # flack CHANGELOG.md
3
+
4
+
5
+ ## flack 0.9.0 released 2017-01-30
6
+
7
+ - initial release
8
+
9
+
10
+ ## flack 0.4.0 released 2016-09-12
11
+
12
+ - initial empty release
13
+
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2016-2016, John Mettraux, jmettraux+flor@gmail.com
2
+ Copyright (c) 2016-2017, John Mettraux, jmettraux+flor@gmail.com
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
data/Makefile CHANGED
@@ -26,3 +26,26 @@ build: gemspec_validate
26
26
  push: build
27
27
  gem push pkg/$(NAME)-$(VERSION).gem
28
28
 
29
+
30
+ ## flor tasks
31
+
32
+ RUBY=bundle exec ruby
33
+ FLOR_ENV?=dev
34
+ TO?=nil
35
+ FROM?=nil
36
+
37
+ migrate:
38
+ $(RUBY) -Ilib -e "require 'flor/unit'; Flor::Unit.new('envs/$(FLOR_ENV)/etc/conf.json').storage.migrate($(TO), $(FROM))"
39
+
40
+
41
+ ## flack tasks
42
+
43
+ serve:
44
+ bundle exec rackup -p 7007
45
+ s: serve
46
+
47
+ curl:
48
+ curl -s http://127.0.0.1:7007/ | \
49
+ $(RUBY) -e "require 'json'; puts JSON.pretty_generate(JSON.load(STDIN.read))"
50
+ c: curl
51
+
data/README.md CHANGED
@@ -1,7 +1,14 @@
1
1
 
2
2
  # flack
3
3
 
4
- Flack is a web front-end for the [flor](https://github.com/floraison/flor) workflow engine.
4
+ [![Build Status](https://secure.travis-ci.org/floraison/flack.svg)](http://travis-ci.org/floraison/flack)
5
+ [![Gem Version](https://badge.fury.io/rb/flack.svg)](http://badge.fury.io/rb/flack)
6
+
7
+ Flack is a Rack app for the [flor](https://github.com/floraison/flor) workflow engine.
8
+
9
+ ## api
10
+
11
+ Based on HAL ([spec](http://stateless.co/hal_specification.html) and [draft](https://tools.ietf.org/html/draft-kelly-json-hal-08)).
5
12
 
6
13
  ## license
7
14
 
data/env.txt ADDED
@@ -0,0 +1,38 @@
1
+
2
+ GATEWAY_INTERFACE: "CGI/1.1"
3
+ PATH_INFO: "/debug/77"
4
+ QUERY_STRING: "a=b&c=d"
5
+ REMOTE_ADDR: "::1"
6
+ REMOTE_HOST: "localhost"
7
+ REQUEST_METHOD: "GET"
8
+ REQUEST_URI: "http://localhost:7007/debug/77?a=b&c=d"
9
+ SCRIPT_NAME: ""
10
+ SERVER_NAME: "localhost"
11
+ SERVER_PORT: "7007"
12
+ SERVER_PROTOCOL: "HTTP/1.1"
13
+ SERVER_SOFTWARE: "WEBrick/1.3.1 (Ruby/1.9.3/2014-05-14)"
14
+ HTTP_HOST: "localhost:7007"
15
+ HTTP_CONNECTION: "keep-alive"
16
+ HTTP_UPGRADE_INSECURE_REQUESTS: "1"
17
+ HTTP_USER_AGENT: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36"
18
+ HTTP_ACCEPT: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
19
+ HTTP_ACCEPT_ENCODING: "gzip, deflate, sdch"
20
+ HTTP_ACCEPT_LANGUAGE: "ja,en-US;q=0.8,en;q=0.6,fr;q=0.4,de;q=0.2,it;q=0.2,zh-TW;q=0.2,zh;q=0.2"
21
+ HTTP_COOKIE: "sg_dev=2ebdd63d694602c96834d5a261fc471732a2a44c37f40d6446c5cab1b724a263"
22
+ rack.version: [1, 3]
23
+ rack.input: #<Rack::Lint::InputWrapper:0x007fb27b230048 @input=#<StringIO:0x007fb27b238b30>>
24
+ rack.errors: #<Rack::Lint::ErrorWrapper:0x007fb27b22fee0 @error=#<IO:<STDERR>>>
25
+ rack.multithread: true
26
+ rack.multiprocess: false
27
+ rack.run_once: false
28
+ rack.url_scheme: "http"
29
+ rack.hijack?: true
30
+ rack.hijack: #<Proc:0x007fb27b230ae8@/Users/jmettraux/.gem/ruby/1.9.3/gems/rack-1.6.4/lib/rack/lint.rb:525>
31
+ rack.hijack_io: nil
32
+ HTTP_VERSION: "HTTP/1.1"
33
+ REQUEST_PATH: "/debug/77"
34
+ rack.tempfiles: []
35
+ flack.path_info: ["debug", "77"]
36
+ flack.args: [77]
37
+ flack.query_string: {"a"=>"b", "c"=>"d"}
38
+
data/env2.txt ADDED
@@ -0,0 +1,33 @@
1
+ GATEWAY_INTERFACE:CGI/1.1
2
+ PATH_INFO:/debug
3
+ QUERY_STRING:
4
+ REMOTE_ADDR:127.0.0.1
5
+ REMOTE_HOST:localhost
6
+ REQUEST_METHOD:GET
7
+ REQUEST_URI:http://127.0.0.1:7007/flack/debug
8
+ SCRIPT_NAME:/flack
9
+ SERVER_NAME:127.0.0.1
10
+ SERVER_PORT:7007
11
+ SERVER_PROTOCOL:HTTP/1.1
12
+ SERVER_SOFTWARE:WEBrick/1.3.1 (Ruby/1.9.3/2014-05-14)
13
+ HTTP_HOST:127.0.0.1:7007
14
+ HTTP_USER_AGENT:curl/7.43.0
15
+ HTTP_ACCEPT:*/*
16
+ rack.version:[1
17
+ 3]
18
+ rack.input:#<Rack::Lint::InputWrapper:0x007ff6baa373a8>
19
+ rack.errors:#<Rack::Lint::ErrorWrapper:0x007ff6baa37290>
20
+ rack.multithread:true
21
+ rack.multiprocess:false
22
+ rack.run_once:false
23
+ rack.url_scheme:http
24
+ rack.hijack?:true
25
+ rack.hijack:#<Proc:0x007ff6baa38208@/Users/jmettraux/.gem/ruby/1.9.3/gems/rack-1.6.4/lib/rack/lint.rb:525>
26
+ rack.hijack_io:null
27
+ HTTP_VERSION:HTTP/1.1
28
+ REQUEST_PATH:/flack/debug
29
+ rack.tempfiles:[]
30
+ flack.path_info:[debug]
31
+ flack.args:[]
32
+ flack.query_string:{}
33
+ flack.root_uri:http://127.0.0.1:7007
data/flack.gemspec CHANGED
@@ -27,8 +27,10 @@ A web front-end to the flor workflow engine
27
27
  ]
28
28
 
29
29
  s.add_runtime_dependency 'flor', s.version
30
+ s.add_runtime_dependency 'rack', '~> 1.6'
31
+ s.add_runtime_dependency 'sequel', '~> 4'
30
32
 
31
- s.add_development_dependency 'rspec', '3.4.0'
33
+ s.add_development_dependency 'rspec', '~> 3'
32
34
 
33
35
  s.require_path = 'lib'
34
36
  end
@@ -0,0 +1,42 @@
1
+ #--
2
+ # Copyright (c) 2016-2017, John Mettraux, jmettraux+flor@gmail.com
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #
22
+ # Made in Japan.
23
+ #++
24
+
25
+
26
+ # /executions/*
27
+ #
28
+ class Flack::App
29
+
30
+ def get_executions(env)
31
+
32
+ # TODO implement paging
33
+ respond(env, @unit.executions.all)
34
+ end
35
+
36
+ def get_executions_i(env)
37
+
38
+ # TODO
39
+ debug_respond(env)
40
+ end
41
+ end
42
+
@@ -0,0 +1,169 @@
1
+ #--
2
+ # Copyright (c) 2016-2017, John Mettraux, jmettraux+flor@gmail.com
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #
22
+ # Made in Japan.
23
+ #++
24
+
25
+
26
+ # helpers
27
+ #
28
+ class Flack::App
29
+
30
+ protected
31
+
32
+ def debug_respond(env)
33
+
34
+ [ 200, { 'Content-Type' => 'application/json' }, [ JSON.dump(env) ] ]
35
+ end
36
+
37
+ def is_response?(o)
38
+
39
+ o.is_a?(Array) &&
40
+ o.length == 3 &&
41
+ o[0].is_a?(Fixnum) &&
42
+ o[1].is_a?(Hash) &&
43
+ o[2].is_a?(Array)
44
+ end
45
+
46
+ def respond(env, data, opts={})
47
+
48
+ return data if opts == {} && is_response?(data)
49
+
50
+ status = nil
51
+ links = nil
52
+ location = nil
53
+
54
+ if data.is_a?(Hash)
55
+ status = data['_status'] || data[:_status]
56
+ links = data.delete('_links') || data.delete(:_links)
57
+ location = data['_location'] || data[:_location]
58
+ end
59
+
60
+ status = status || opts[:code] || opts[:status] || 200
61
+
62
+ headers = { 'Content-Type' => 'application/json' }
63
+ headers['Location'] = location if location
64
+
65
+ json = serialize(env, data, opts)
66
+
67
+ json['_links'].merge!(links) if links
68
+
69
+ json['_status'] = status
70
+ json['_status_text'] = Rack::Utils::HTTP_STATUS_CODES[status]
71
+
72
+ if e = opts[:error]; json['error'] = e; end
73
+
74
+ [ status, headers, [ JSON.dump(json) ] ]
75
+ end
76
+
77
+ def try(o, meth)
78
+
79
+ o.respond_to?(meth) ? o.send(meth) : nil
80
+ end
81
+
82
+ def serialize(env, data, opts)
83
+
84
+ return serialize_array(env, data, opts) if data.is_a?(Array)
85
+
86
+ r =
87
+ (data.is_a?(Hash) ? Flor.dup(data) : nil) ||
88
+ (data.nil? ? {} : nil) ||
89
+ data.to_h
90
+
91
+ #r['_klass'] = data.class.to_s # too rubyish
92
+ r['_links'] = links(env)
93
+ r['_forms'] = forms(env)
94
+
95
+ r
96
+ end
97
+
98
+ def serialize_array(env, data, opts)
99
+
100
+ { '_links' => links(env),
101
+ '_embedded' => data.collect { |e| serialize(env, e, opts) } }
102
+ end
103
+
104
+ def determine_root_uri(env)
105
+
106
+ hh = env['HTTP_HOST'] || "#{env['SERVER_NAME']}:#{env['SERVER_PORT']}"
107
+
108
+ "#{env['rack.url_scheme']}://#{hh}#{env['SCRIPT_NAME']}"
109
+ end
110
+
111
+ def abs(env, href)
112
+
113
+ return href if href[0, 4] == 'http'
114
+ "#{env['flack.root_uri']}#{href[0, 1] == '/' ? '': '/'}#{href}"
115
+ end
116
+
117
+ def rel(env, href)
118
+
119
+ return href if href[0, 4] == 'http'
120
+ "#{env['SCRIPT_NAME']}#{href[0, 1] == '/' ? '': '/'}#{href}"
121
+ end
122
+
123
+ def link(env, h, type)
124
+
125
+ h["flack:#{type}"] = { href: rel(env, "/#{type}") }
126
+ end
127
+
128
+ def links(env)
129
+
130
+ h = {}
131
+
132
+ h['self'] = {
133
+ href: rel(env, env['REQUEST_PATH']) }
134
+ m = env['REQUEST_METHOD']
135
+ h['self'][:method] = m unless %w[ GET HEAD ].include?(m)
136
+
137
+ h['curies'] = [{
138
+ name: 'flack',
139
+ href: 'https://github.com/floraison/flack/blob/master/doc/rels.md#{rel}',
140
+ templated: true }]
141
+
142
+ link(env, h, :executions)
143
+
144
+ h
145
+ end
146
+
147
+ def forms(env)
148
+
149
+ h = {}
150
+
151
+ h['flack:forms/message'] = {
152
+ action: rel(env, '/message'),
153
+ method: 'POST',
154
+ _inputs: { 'flack:forms/message-content' => { type: 'json' } } }
155
+
156
+ h
157
+ end
158
+
159
+ def respond_bad_request(env, error=nil)
160
+
161
+ respond(env, {}, code: 400, error: error)
162
+ end
163
+
164
+ def respond_not_found(env, error=nil)
165
+
166
+ respond(env, {}, code: 404, error: error)
167
+ end
168
+ end
169
+
@@ -0,0 +1,36 @@
1
+ #--
2
+ # Copyright (c) 2016-2017, John Mettraux, jmettraux+flor@gmail.com
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #
22
+ # Made in Japan.
23
+ #++
24
+
25
+
26
+ # /
27
+ #
28
+ class Flack::App
29
+
30
+ def get_index(env)
31
+
32
+ # TODO
33
+ respond(env, nil)
34
+ end
35
+ end
36
+
@@ -0,0 +1,98 @@
1
+ #--
2
+ # Copyright (c) 2016-2017, John Mettraux, jmettraux+flor@gmail.com
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #
22
+ # Made in Japan.
23
+ #++
24
+
25
+
26
+ # /message
27
+ #
28
+ class Flack::App
29
+
30
+ def post_message(env)
31
+
32
+ msg = JSON.load(env['rack.input'].read)
33
+ #pp msg
34
+
35
+ pt = msg['point']
36
+
37
+ return respond_bad_request(env, 'missing msg point') \
38
+ unless pt
39
+ return respond_bad_request(env, "bad msg point #{pt.inspect}") \
40
+ unless %w[ launch cancel ].include?(pt)
41
+
42
+ r = self.send("queue_#{pt}", env, msg, { point: pt })
43
+
44
+ respond(env, r)
45
+ end
46
+
47
+ protected
48
+
49
+ def queue_launch(env, msg, ret)
50
+
51
+ dom = msg['domain']
52
+ src = msg['tree'] || msg['name']
53
+
54
+ return respond_bad_request(env, 'missing domain') \
55
+ unless dom
56
+ return respond_bad_request(env, 'missing "tree" or "name" in launch msg') \
57
+ unless src
58
+
59
+ opts = {}
60
+ opts[:domain] = dom
61
+
62
+ r = @unit.launch(src, opts)
63
+
64
+ ret['exid'] = r
65
+ ret['_status'] = 201
66
+ ret['_location'] = rel(env, '/executions/' + r)
67
+
68
+ ret['_links'] = {
69
+ 'flack:forms/message-created' => { 'href' => ret['_location'] } }
70
+
71
+ ret
72
+ end
73
+
74
+ def queue_cancel(env, msg, ret)
75
+
76
+ exid = msg['exid']
77
+ nid = msg['nid'] || '0'
78
+
79
+ return respond_bad_request(env, 'missing exid') \
80
+ unless exid
81
+
82
+ exe = @unit.executions[exid: exid]
83
+
84
+ return respond_not_found(env, 'missing execution') \
85
+ unless exe
86
+ return respond_not_found(env, 'missing execution node') \
87
+ unless exe.nodes[nid]
88
+
89
+ ret['xxx'] = @unit.queue({ 'point' => 'cancel', 'exid' => exid, 'nid' => nid })
90
+
91
+ ret['_status'] = 202
92
+ ret['_location'] = rel(env, '/executions/' + exid)
93
+ ret['_links'] = { 'flack:execution' => { 'href' => ret['_location'] } }
94
+
95
+ ret
96
+ end
97
+ end
98
+
@@ -0,0 +1,40 @@
1
+ #--
2
+ # Copyright (c) 2016-2017, John Mettraux, jmettraux+flor@gmail.com
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #
22
+ # Made in Japan.
23
+ #++
24
+
25
+
26
+ # /static/+
27
+ #
28
+ class Flack::App
29
+
30
+ RACK_FILE = Rack::File.new(
31
+ File.absolute_path(
32
+ File.join(
33
+ File.dirname(__FILE__), '..')))
34
+
35
+ def get_static_plus(env)
36
+
37
+ RACK_FILE.call(env)
38
+ end
39
+ end
40
+
data/lib/flack/app.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2016-2016, John Mettraux, jmettraux+flor@gmail.com
2
+ # Copyright (c) 2016-2017, John Mettraux, jmettraux+flor@gmail.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
@@ -22,7 +22,99 @@
22
22
  # Made in Japan.
23
23
  #++
24
24
 
25
+ require 'flack/app/helpers'
26
+ #
27
+ require 'flack/app/index'
28
+ require 'flack/app/static'
29
+ require 'flack/app/message'
30
+ require 'flack/app/executions'
25
31
 
26
- module Flack::App
32
+
33
+ class Flack::App
34
+
35
+ attr_reader :unit
36
+
37
+ def initialize(root, opts={})
38
+
39
+ @root = root
40
+
41
+ conf_path =
42
+ root.end_with?(File::SEPARATOR + 'conf.json') ?
43
+ root :
44
+ File.join(@root, 'etc', 'conf.json')
45
+
46
+ @unit = Flor::Unit.new(conf_path)
47
+
48
+ @unit.start unless opts[:start] == false
49
+
50
+ self.class.unit = @unit
51
+
52
+ @unit
53
+ end
54
+
55
+ def self.unit
56
+ @unit
57
+ end
58
+ def self.unit=(u)
59
+ @unit = u
60
+ end
61
+
62
+ def call(env)
63
+
64
+ flack_path_info = (env['PATH_INFO'][1..-1] || '')
65
+ .split('/')
66
+
67
+ flack_path_info = [ 'index' ] if flack_path_info.empty?
68
+
69
+ env['flack.path_info'] = flack_path_info
70
+
71
+ METHS.each do |m|
72
+
73
+ next if env['REQUEST_METHOD'] != m[1]
74
+ next if flack_path_info.length != m[2].length
75
+
76
+ match = true
77
+ args = []
78
+
79
+ for i in 0..flack_path_info.length - 1
80
+
81
+ break unless match
82
+
83
+ pi = flack_path_info[i]
84
+ mi = m[2][i]
85
+
86
+ break if mi == 'plus' || mi == 'star'
87
+
88
+ if mi == 'i'
89
+ match = pi.match(/\A\d+\z/)
90
+ args << pi.to_i
91
+ elsif mi == 's'
92
+ args << pi
93
+ else
94
+ match = pi == mi
95
+ end
96
+ end
97
+
98
+ next unless match
99
+
100
+ env['flack.args'] = args
101
+ env['flack.query_string'] = Rack::Utils.parse_query(env['QUERY_STRING'])
102
+ env['flack.root_uri'] = determine_root_uri(env)
103
+
104
+ return send(m[0], env)
105
+ end
106
+
107
+ respond_not_found(env)
108
+ end
109
+
110
+ def get_debug(env); debug_respond(env); end
111
+ alias get_debug_i get_debug
112
+
113
+ METHS = instance_methods
114
+ .collect(&:to_s)
115
+ .select { |m| m.match(/\A(get|head|put|post|delete)_.+\z/) }
116
+ .select { |m| instance_method(m).arity == 1 }
117
+ .collect { |m| s = m.split('_'); [ m, s.shift.upcase, s ] }
118
+ .collect(&:freeze).freeze
27
119
  end
28
120
 
data/lib/flack.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2016-2016, John Mettraux, jmettraux+flor@gmail.com
2
+ # Copyright (c) 2016-2017, John Mettraux, jmettraux+flor@gmail.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
@@ -22,13 +22,15 @@
22
22
  # Made in Japan.
23
23
  #++
24
24
 
25
- require 'flor'
25
+ require 'rack'
26
26
 
27
- require 'flack/app'
27
+ require 'flor/unit'
28
28
 
29
29
 
30
30
  module Flack
31
31
 
32
- VERSION = '0.4.0'
32
+ VERSION = '0.9.0'
33
33
  end
34
34
 
35
+ require 'flack/app'
36
+
data/t.txt ADDED
@@ -0,0 +1,7 @@
1
+
2
+ https://git.io/viDSd
3
+ https://goo.gl/xuOZcu
4
+ http://tiny.cc/flack
5
+
6
+ http://lambda.io/flack
7
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-09-12 00:00:00.000000000 Z
12
+ date: 2017-01-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: flor
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.4.0
21
+ version: 0.9.0
22
22
  prerelease:
23
23
  type: :runtime
24
24
  prerelease: false
@@ -27,24 +27,56 @@ dependencies:
27
27
  requirements:
28
28
  - - '='
29
29
  - !ruby/object:Gem::Version
30
- version: 0.4.0
30
+ version: 0.9.0
31
31
  prerelease:
32
+ - !ruby/object:Gem::Dependency
33
+ name: rack
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: '1.6'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ - !ruby/object:Gem::Dependency
49
+ name: sequel
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '4'
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ version: '4'
32
64
  - !ruby/object:Gem::Dependency
33
65
  name: rspec
34
66
  requirement: !ruby/object:Gem::Requirement
35
67
  none: false
36
68
  requirements:
37
- - - '='
69
+ - - ~>
38
70
  - !ruby/object:Gem::Version
39
- version: 3.4.0
71
+ version: '3'
40
72
  type: :development
41
73
  prerelease: false
42
74
  version_requirements: !ruby/object:Gem::Requirement
43
75
  none: false
44
76
  requirements:
45
- - - '='
77
+ - - ~>
46
78
  - !ruby/object:Gem::Version
47
- version: 3.4.0
79
+ version: '3'
48
80
  description: A web front-end to the flor workflow engine
49
81
  email:
50
82
  - jmettraux@gmail.com
@@ -53,10 +85,19 @@ extensions: []
53
85
  extra_rdoc_files: []
54
86
  files:
55
87
  - Makefile
88
+ - lib/flack/app/executions.rb
89
+ - lib/flack/app/helpers.rb
90
+ - lib/flack/app/index.rb
91
+ - lib/flack/app/message.rb
92
+ - lib/flack/app/static.rb
56
93
  - lib/flack/app.rb
57
94
  - lib/flack.rb
58
95
  - flack.gemspec
96
+ - env.txt
97
+ - env2.txt
59
98
  - LICENSE.txt
99
+ - t.txt
100
+ - CHANGELOG.md
60
101
  - README.md
61
102
  homepage: http://github.com/floraison
62
103
  licenses: