/
abstract.rb
64 lines (50 loc) · 1.57 KB
/
abstract.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
# @since x.x.x
# @api private
def project_name
Utils::String.new(Hanami::Environment.new.project_name).underscore
end
end
end
end
end