Class: Teapot::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/teapot/package.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, name, options = {}) ⇒ Package

Returns a new instance of Package.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/teapot/package.rb', line 30

def initialize(path, name, options = {})
  # The path where the package is (or will be) located:
  @path = Path[path]

  # Get the name of the package from the options, if provided:
  if options[:name]
    @name = options[:name]
  end

  if Symbol === name
    # If the name argument was symbolic, we convert it into a string, and use it for both the uri and the name itself:
    @uri = name.to_s
    @name ||= @uri
  else
    # Otherwise, we assume a path may have been given, and use that instead:
    @name ||= File.basename(name)
    @uri = name
  end
  
  # Copy the options provided:
  @options = options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



62
63
64
# File 'lib/teapot/package.rb', line 62

def name
  @name
end

#optionsObject

Returns the value of attribute options.



66
67
68
# File 'lib/teapot/package.rb', line 66

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



63
64
65
# File 'lib/teapot/package.rb', line 63

def path
  @path
end

#uriObject (readonly)

Returns the value of attribute uri.



65
66
67
# File 'lib/teapot/package.rb', line 65

def uri
  @uri
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/teapot/package.rb', line 100

def eql?(other)
  @path.eql?(other.path)
end

#external?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/teapot/package.rb', line 72

def external?
  @options.key? :source
end

#external_url(relative_root) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'lib/teapot/package.rb', line 80

def external_url(relative_root)
  base_uri = URI(source)

  if base_uri.scheme == nil || base_uri.scheme == 'file'
    base_uri = URI "file://" + File.expand_path(base_uri.path, relative_root) + "/"
  end

  return relative_url(base_uri)
end

#freezeObject



53
54
55
56
57
58
59
60
# File 'lib/teapot/package.rb', line 53

def freeze
  @path.freeze
  @name.freeze
  @uri.freeze
  @options.freeze
  
  super
end

#hashObject

Package may be used as hash key / in a set:



96
97
98
# File 'lib/teapot/package.rb', line 96

def hash
  @path.hash
end

#local?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/teapot/package.rb', line 68

def local?
  @options.key? :local
end

#sourceObject



76
77
78
# File 'lib/teapot/package.rb', line 76

def source
  @options[:source].to_s + '/'
end

#to_sObject



90
91
92
# File 'lib/teapot/package.rb', line 90

def to_s
  "#<#{self.class} #{@name.dump} path=#{path}>"
end