Class: Plutil
- Inherits:
-
Object
- Object
- Plutil
- Defined in:
- lib/tm_bundle/plutil.rb
Defined Under Namespace
Modules: JSON
Class Method Summary collapse
-
.call(*args, &block) ⇒ Object
(also: plutil)
Also aliased as ‘Plutil.plutil` Usage:.
-
.convert(path, to: :json, &block) ⇒ Object
Usage:.
- .dump_json(*args) ⇒ Object
-
.load_json(*args) ⇒ Object
Shorthand to ‘Plutil::JSON.load(plist)`.
-
.replace(path, keypath, data, as: :xml, &block) ⇒ Object
Usage:.
Instance Method Summary collapse
- #execute(&block) ⇒ Object
-
#initialize(*args) ⇒ Plutil
constructor
A new instance of Plutil.
- #input_args ⇒ Object
- #output_args ⇒ Object
- #stdin? ⇒ Boolean
Constructor Details
#initialize(*args) ⇒ Plutil
Returns a new instance of Plutil.
74 75 76 77 78 79 80 |
# File 'lib/tm_bundle/plutil.rb', line 74 def initialize(*args) = args. @command, *@args = *args @in, @out, @mode = *.values_at(:in, :out, :mode) @in ||= [:file] @mode ||= auto_mode end |
Class Method Details
.call(*args, &block) ⇒ Object Also known as: plutil
30 31 32 |
# File 'lib/tm_bundle/plutil.rb', line 30 def self.call(*args, &block) new(*args).execute(&block) end |
.convert(path, to: :json, &block) ⇒ Object
52 53 54 55 |
# File 'lib/tm_bundle/plutil.rb', line 52 def self.convert(path, to: :json, &block) to = "xml1" if to.to_s == 'xml' plutil(:convert, to, out: :stdin, file: path.to_s, &block) end |
.dump_json(*args) ⇒ Object
70 71 72 |
# File 'lib/tm_bundle/plutil.rb', line 70 def self.dump_json(*args) Plutil::JSON.dump(*args) end |
.load_json(*args) ⇒ Object
Shorthand to ‘Plutil::JSON.load(plist)`
66 67 68 |
# File 'lib/tm_bundle/plutil.rb', line 66 def self.load_json(*args) Plutil::JSON.load(*args) end |
.replace(path, keypath, data, as: :xml, &block) ⇒ Object
Usage:
Plutil.replace(plist, 'name', data, as: 'xml', &:read)
61 62 63 |
# File 'lib/tm_bundle/plutil.rb', line 61 def self.replace(path, keypath, data, as: :xml, &block) plutil(:replace, keypath, "-#{as}", data, file: path.to_s, &block) end |
Instance Method Details
#execute(&block) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/tm_bundle/plutil.rb', line 82 def execute(&block) io = IO.popen(cmd, @mode) block.call(io) ensure io.close if io && !io.closed? end |
#input_args ⇒ Object
90 |
# File 'lib/tm_bundle/plutil.rb', line 90 def input_args; @in && ['--', normalize_io_arg(@in)]; end |
#output_args ⇒ Object
89 |
# File 'lib/tm_bundle/plutil.rb', line 89 def output_args; @out && ['-o', normalize_io_arg(@out)]; end |
#stdin? ⇒ Boolean
91 |
# File 'lib/tm_bundle/plutil.rb', line 91 def stdin?; @in.to_s == 'stdin'; end |