Class: Fig::Package
Overview
The parsed representation of a configuration file for a specific version. Contains the statement objects.
Unique identifier for this object: name and version. A different version of the same package will be a separate instance of this class.
Constant Summary collapse
- DEFAULT_CONFIG =
'default'
Instance Attribute Summary collapse
-
#backtrace ⇒ Object
Returns the value of attribute backtrace.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#include_file_base_directory ⇒ Object
readonly
Returns the value of attribute include_file_base_directory.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#runtime_directory ⇒ Object
readonly
Returns the value of attribute runtime_directory.
-
#statements ⇒ Object
readonly
Returns the value of attribute statements.
-
#unparsed_text ⇒ Object
Returns the value of attribute unparsed_text.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #[](config_name) ⇒ Object
- #add_applied_config_name(name) ⇒ Object
- #applied_config_names ⇒ Object
- #archive_locations ⇒ Object
-
#base? ⇒ Boolean
Is this the base package?.
- #config_names ⇒ Object
- #configs ⇒ Object
-
#initialize(name, version, description, runtime_directory, include_file_base_directory, statements, synthetic) ⇒ Package
constructor
A new instance of Package.
-
#package_dependencies(config_name, backtrace) ⇒ Object
Returns an array of PackageDescriptors.
- #primary_config_name ⇒ Object
- #resource_locations ⇒ Object
- #retrieves ⇒ Object
- #set_base(yea_or_nay) ⇒ Object
-
#synthetic? ⇒ Boolean
Was this package (supposedly) created from something other than usual parsing? (Note that some tests artificially create “non-synthetic” instances.).
-
#to_descriptive_string_with_config(config_name) ⇒ Object
Useful for debugging; should not be used for regular output.
- #to_s ⇒ Object
- #to_s_with_config(config_name) ⇒ Object
-
#walk_statements(&block) ⇒ Object
Block will receive a Statement.
Constructor Details
#initialize(name, version, description, runtime_directory, include_file_base_directory, statements, synthetic) ⇒ Package
Returns a new instance of Package.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fig/package.rb', line 32 def initialize( name, version, description, runtime_directory, include_file_base_directory, statements, synthetic ) @name = name @version = version @description = description @runtime_directory = runtime_directory @include_file_base_directory = include_file_base_directory @statements = statements @synthetic = synthetic @applied_config_names = [] @backtrace = nil end |
Instance Attribute Details
#backtrace ⇒ Object
Returns the value of attribute backtrace.
29 30 31 |
# File 'lib/fig/package.rb', line 29 def backtrace @backtrace end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
25 26 27 |
# File 'lib/fig/package.rb', line 25 def description @description end |
#include_file_base_directory ⇒ Object (readonly)
Returns the value of attribute include_file_base_directory.
27 28 29 |
# File 'lib/fig/package.rb', line 27 def include_file_base_directory @include_file_base_directory end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/fig/package.rb', line 23 def name @name end |
#runtime_directory ⇒ Object (readonly)
Returns the value of attribute runtime_directory.
26 27 28 |
# File 'lib/fig/package.rb', line 26 def runtime_directory @runtime_directory end |
#statements ⇒ Object (readonly)
Returns the value of attribute statements.
28 29 30 |
# File 'lib/fig/package.rb', line 28 def statements @statements end |
#unparsed_text ⇒ Object
Returns the value of attribute unparsed_text.
30 31 32 |
# File 'lib/fig/package.rb', line 30 def unparsed_text @unparsed_text end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
24 25 26 |
# File 'lib/fig/package.rb', line 24 def version @version end |
Instance Method Details
#<=>(other) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/fig/package.rb', line 90 def <=>(other) compared = compare_components(name, other.name) return compared if compared != 0 return compare_components(version, other.version) end |
#[](config_name) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/fig/package.rb', line 70 def [](config_name) @statements.each do |stmt| return stmt if stmt.is_a?(Fig::Statement::Configuration) && stmt.name == config_name end descriptor = Fig::PackageDescriptor.new( @name, @version, config_name, :description => @description ) config_description = nil if @name.nil? and @version.nil? config_description = config_name else config_description = descriptor.to_string(:use_default_config) end = %Q<There is no "#{config_description}" config.> raise Fig::NoSuchPackageConfigError.new(, descriptor, self) end |
#add_applied_config_name(name) ⇒ Object
125 126 127 |
# File 'lib/fig/package.rb', line 125 def add_applied_config_name(name) @applied_config_names << name end |
#applied_config_names ⇒ Object
121 122 123 |
# File 'lib/fig/package.rb', line 121 def applied_config_names() return @applied_config_names.clone end |
#archive_locations ⇒ Object
109 110 111 112 113 |
# File 'lib/fig/package.rb', line 109 def archive_locations return @statements. select{|s| s.is_a?(Fig::Statement::Archive)}. map{|s| s.location} end |
#base? ⇒ Boolean
Is this the base package?
60 61 62 |
# File 'lib/fig/package.rb', line 60 def base?() return @base end |
#config_names ⇒ Object
101 102 103 |
# File 'lib/fig/package.rb', line 101 def config_names return configs.collect { |statement| statement.name } end |
#configs ⇒ Object
97 98 99 |
# File 'lib/fig/package.rb', line 97 def configs return @statements.select { |statement| statement.is_a?(Fig::Statement::Configuration) } end |
#package_dependencies(config_name, backtrace) ⇒ Object
Returns an array of PackageDescriptors
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/fig/package.rb', line 134 def package_dependencies(config_name, backtrace) descriptors = [] self[config_name || DEFAULT_CONFIG].walk_statements do |statement| if statement.is_a?(Fig::Statement::Include) descriptors << statement.resolved_dependency_descriptor(self, backtrace) elsif statement.is_a?(Fig::Statement::Override) backtrace.add_override(statement) end end return descriptors end |
#primary_config_name ⇒ Object
129 130 131 |
# File 'lib/fig/package.rb', line 129 def primary_config_name() return @applied_config_names.first end |
#resource_locations ⇒ Object
115 116 117 118 119 |
# File 'lib/fig/package.rb', line 115 def resource_locations return @statements. select{|s| s.is_a?(Fig::Statement::Resource)}. map{|s| s.location} end |
#retrieves ⇒ Object
105 106 107 |
# File 'lib/fig/package.rb', line 105 def retrieves return @statements.select { |statement| statement.is_a?(Fig::Statement::Retrieve) } end |
#set_base(yea_or_nay) ⇒ Object
64 65 66 67 68 |
# File 'lib/fig/package.rb', line 64 def set_base(yea_or_nay) @base = yea_or_nay return end |
#synthetic? ⇒ Boolean
Was this package (supposedly) created from something other than usual parsing? (Note that some tests artificially create “non-synthetic” instances.)
55 56 57 |
# File 'lib/fig/package.rb', line 55 def synthetic? return @synthetic end |
#to_descriptive_string_with_config(config_name) ⇒ Object
Useful for debugging; should not be used for regular output.
174 175 176 177 178 |
# File 'lib/fig/package.rb', line 174 def to_descriptive_string_with_config(config_name) return Fig::PackageDescriptor.format( name, version, config_name, :use_default_config, description ) end |
#to_s ⇒ Object
160 161 162 163 164 |
# File 'lib/fig/package.rb', line 160 def to_s name = @name || UNPUBLISHED version = @version || '<empty>' return Fig::PackageDescriptor.format(name, version, nil) end |
#to_s_with_config(config_name) ⇒ Object
166 167 168 169 170 171 |
# File 'lib/fig/package.rb', line 166 def to_s_with_config(config_name) displayed_config = config_name == DEFAULT_CONFIG ? nil : config_name return Fig::PackageDescriptor.format( name || UNPUBLISHED, version, displayed_config ) end |
#walk_statements(&block) ⇒ Object
Block will receive a Statement.
151 152 153 154 155 156 157 158 |
# File 'lib/fig/package.rb', line 151 def walk_statements(&block) @statements.each do |statement| yield statement statement.walk_statements(&block) end return end |