class ActionFlow::Expression
Public Class Methods
from_hash(hash)
click to toggle source
# File lib/action_flow/expression.rb, line 12 def self.from_hash(hash) new(nil, hash) end
new(controller, params, &block)
click to toggle source
# File lib/action_flow/expression.rb, line 4 def initialize(controller, params, &block) @params = params.dup @controller = (@params.delete(:controller) || controller).to_s @action = @params.delete(:action).to_s if @params[:action] @format = @params.delete(:format).to_s if @params[:format] @matcher = block end
Public Instance Methods
*(expression)
click to toggle source
# File lib/action_flow/expression.rb, line 20 def *(expression) @format = expression.instance_eval { @controller } @action = nil self end
+(expression)
click to toggle source
# File lib/action_flow/expression.rb, line 16 def +(expression) self.class::Group.new + self + expression end
/(expression)
click to toggle source
# File lib/action_flow/expression.rb, line 26 def /(expression) expression.nesting = @controller expression end
===(context)
click to toggle source
# File lib/action_flow/expression.rb, line 47 def ===(context) p, req = context.params, context.request return false if (@controller != p[:controller].to_s) or (@action and @action != p[:action].to_s) or (@verb and !req.__send__("#{ @verb }?")) or (@format and @format != p[:format].to_s) return false unless @params.all? do |key, value| Variable === value || (value == p[key]) || (value == p[key].to_s) || (value === p[key]) || (value === p[key].to_i) end @matcher ? context.instance_eval(&@matcher) : true end
inspect()
click to toggle source
# File lib/action_flow/expression.rb, line 77 def inspect source = @controller.dup source << ".#{ @action }" if @action source << "(#{ @params.map { |k,v| ":#{k} => #{v.inspect}" } * ', ' })" unless @params.empty? source << "#{ @action ? '.' : '*' }#{ @format }" if @format source = "#{ @verb }(#{ source })" if @verb source end
method_missing(name, params = {}, &block)
click to toggle source
# File lib/action_flow/expression.rb, line 35 def method_missing(name, params = {}, &block) @format = name.to_s if @action @action ||= name.to_s @params.update(params) if Hash === params @matcher = block if block_given? self end
nesting=(name)
click to toggle source
# File lib/action_flow/expression.rb, line 31 def nesting=(name) @controller = "#{ name }/#{ @controller }" end
to_params(env = {})
click to toggle source
# File lib/action_flow/expression.rb, line 64 def to_params(env = {}) options = {:controller => '/' + @controller} options[:action] = @action || :index options[:format] = @format if @format @params.each do |key, value| value = value.lookup(env) if Variable === value options[key] = value end options end
verb=(verb)
click to toggle source
# File lib/action_flow/expression.rb, line 43 def verb=(verb) @verb = verb.to_s end