Module: Utopia::Controller::Actions::ClassMethods

Defined in:
lib/utopia/controller/actions.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(klass) ⇒ Object



116
117
118
119
120
121
# File 'lib/utopia/controller/actions.rb', line 116

def self.extended(klass)
	klass.instance_eval do
		@actions = nil
		@otherwise = nil
	end
end

Instance Method Details

#actions ⇒ Object



123
124
125
# File 'lib/utopia/controller/actions.rb', line 123

def actions
	@actions ||= Action.new
end

#dispatch(controller, request, path) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
# File 'lib/utopia/controller/actions.rb', line 139

def dispatch(controller, request, path)
	if @actions
		matched = @actions.apply(path.components) do |action|
			controller.instance_exec(request, path, &action.callback)
		end
	end
	
	if @otherwise and !matched
		controller.instance_exec(request, path, &@otherwise)
	end
end

#on(first, *path, **options, &block) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/utopia/controller/actions.rb', line 127

def on(first, *path, **options, &block)
	if first.is_a? Symbol
		first = ['**', first.to_s]
	end
	
	actions.define(Path.split(first) + path, options, &block)
end

#otherwise(&block) ⇒ Object



135
136
137
# File 'lib/utopia/controller/actions.rb', line 135

def otherwise(&block)
	@otherwise = block
end