Class: TDiary::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/tdiary/dispatcher.rb,
lib/tdiary/dispatcher/index_main.rb,
lib/tdiary/dispatcher/update_main.rb

Defined Under Namespace

Classes: IndexMain, UpdateMain

Constant Summary collapse

TARGET =
{
	index: IndexMain,
	update: UpdateMain
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ Dispatcher

Returns a new instance of Dispatcher.



14
15
16
# File 'lib/tdiary/dispatcher.rb', line 14

def initialize( target )
	@target = TARGET[target]
end

Class Method Details

.extract_status_for_legacy_tdiary(head) ⇒ Object

FIXME temporary method during (scratch) refactoring



27
28
29
30
31
32
33
34
35
36
# File 'lib/tdiary/dispatcher.rb', line 27

def extract_status_for_legacy_tdiary( head )
	status_str = head.delete('status')
	return 200 if !status_str || status_str.empty?

	if m = status_str.match(/(\d+)\s(.+)\Z/)
		m[1].to_i
	else
		200
	end
end

.indexObject



38
39
40
# File 'lib/tdiary/dispatcher.rb', line 38

def index
	new( :index )
end

.updateObject



42
43
44
# File 'lib/tdiary/dispatcher.rb', line 42

def update
	new( :update )
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
# File 'lib/tdiary/dispatcher.rb', line 18

def call( env )
	request = adopt_rack_request_to_plain_old_tdiary_style( env )
	result = @target.run( request )
	result.headers.reject!{|k,v| k.to_s.downcase == "status" }
	result.to_a
end