Sha256: 825b351779d2205726bc7dc0798e14cd7f912e08e8713bb1d533d4fa3fc0a806

Contents?: true

Size: 1.17 KB

Versions: 10

Compression:

Stored size: 1.17 KB

Contents

require "active_support/all"

module Godmin
  module Generators
    class Base < Rails::Generators::Base
      def self.source_paths
        %w(authentication install policy resource).map do |path|
          File.expand_path("../../../generators/godmin/#{path}/templates", __FILE__)
        end
      end

      private

      def namespace
        @namespace ||= Rails::Generators.namespace
      end

      def namespaced?
        @namespaced ||= namespace.present?
      end

      def namespaced_path
        @namespaced_path ||= begin
          if namespaced?
            namespace.name.classify.split("::").map(&:underscore)
          else
            []
          end
        end
      end

      def module_namespacing(&block)
        content = capture(&block)
        content = wrap_with_namespace(content) if namespaced?
        concat(content)
      end

      def indent(content, multiplier = 2)
        spaces = " " * multiplier
        content.each_line.map { |line| line.blank? ? line : "#{spaces}#{line}" }.join
      end

      def wrap_with_namespace(content)
        content = indent(content).chomp
        "module #{namespace.name}\n#{content}\nend\n"
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
godmin-0.12.2 lib/godmin/generators/base.rb
godmin-0.12.1 lib/godmin/generators/base.rb
godmin-0.12.0 lib/godmin/generators/base.rb
godmin-0.11.2 lib/godmin/generators/base.rb
godmin-0.11.1 lib/godmin/generators/base.rb
godmin-0.11.0 lib/godmin/generators/base.rb
godmin-0.10.3 lib/godmin/generators/base.rb
godmin-0.10.2 lib/godmin/generators/base.rb
godmin-0.10.1 lib/godmin/generators/base.rb
godmin-0.10.0 lib/godmin/generators/base.rb