Sha256: e1bf20f71bbf751dbb74789ed93ee7e6e2799c34323ea1e9c926449bb3ed7ec5

Contents?: true

Size: 1.79 KB

Versions: 4

Compression:

Stored size: 1.79 KB

Contents

# Adapted from Restful Authentication generator
Rails::Generator::Commands::Create.class_eval do
  def route_resource(*resources)
    resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
    sentinel = 'ActionController::Routing::Routes.draw do |map|'

    logger.route "map.resource #{resource_list}"
    unless options[:pretend]
      gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
        "#{match}\n  map.resource #{resource_list}\n"
      end
    end
  end
  
  def route_name(name, path, route_options)
    sentinel = 'ActionController::Routing::Routes.draw do |map|'
    
    logger.route "map.#{name} '#{path}', #{route_options}"
    unless options[:pretend]
      gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
        "#{match}\n  map.#{name} '#{path}', #{route_options}"
      end
    end
  end
end

Rails::Generator::Commands::Destroy.class_eval do
  def route_resource(*resources)
    resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
    look_for = "\n  map.resource #{resource_list}\n"
    logger.route "map.resource #{resource_list}"
    unless options[:pretend]
      gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
    end
  end
  
  def route_name(name, path, route_options)
    look_for =   "\n  map.#{name} '#{path}', #{route_options}"
    logger.route "map.#{name} '#{path}', #{route_options}"
    unless options[:pretend]
      gsub_file    'config/routes.rb', /(#{look_for})/mi, ''
    end
  end
end

Rails::Generator::Commands::List.class_eval do
  def route_resource(*resources)
    resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
    logger.route "map.resource #{resource_list}"
  end
  
  def route_name(name, path, route_options)
    logger.route "map.#{name} '#{path}', #{route_options}"
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
event-calendar-2.3.3 generators/event_calendar/lib/insert_routes.rb
event-calendar-2.3.2 generators/event_calendar/lib/insert_routes.rb
event-calendar-2.3.1 generators/event_calendar/lib/insert_routes.rb
elevation_event_calendar-1.0.0 ./generators/event_calendar/lib/insert_routes.rb