Sha256: 9071716727854490eb39bc995b78f2277733b6b742d5e534cc16a4b19340fef6
Contents?: true
Size: 1.61 KB
Versions: 2
Compression:
Stored size: 1.61 KB
Contents
module Fig; end # Parsed representation of a package (name/version:config). class Fig::PackageDescriptor include Comparable attr_reader :name, :version, :config def self.format(name, version, config, use_default_config = false) string = name || '' if version string += '/' string += version end if config string += ':' string += config elsif use_default_config string += ':default' end return string end def self.parse(raw_string) # Additional checks in validate_component() will take care of the looseness # of the regexes. These just need to ensure that the entire string gets # assigned to one component or another. self.new( raw_string =~ %r< \A ( [^:/]+ ) >x ? $1 : nil, raw_string =~ %r< \A [^/]* / ( [^:]+ ) >x ? $1 : nil, raw_string =~ %r< \A [^:]* : ( .+ ) \z >x ? $1 : nil ) end def initialize(name, version, config) validate_component name, 'name' validate_component version, 'version' validate_component config, 'config' @name = name @version = version @config = config end def validate_component(value, name) return if value.nil? return if value =~ / \A [a-zA-Z0-9_.-]+ \z /x raise %Q<Invalid #{name} for package descriptor: "#{value}".> end # Specifically not named :to_s because it doesn't act like that should. def to_string(use_default_config = false) return Fig::PackageDescriptor.format( @name, @version, @config, use_default_config ) end def <=>(other) return to_string() <=> other.to_string() end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
fig-0.1.62 | lib/fig/packagedescriptor.rb |
fig-0.1.61 | lib/fig/packagedescriptor.rb |