Sha256: 70f05c2b8a4f1384a88be0fe219aa330547afe62dc51ed00d5f2ac95559db30d

Contents?: true

Size: 989 Bytes

Versions: 2

Compression:

Stored size: 989 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(&block)
          yield if block
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
draper-1.2.0 lib/generators/decorator/decorator_generator.rb
jamesgolick-draper-1.1.1a lib/generators/decorator/decorator_generator.rb