Class: Flack::App
- Inherits:
-
Object
- Object
- Flack::App
- Defined in:
- lib/flack/app/index.rb,
lib/flack/app.rb,
lib/flack/app/static.rb,
lib/flack/app/helpers.rb,
lib/flack/app/message.rb,
lib/flack/app/executions.rb
Overview
/executions/*
Constant Summary collapse
- METHS =
instance_methods .collect(&:to_s) .select { |m| m.match(/\A(get|head|put|post|delete)_.+\z/) } .select { |m| instance_method(m).arity == 1 } .collect { |m| s = m.split('_'); [ m, s.shift.upcase, s ] } .collect(&:freeze).freeze
- RACK_FILE =
Rack::File.new( File.absolute_path( File.join( File.dirname(__FILE__), '..')))
Instance Attribute Summary collapse
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
- #get_debug(env) ⇒ Object (also: #get_debug_i)
- #get_executions(env) ⇒ Object
- #get_executions_i(env) ⇒ Object
- #get_index(env) ⇒ Object
- #get_static_plus(env) ⇒ Object
-
#initialize(root, opts = {}) ⇒ App
constructor
A new instance of App.
- #post_message(env) ⇒ Object
Constructor Details
#initialize(root, opts = {}) ⇒ App
Returns a new instance of App.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/flack/app.rb', line 37 def initialize(root, opts={}) @root = root conf_path = root.end_with?(File::SEPARATOR + 'conf.json') ? root : File.join(@root, 'etc', 'conf.json') @unit = Flor::Unit.new(conf_path) @unit.start unless opts[:start] == false self.class.unit = @unit @unit end |
Instance Attribute Details
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
35 36 37 |
# File 'lib/flack/app.rb', line 35 def unit @unit end |
Class Method Details
.unit ⇒ Object
55 56 57 |
# File 'lib/flack/app.rb', line 55 def self.unit @unit end |
.unit=(u) ⇒ Object
58 59 60 |
# File 'lib/flack/app.rb', line 58 def self.unit=(u) @unit = u end |
Instance Method Details
#call(env) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/flack/app.rb', line 62 def call(env) flack_path_info = (env['PATH_INFO'][1..-1] || '') .split('/') flack_path_info = [ 'index' ] if flack_path_info.empty? env['flack.path_info'] = flack_path_info METHS.each do |m| next if env['REQUEST_METHOD'] != m[1] next if flack_path_info.length != m[2].length match = true args = [] for i in 0..flack_path_info.length - 1 break unless match pi = flack_path_info[i] mi = m[2][i] break if mi == 'plus' || mi == 'star' if mi == 'i' match = pi.match(/\A\d+\z/) args << pi.to_i elsif mi == 's' args << pi else match = pi == mi end end next unless match env['flack.args'] = args env['flack.query_string'] = Rack::Utils.parse_query(env['QUERY_STRING']) env['flack.root_uri'] = determine_root_uri(env) return send(m[0], env) end respond_not_found(env) end |
#get_debug(env) ⇒ Object Also known as: get_debug_i
110 |
# File 'lib/flack/app.rb', line 110 def get_debug(env); debug_respond(env); end |
#get_executions(env) ⇒ Object
30 31 32 33 34 |
# File 'lib/flack/app/executions.rb', line 30 def get_executions(env) # TODO implement paging respond(env, @unit.executions.all) end |
#get_executions_i(env) ⇒ Object
36 37 38 39 40 |
# File 'lib/flack/app/executions.rb', line 36 def get_executions_i(env) # TODO debug_respond(env) end |
#get_index(env) ⇒ Object
30 31 32 33 34 |
# File 'lib/flack/app/index.rb', line 30 def get_index(env) # TODO respond(env, nil) end |
#get_static_plus(env) ⇒ Object
35 36 37 38 |
# File 'lib/flack/app/static.rb', line 35 def get_static_plus(env) RACK_FILE.call(env) end |
#post_message(env) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/flack/app/message.rb', line 30 def (env) msg = JSON.load(env['rack.input'].read) #pp msg pt = msg['point'] return respond_bad_request(env, 'missing msg point') \ unless pt return respond_bad_request(env, "bad msg point #{pt.inspect}") \ unless %w[ launch cancel ].include?(pt) r = self.send("queue_#{pt}", env, msg, { point: pt }) respond(env, r) end |