Sha256: 2960426692016d4072303c9f098c3b763b3205d2cb13b3bfe8da20f43c44a199

Contents?: true

Size: 1.49 KB

Versions: 3

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

require 'pathname'

require 'skippy'
require 'skippy/command'
require 'skippy/group'

class Skippy::App

  # @param [String] boot_loader_path
  # @return [Skippy::App]
  def self.boot(boot_loader_path)
    Skippy.app = Skippy::App.new(boot_loader_path)
    Skippy.app.boot
    Skippy.app
  end

  attr_reader :path

  # @param [String] boot_loader_path
  def initialize(boot_loader_path)
    @boot_loader_path = File.expand_path(boot_loader_path)
    @path = File.dirname(@boot_loader_path)
  end

  def boot
    boot_commands
  end

  def resources(item = nil)
    resource = Pathname.new(File.join(path, 'resources'))
    item ? resource.join(item) : resource
  end

  # @return [Array<String>]
  def templates_source_path
    Pathname.new(File.join(path, 'templates'))
  end

  # @return [Array<Pathname>]
  def templates
    result = []
    templates_source_path.entries.each { |entry|
      template_path = templates_source_path.join(entry)
      next unless template_path.directory?
      next if %w(. ..).include?(entry.basename.to_s)

      result << entry.expand_path(templates_source_path)
    }
    result
  end

  private

  def boot_commands
    # Load the default skippy commands.
    path_commands = File.join(path, 'commands')
    commands_pattern = File.join(path_commands, '*.rb')
    Dir.glob(commands_pattern).sort.each { |filename|
      # noinspection RubyResolve
      require filename
    }
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
skippy-0.5.2.a lib/skippy/app.rb
skippy-0.5.1.a lib/skippy/app.rb
skippy-0.5.0.a lib/skippy/app.rb