Sha256: d3b6901a4bbafd4bdcd4f6be35fdac7f4813c85a5fdf0326f29963007750b29b

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

require 'json'
require 'pathname'

require 'skippy/helpers/file'
require 'skippy/config'
require 'skippy/config_accessors'
require 'skippy/lib_module'

class Skippy::Library

  extend Skippy::ConfigAccessors

  include Skippy::Helpers::File

  CONFIG_FILENAME = 'skippy.json'.freeze

  attr_reader :path

  config_attr_reader :title, key: :name # TODO(thomthom): Clean up this kludge.
  config_attr_reader :version

  class LibraryNotFoundError < Skippy::Error; end

  def initialize(path)
    @path = Pathname.new(path)
    raise LibraryNotFoundError, @path.to_s unless @path.directory?
    # noinspection RubyResolve
    @config = Skippy::Config.load(config_file)
  end

  def name
    path.basename.to_s
  end

  def modules
    libs = modules_path.children(false).select { |file|
      file.extname.downcase == '.rb'
    }
    libs.map! { |lib|
      path = modules_path.join(lib)
      Skippy::LibModule.new(path)
    }
    libs
  end

  private

  def config_file
    path.join(CONFIG_FILENAME)
  end

  def modules_path
    # TODO(thomthom): Make this configurable and default to 'lib'?
    path.join('src')
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
skippy-0.2.0.a lib/skippy/library.rb