Skip to content

Commit

Permalink
refactor Journey::Routes
Browse files Browse the repository at this point in the history
* prefer do-end for multiline blocks
* prefer or-equals over returns with checks
  • Loading branch information
goshacmd committed Jan 6, 2013
1 parent 807e176 commit 2467ec8
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions actionpack/lib/action_dispatch/journey/routes.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,24 +33,23 @@ def clear
end end


def partitioned_routes def partitioned_routes
@partitioned_routes ||= routes.partition { |r| @partitioned_routes ||= routes.partition do |r|
r.path.anchored && r.ast.grep(Nodes::Symbol).all? { |n| n.default_regexp? } r.path.anchored && r.ast.grep(Nodes::Symbol).all?(&:default_regexp?)
} end
end end


def ast def ast
return @ast if @ast @ast ||= begin
return if partitioned_routes.first.empty? asts = partitioned_routes.first.map(&:ast)

Nodes::Or.new(asts) unless asts.empty?
asts = partitioned_routes.first.map { |r| r.ast } end
@ast = Nodes::Or.new(asts)
end end


def simulator def simulator
return @simulator if @simulator @simulator ||= begin

gtg = GTG::Builder.new(ast).transition_table
gtg = GTG::Builder.new(ast).transition_table GTG::Simulator.new(gtg)
@simulator = GTG::Simulator.new(gtg) end
end end


# Add a route to the routing table. # Add a route to the routing table.
Expand Down

0 comments on commit 2467ec8

Please sign in to comment.