Class: Vim::Flavor::LockFile

Inherits:
Object
  • Object
show all
Defined in:
lib/vim-flavor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ LockFile

Returns a new instance of LockFile.



242
243
244
245
# File 'lib/vim-flavor.rb', line 242

def initialize(path)
  @flavors = {}  # repo_uri => flavor
  @path = path
end

Instance Attribute Details

#flavorsObject (readonly)

TODO: Resolve dependencies recursively.



240
241
242
# File 'lib/vim-flavor.rb', line 240

def flavors
  @flavors
end

#pathObject (readonly)

TODO: Resolve dependencies recursively.



240
241
242
# File 'lib/vim-flavor.rb', line 240

def path
  @path
end

Class Method Details

.flavors_from_poro(poro) ⇒ Object



281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/vim-flavor.rb', line 281

def self.flavors_from_poro(poro)
  Hash[
    poro.to_a().map {|repo_uri, h|
      f = Flavor.new()
      f.groups = h[:groups]
      f.locked_version = Gem::Version.create(h[:locked_version])
      f.repo_name = h[:repo_name]
      f.repo_uri = repo_uri
      f.version_contraint = VersionConstraint.new(h[:version_contraint])
      [f.repo_uri, f]
    }
  ]
end

.poro_from_flavors(flavors) ⇒ Object



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/vim-flavor.rb', line 265

def self.poro_from_flavors(flavors)
  Hash[
    flavors.values.map {|f|
      [
        f.repo_uri,
        {
          :groups => f.groups,
          :locked_version => f.locked_version.to_s(),
          :repo_name => f.repo_name,
          :version_contraint => f.version_contraint.to_s(),
        }
      ]
    }
  ]
end

Instance Method Details

#loadObject



247
248
249
250
251
252
253
# File 'lib/vim-flavor.rb', line 247

def load()
  h = File.open(@path, 'rb') do |f|
    YAML.load(f.read())
  end

  @flavors = self.class.flavors_from_poro(h[:flavors])
end

#saveObject



255
256
257
258
259
260
261
262
263
# File 'lib/vim-flavor.rb', line 255

def save()
  h = {}

  h[:flavors] = self.class.poro_from_flavors(@flavors)

  File.open(@path, 'wb') do |f|
    YAML.dump(h, f)
  end
end