Class: Packagit::Specification
- Inherits:
-
Object
- Object
- Packagit::Specification
- Defined in:
- lib/packagit/specification.rb
Constant Summary collapse
- REQUIREDS =
[:name, :version]
Instance Attribute Summary collapse
-
#files ⇒ Object
Returns the value of attribute files.
-
#loaded_from ⇒ Object
Returns the value of attribute loaded_from.
-
#name ⇒ Object
Returns the value of attribute name.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
-
.load(file) ⇒ Object
Widely inspired from rubygems.
Instance Method Summary collapse
-
#initialize {|_self| ... } ⇒ Specification
constructor
A new instance of Specification.
Constructor Details
#initialize {|_self| ... } ⇒ Specification
Returns a new instance of Specification.
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
#files ⇒ Object
Returns the value of attribute files.
6 7 8 |
# File 'lib/packagit/specification.rb', line 6 def files @files end |
#loaded_from ⇒ Object
Returns the value of attribute loaded_from.
6 7 8 |
# File 'lib/packagit/specification.rb', line 6 def loaded_from @loaded_from end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/packagit/specification.rb', line 6 def name @name end |
#version ⇒ Object
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. 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 |