Sha256: f427fadefe83ec9d98c9266159b2eeb7a20819600d2f3e488c54ee1bfe5f4724

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

require 'hanami/environment'
require 'hanami/commands/command'
require 'hanami/generators/generatable'
require 'hanami/generators/test_framework'
require 'hanami/generators/template_engine'
require 'hanami/version'
require 'hanami/utils/string'

module Hanami
  module Commands
    class Generate
      class Abstract < Commands::Command

        include Hanami::Generators::Generatable

        attr_reader :options, :target_path

        def initialize(options)
          super

          @options = Hanami::Utils::Hash.new(options).symbolize!
          assert_options!

          @target_path = Hanami.root
        end

        def template_source_path
          generator = self.class.name.split('::').last.downcase
          Pathname.new(::File.dirname(__FILE__) + "/../../generators/#{generator}/").realpath
        end

        private

        def test_framework
          @test_framework ||= Hanami::Generators::TestFramework.new(hanamirc, options[:test])
        end

        def hanamirc_options
          hanamirc.options
        end

        def hanamirc
          @hanamirc ||= Hanamirc.new(target_path)
        end

        def template_engine
          @template_engine ||= Hanami::Generators::TemplateEngine.new(hanamirc, options[:template])
        end

        def assert_options!
          if options.nil?
            raise ArgumentError.new('options must not be nil')
          end
        end

      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hanami-0.9.2 lib/hanami/commands/generate/abstract.rb
hanami-0.9.1 lib/hanami/commands/generate/abstract.rb
hanami-0.9.0 lib/hanami/commands/generate/abstract.rb