Class: RailsUpgrade::Upgraders::FakeRoute

Inherits:
RouteObject
  • Object
show all
Defined in:
lib/rails-upgrade/upgraders/routes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RouteObject

#indent_lines, #opts_to_string

Constructor Details

#initialize(path, options, name = "") ⇒ FakeRoute

Returns a new instance of FakeRoute.



181
182
183
184
185
186
# File 'lib/rails-upgrade/upgraders/routes.rb', line 181

def initialize(path, options, name = "")
  @path = path
  @options = options || {}
  @name = name
  @indent = RouteRedrawer.indent
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



179
180
181
# File 'lib/rails-upgrade/upgraders/routes.rb', line 179

def name
  @name
end

#optionsObject

Returns the value of attribute options.



179
180
181
# File 'lib/rails-upgrade/upgraders/routes.rb', line 179

def options
  @options
end

#pathObject

Returns the value of attribute path.



179
180
181
# File 'lib/rails-upgrade/upgraders/routes.rb', line 179

def path
  @path
end

Instance Method Details

#to_route_codeObject



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/rails-upgrade/upgraders/routes.rb', line 188

def to_route_code
  if @options[:default_route]
    indent_lines ["match '#{@path}'"]
  else
    base = "match '%s' => '%s#%s'"
    extra_options = []
  
    if not name.empty?
      extra_options << ":as => :#{name}"
    end
    
    if @options[:requirements]
      @options[:constraints] = @options.delete(:requirements)
    end
    
    if @options[:conditions]
      @options[:via] = @options.delete(:conditions).delete(:method)
    end
  
    @options ||= {}
    base = (base % [@path, @options.delete(:controller), (@options.delete(:action) || "index")])
    opts = opts_to_string(@options)
    
    route_pieces = ([base] + extra_options + [opts])
    route_pieces.delete("")
    
    indent_lines [route_pieces.join(", ")]
  end
end