Sha256: 19757eeed55df002deaffc2d76179cc107531ec92e5030a1ec74a8b93a295ca4

Contents?: true

Size: 912 Bytes

Versions: 3

Compression:

Stored size: 912 Bytes

Contents

# frozen_string_literal: true

require 'pathname'

require 'skippy/library'

class Skippy::LibModule

  attr_reader :path, :library

  class ModuleNotFoundError < Skippy::Error; end

  # @param [Skippy::Library] library
  # @param [String] path
  def initialize(library, path)
    @path = Pathname.new(path)
    raise ModuleNotFoundError, @path.to_s unless @path.file?

    @library = library
  end

  def <=>(other)
    other.is_a?(self.class) ? name <=> other.name : nil
  end

  def eql?(other)
    # http://javieracero.com/blog/the-key-to-ruby-hashes-is-eql-hash
    other.is_a?(self.class) && name.casecmp(other.name).zero?
  end

  # @param [String]
  def basename
    path.basename('.*').to_s
  end

  def hash
    name.hash
  end

  # @param [String]
  def name
    "#{library.name}/#{basename}"
  end

  # @param [String]
  def to_s
    name
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

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