Class: UpmSupport::Upbring
- Inherits:
-
Object
- Object
- UpmSupport::Upbring
- Includes:
- REXML
- Defined in:
- lib/upm_support/uplift.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path) ⇒ Upbring
constructor
A new instance of Upbring.
- #installed_package(name) ⇒ Object
- #installed_packages ⇒ Object
- #remove_package(name) ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(path) ⇒ Upbring
Returns a new instance of Upbring.
58 59 60 61 62 63 64 65 |
# File 'lib/upm_support/uplift.rb', line 58 def initialize(path) @path = path @doc = File.open(path) do |f| REXML::Document.new f rescue => e raise "Unable to open your Upbring file in #{@path}. You might need to clean your project, #{e}" end end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
56 57 58 |
# File 'lib/upm_support/uplift.rb', line 56 def path @path end |
Instance Method Details
#installed_package(name) ⇒ Object
78 79 80 |
# File 'lib/upm_support/uplift.rb', line 78 def installed_package(name) installed_packages.select { |ip| ip.name == name }.first end |
#installed_packages ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/upm_support/uplift.rb', line 67 def installed_packages install_specs = XPath.match(@doc.root, '/Upbring/InstalledPackage').map do |ip| name = ip['Name'] version = ip['Version'] install_specs = XPath.match(ip, './Install').map do |e| InstallSpec.new(type: e['Type'], path: e['Path'], guid: e['Guid']) end InstalledPackage.new(name, version, install_specs) end end |
#remove_package(name) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/upm_support/uplift.rb', line 82 def remove_package(name) upbring_elt = XPath.match(@doc.root, '/Upbring') elt_to_remove = XPath.match(upbring_elt, "./InstalledPackage[@Name='#{name}']") return nil unless elt_to_remove.count.positive? upbring_elt.first.delete(elt_to_remove.first) end |
#save ⇒ Object
90 91 92 93 94 |
# File 'lib/upm_support/uplift.rb', line 90 def save File.open(@path, 'w') do |f| @doc.write(f) end end |