Sha256: a12dd1b4764866b75634ad6febeb2a903532d50a317df2c037fd00160f01fa3e

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'hocus_pocus/generator/engine'

module HocusPocus
  module Generator
    class Railtie < ::Rails::Railtie #:nodoc:
      initializer 'hocus_pocus.generator' do |app|
        ActiveSupport.on_load(:after_initialize) do
          if HocusPocus.config.enable_generator
            Rails.application.routes.append do
              mount HocusPocus::Generator::Engine, :at => '/'
            end
          end
        end

        ActiveSupport.on_load(:action_view) do
          if HocusPocus.config.enable_generator
            class ::ActionView::Base
              def method_missing(method, args = {}, &blk)
                if method.to_s =~ /(new_|edit_)?(.*)(_path|_url)\z/
                  # to avoid DoubleRenderError
                  controller.instance_variable_set :@_response_body, nil
                  #FIXME preserve args
                  controller.redirect_to "/#{$2.pluralize}?return_path=#{method}(#{args})"
                else
                  super
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hocus_pocus-0.2.0 engines/generator/lib/hocus_pocus/generator/railtie.rb