Sha256: 1810cb536fbfc4263d9caefa502f6be27ef27cf495d3996ed7e0075fd2d2d417

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require "active_support/concern"

module Redmine
  module Generators
    module PluginNameAttribute
      extend ActiveSupport::Concern

      def initialize(args = [], options = {}, config = {})
        self.plugin_name = args.shift unless plugin_name
        plugin_destination = plugin_destination_root
        raise "Invalid plugin name #{plugin_name}" if bail_on_missing? && !plugin_destination
        super
        self.destination_root = plugin_destination
      end

      protected
      def bail_on_missing?
        true
      end

      def plugin_name=(name)
        Redmine::Generators.plugin = name
      end

      def plugin_name
        Redmine::Generators.plugin
      end

      def possible_plugin_names
        %W(#{plugin_name} redmine_#{plugin_name} chiliproject_#{plugin_name})
      end

      def plugin_destination_root
        possible_plugin_paths.find { |p| p.exist? }
      end

      def possible_plugin_paths
        possible_plugin_names.map { |p| Rails.root.join "plugins", p }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
redmine-generators-0.0.1 lib/redmine/generators/plugin_name_attribute.rb