Class: Inspec::Lockfile
- Inherits:
-
Object
- Object
- Inspec::Lockfile
- Defined in:
- lib/inspec/dependencies/lockfile.rb
Constant Summary collapse
- MINIMUM_SUPPORTED_VERSION =
When we finalize this feature, we should set these to 1
0
- CURRENT_LOCKFILE_VERSION =
0
Instance Attribute Summary collapse
-
#deps ⇒ Object
readonly
Returns the value of attribute deps.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
- .from_dependency_set(dep_set) ⇒ Object
- .from_file(path) ⇒ Object
- .validate_lockfile_version!(version) ⇒ Object
Instance Method Summary collapse
-
#initialize(lockfile_content_hash) ⇒ Lockfile
constructor
A new instance of Lockfile.
- #to_yaml ⇒ Object
Constructor Details
#initialize(lockfile_content_hash) ⇒ Lockfile
Returns a new instance of Lockfile.
56 57 58 59 60 |
# File 'lib/inspec/dependencies/lockfile.rb', line 56 def initialize(lockfile_content_hash) version = lockfile_content_hash['lockfile_version'] @version = version.to_i parse_content_hash(lockfile_content_hash) end |
Instance Attribute Details
#deps ⇒ Object (readonly)
Returns the value of attribute deps.
55 56 57 |
# File 'lib/inspec/dependencies/lockfile.rb', line 55 def deps @deps end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
55 56 57 |
# File 'lib/inspec/dependencies/lockfile.rb', line 55 def version @version end |
Class Method Details
.from_dependency_set(dep_set) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/inspec/dependencies/lockfile.rb', line 10 def self.from_dependency_set(dep_set) lockfile_content = { 'lockfile_version' => CURRENT_LOCKFILE_VERSION, 'depends' => dep_set.to_array, } new(lockfile_content) end |
.from_file(path) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/inspec/dependencies/lockfile.rb', line 18 def self.from_file(path) parsed_content = YAML.load(File.read(path)) version = parsed_content['lockfile_version'] fail "No lockfile_version set in #{path}!" if version.nil? validate_lockfile_version!(version.to_i) new(parsed_content) end |
.validate_lockfile_version!(version) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/inspec/dependencies/lockfile.rb', line 26 def self.validate_lockfile_version!(version) if version < MINIMUM_SUPPORTED_VERSION fail <<EOF This lockfile specifies a lockfile_version of #{version} which is lower than the minimum supported version #{MINIMUM_SUPPORTED_VERSION}. Please create a new lockfile for this project by running: inspec vendor EOF elsif version == 0 # Remove this case once this feature stablizes $stderr.puts <<EOF WARNING: This is a version 0 lockfile. Thank you for trying the experimental dependency management feature. Please be aware you may need to regenerate this lockfile in future versions as the feature is currently in development. EOF elsif version > CURRENT_LOCKFILE_VERSION fail <<EOF This lockfile claims to be version #{version} which is greater than the most recent lockfile version(#{CURRENT_LOCKFILE_VERSION}). This may happen if you are using an older version of inspec than was used to create the lockfile. EOF end end |
Instance Method Details
#to_yaml ⇒ Object
62 63 64 65 66 67 |
# File 'lib/inspec/dependencies/lockfile.rb', line 62 def to_yaml { 'lockfile_version' => CURRENT_LOCKFILE_VERSION, 'depends' => @deps, }.to_yaml end |