Sha256: 8cbf9a43ff90ce739c36c5f97944cdfe9431a8c204270877708d2af791d4b67c

Contents?: true

Size: 988 Bytes

Versions: 9

Compression:

Stored size: 988 Bytes

Contents

module Rails
  module Generators
   class DecoratorGenerator < NamedBase
      source_root File.expand_path("../templates", __FILE__)
      check_class_collision suffix: "Decorator"

      class_option :parent, type: :string, desc: "The parent class for the generated decorator"

      def create_decorator_file
        template 'decorator.rb', File.join('app/decorators', class_path, "#{file_name}_decorator.rb")
      end

      hook_for :test_framework

      private

      def parent_class_name
        options.fetch("parent") do
          begin
            require 'application_decorator'
            ApplicationDecorator
          rescue LoadError
            "Draper::Decorator"
          end
        end
      end

      # Rails 3.0.X compatibility, stolen from https://github.com/jnunemaker/mongomapper/pull/385/files#L1R32
      unless methods.include?(:module_namespacing)
        def module_namespacing
          yield if block_given?
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
draper-3.0.0.pre1 lib/generators/rails/decorator_generator.rb
draper_new-3.0.0 lib/generators/rails/decorator_generator.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/draper-2.1.0/lib/generators/rails/decorator_generator.rb
draper-2.1.0 lib/generators/rails/decorator_generator.rb
draper-2.0.0 lib/generators/rails/decorator_generator.rb
draper-1.4.0 lib/generators/rails/decorator_generator.rb
draper-1.3.1 lib/generators/rails/decorator_generator.rb
draper-1.3.0 lib/generators/rails/decorator_generator.rb
draper-1.2.1 lib/generators/decorator/decorator_generator.rb