Class: Packagit::Specification

Inherits:
Object
  • Object
show all
Defined in:
lib/packagit/specification.rb

Constant Summary collapse

REQUIREDS =
[:name, :version]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Specification

Returns a new instance of Specification.

Yields:

  • (_self)

Yield Parameters:



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/packagit/specification.rb', line 10

def initialize(&block)
  unless block_given?
    raise ArgumentError, "Block must be given"
  end
  yield(self)
  for required in REQUIREDS
    if self.send(required).blank?
      raise ArgumentError, "#{required} must be given (#{self.class.name})"
    end
  end
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



6
7
8
# File 'lib/packagit/specification.rb', line 6

def files
  @files
end

#loaded_fromObject

Returns the value of attribute loaded_from.



6
7
8
# File 'lib/packagit/specification.rb', line 6

def loaded_from
  @loaded_from
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/packagit/specification.rb', line 6

def name
  @name
end

#versionObject

Returns the value of attribute version.



6
7
8
# File 'lib/packagit/specification.rb', line 6

def version
  @version
end

Class Method Details

.load(file) ⇒ Object

Widely inspired from rubygems



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/packagit/specification.rb', line 24

def self.load(file)
  code = if defined? Encoding
           File.read(file, :mode => 'r:UTF-8:-')
         else
           File.read(file)
         end
  
  code.untaint

  begin
    spec = eval(code, binding, file.to_s)

    if Packagit::Specification === spec
      spec.loaded_from = File.expand_path file.to_s
      return spec
    end
    
    warn "[#{file}] isn't a Packagit::Specification (#{spec.class} instead)."
  rescue SignalException, SystemExit
    raise
  rescue SyntaxError, Exception => e
    warn "Invalid packagit in [#{file}]: #{e}"
  end
  
  return nil
end