Sha256: dcd3cf9c23de54751b0221a1a54c7188e2110a8609424d2c41d2ec19ea1b50d4

Contents?: true

Size: 1.37 KB

Versions: 5

Compression:

Stored size: 1.37 KB

Contents

module Batman
  module Generators
    module Common
      def self.included(base)
        base.send(:extend, ClassMethods)
        base.source_root File.expand_path("../../templates", __FILE__)
      end

      protected
      def with_app_name
        raise "Batman application name must be given" unless app_name
        yield
      end

      def js_app_name
        app_name.camelize
      end

      def app_name
        @app_name ||= options[:app_name] || 'batman'
      end

      def js_application_name
        application_name.camelize
      end

      def application_name
        rails_application_name = if defined?(::Rails) && ::Rails.application
          ::Rails.application.class.name.split('::').first.underscore
        end
        @application_name ||= options[:app_name] || rails_application_name
      end

      def js_path
        "app/assets"
      end

      def app_path
        "#{js_path}/#{app_name}"
      end

      def singular_model_name
        singular_table_name.camelize
      end

      def app_name_flag
        return if app_name == 'batman'
        "--app_name #{options[:app_name] || app_name}"
      end

      module ClassMethods
        def requires_app_name
          class_option :app_name, :type => :string, :optional => true,
                       :desc => "Name of the Batman app (defaults to the Rails app name"
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
batman-rails-0.15.4 lib/generators/common.rb
batman-rails-0.15.3 lib/generators/common.rb
batman-rails-0.15.2 lib/generators/common.rb
batman-rails-0.15.1 lib/generators/common.rb
batman-rails-0.15.0 lib/generators/common.rb