Sha256: 7e1c52525323b9e959f430c30e3ee3c05f6768b095ea65445bfe1ce62924cc52

Contents?: true

Size: 1.49 KB

Versions: 33

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal  = true

require 'fileutils'
require 'pathname'

module Ree
  module Gen
    class Package
      TEMPLATE_NAME = 'package'

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

      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

      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

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

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
ree-1.0.32 lib/ree/gen/package.rb
ree-1.0.31 lib/ree/gen/package.rb
ree-1.0.30 lib/ree/gen/package.rb
ree-1.0.29 lib/ree/gen/package.rb
ree-1.0.28 lib/ree/gen/package.rb
ree-1.0.27 lib/ree/gen/package.rb
ree-1.0.26 lib/ree/gen/package.rb
ree-1.0.25 lib/ree/gen/package.rb
ree-1.0.24 lib/ree/gen/package.rb
ree-1.0.23 lib/ree/gen/package.rb
ree-1.0.22 lib/ree/gen/package.rb
ree-1.0.21 lib/ree/gen/package.rb
ree-1.0.20 lib/ree/gen/package.rb
ree-1.0.19 lib/ree/gen/package.rb
ree-1.0.18 lib/ree/gen/package.rb
ree-1.0.17 lib/ree/gen/package.rb
ree-1.0.16 lib/ree/gen/package.rb
ree-1.0.15 lib/ree/gen/package.rb
ree-1.0.14 lib/ree/gen/package.rb
ree-1.0.13 lib/ree/gen/package.rb