Class: Fig::PackageDescriptor
- Inherits:
-
Object
- Object
- Fig::PackageDescriptor
- Includes:
- Comparable
- Defined in:
- lib/fig/package_descriptor.rb
Overview
Parsed representation of a package specification, i.e. “name/version:config”.
Constant Summary collapse
- UNBRACKETED_COMPONENT_PATTERN =
/ (?! [.]{1,2} $) [a-zA-Z0-9_.-]+ /x
- COMPONENT_PATTERN =
/ \A #{UNBRACKETED_COMPONENT_PATTERN} \z /x
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#original_string ⇒ Object
readonly
Returns the value of attribute original_string.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
- .format(name, version, config, use_default_config = false, description = nil) ⇒ Object
- .parse(raw_string, options = {}) ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(name, version, config, options = {}) ⇒ PackageDescriptor
constructor
Options are:.
-
#to_string(use_default_config = false, use_description = false) ⇒ Object
Specifically not named :to_s because it doesn’t act like that should.
Constructor Details
#initialize(name, version, config, options = {}) ⇒ PackageDescriptor
Options are:
:name => { :required | :forbidden }
:version => { :required | :forbidden }
:config => { :required | :forbidden }
:original_string => the unparsed form
:description => meta-information, if this is for a
synthetic package
:require_at_least_one_component => should we have at least one of
name, version, and config
:validation_context => what the descriptor is for
:source_description => where the descriptor came from,
most likely the result of invoking
Fig::Statement.position_description().
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/fig/package_descriptor.rb', line 68 def initialize(name, version, config, = {}) @name = translate_component(name) @version = translate_component(version) @config = translate_component(config) @original_string = [:original_string] @description = [:description] validate_component name, 'name', :name, validate_component version, 'version', :version, validate_component config, 'config', :config, validate_across_components end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/fig/package_descriptor.rb', line 12 def config @config end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
12 13 14 |
# File 'lib/fig/package_descriptor.rb', line 12 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/fig/package_descriptor.rb', line 12 def name @name end |
#original_string ⇒ Object (readonly)
Returns the value of attribute original_string.
12 13 14 |
# File 'lib/fig/package_descriptor.rb', line 12 def original_string @original_string end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
12 13 14 |
# File 'lib/fig/package_descriptor.rb', line 12 def version @version end |
Class Method Details
.format(name, version, config, use_default_config = false, description = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fig/package_descriptor.rb', line 14 def self.format( name, version, config, use_default_config = false, description = nil ) string = name if ! string string = description ? "<#{description}>" : '' end if version string += '/' string += version end if config string += ':' string += config elsif use_default_config string += ':default' end return string end |
.parse(raw_string, options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fig/package_descriptor.rb', line 37 def self.parse(raw_string, = {}) = {} .merge!() [:original_string] = raw_string [:require_at_least_one_component] = true # 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. return 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 |
Instance Method Details
#<=>(other) ⇒ Object
92 93 94 |
# File 'lib/fig/package_descriptor.rb', line 92 def <=>(other) return to_string() <=> other.to_string() end |
#to_string(use_default_config = false, use_description = false) ⇒ Object
Specifically not named :to_s because it doesn’t act like that should.
82 83 84 85 86 87 88 89 90 |
# File 'lib/fig/package_descriptor.rb', line 82 def to_string(use_default_config = false, use_description = false) return Fig::PackageDescriptor.format( @name, @version, @config, use_default_config, use_description ? @description : nil ) end |