Sha256: 21b7ea5b65cfc9e16c840b006665bc055aa73aeab23165b2be70919429e1fdfe

Contents?: true

Size: 1.4 KB

Versions: 19

Compression:

Stored size: 1.4 KB

Contents

require "json"

module VagrantPlugins
  module CommandPlugin
    # This is a helper to deal with the plugin state file that Vagrant
    # uses to track what plugins are installed and activated and such.
    class StateFile
      def initialize(path)
        @path = path

        @data = {}
        @data = JSON.parse(@path.read) if @path.exist?
        @data["installed"] ||= []
      end

      # Add a plugin that is installed to the state file.
      #
      # @param [String] name The name of the plugin
      def add_plugin(name)
        if !@data["installed"].include?(name)
          @data["installed"] << name
        end

        save!
      end

      # This returns a list of installed plugins according to the state
      # file. Note that this may _not_ directly match over to actually
      # installed gems.
      #
      # @return [Array<String>]
      def installed_plugins
        @data["installed"]
      end

      # Remove a plugin that is installed from the state file.
      #
      # @param [String] name The name of the plugin.
      def remove_plugin(name)
        @data["installed"].delete(name)
        save!
      end

      # This saves the state back into the state file.
      def save!
        # Scrub some fields
        @data["installed"].sort!
        @data["installed"].uniq!

        # Save
        @path.open("w+") do |f|
          f.write(JSON.dump(@data))
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 6 rubygems

Version Path
tamtam-vagrant-reload-1.1.3 vendor/cache/vagrant-0ac2a8738841/plugins/commands/plugin/state_file.rb
tamtam-vagrant-reload-1.1.2 vendor/cache/vagrant-0ac2a8738841/plugins/commands/plugin/state_file.rb
tamtam-vagrant-reload-1.1.1 vendor/cache/vagrant-0ac2a8738841/plugins/commands/plugin/state_file.rb
tamtam-vagrant-reload-1.1 vendor/cache/vagrant-0ac2a8738841/plugins/commands/plugin/state_file.rb
tnargav-1.3.6 plugins/commands/plugin/state_file.rb
tnargav-1.3.3 plugins/commands/plugin/state_file.rb
vagrant-shell-0.2.9 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/plugins/commands/plugin/state_file.rb
tnargav-1.2.3 plugins/commands/plugin/state_file.rb
vagrant-shell-0.2.8 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/plugins/commands/plugin/state_file.rb
vagrant-shell-0.2.6 vendor/bundle/gems/tnargav-1.2.2/plugins/commands/plugin/state_file.rb
vagrant-shell-0.2.5 vendor/bundle/gems/tnargav-1.2.2/plugins/commands/plugin/state_file.rb
tnargav-1.2.2 plugins/commands/plugin/state_file.rb
vagrantup-1.1.3 plugins/commands/plugin/state_file.rb
vagrantup-1.1.2 plugins/commands/plugin/state_file.rb
vagrantup-1.1.1 plugins/commands/plugin/state_file.rb
vagrantup-1.1.0 plugins/commands/plugin/state_file.rb
vagrantup-1.1.4 plugins/commands/plugin/state_file.rb
vagrant-actionio-0.0.9 vendor/bundle/bundler/gems/vagrant-c74251a1d9c0/plugins/commands/plugin/state_file.rb
vagrant-lxc-0.0.1 vendor/vagrant/plugins/commands/plugin/state_file.rb