Class: Ree::Gen::Package

Inherits:
Object show all
Defined in:
lib/ree/gen/package.rb

Constant Summary collapse

TEMPLATE_NAME =
'package'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package_name, project_path, local_path, locals = {}) ⇒ Package

Returns a new instance of Package.



17
18
19
20
21
22
23
# File 'lib/ree/gen/package.rb', line 17

def initialize(package_name, project_path, local_path, locals = {})
  @project_path = project_path
  @package_name = package_name
  @local_path = local_path
  @locals = locals
  @schema = get_schema
end

Class Method Details

.generate(package_name:, project_path:, local_path:, locals: {}) ⇒ Object



12
13
14
# File 'lib/ree/gen/package.rb', line 12

def generate(package_name:, project_path:, local_path:, locals: {})
  Ree::Gen::Package.new(package_name, project_path, local_path, locals).create
end

Instance Method Details

#createObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ree/gen/package.rb', line 25

def create
  if Dir.exist?(File.join(Ree.root_dir, @local_path))
    raise Ree::Error.new("Package directory #{@local_path} already exists")
  end

  if @package_name.nil? || @package_name.empty?
    raise Ree::Error.new('Package name was not specified')
  end

  if @schema.packages.map(&:name).include?(@package_name)
    raise Ree::Error.new('Package already exists')
  end

  generated_files = Ree::TemplateHandler.generate(
    template_name: TEMPLATE_NAME,
    project_path: @project_path,
    local_path: @local_path,
    locals: { package_name: @package_name, local_path: @local_path }.merge(@locals)
  )

  generated_files
end

#get_schemaObject



48
49
50
51
52
53
# File 'lib/ree/gen/package.rb', line 48

def get_schema
  @schema ||= begin
    Ree.init(@project_path)
    Ree.container.packages_facade.load_packages_schema
  end
end