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

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

Overview

Exposed to the controller class.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(klass) ⇒ Object



111
112
113
114
115
116
# File 'lib/utopia/controller/actions.rb', line 111

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

Instance Method Details

#actionsObject



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

def actions
	@actions ||= Action.new
end

#dispatch(controller, request, path) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
# File 'lib/utopia/controller/actions.rb', line 134

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



122
123
124
125
126
127
128
# File 'lib/utopia/controller/actions.rb', line 122

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



130
131
132
# File 'lib/utopia/controller/actions.rb', line 130

def otherwise(&block)
	@otherwise = block
end