plist4r 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.1.2
@@ -27,6 +27,10 @@ module Plist4r
27
27
  @hash
28
28
  end
29
29
 
30
+ def to_hash
31
+ @hash
32
+ end
33
+
30
34
  # Select (keep) plist keys from the object.
31
35
  # Copy them to the resultant object moving forward.
32
36
  # @param [Array, *args] keys The list of Plist Keys to keep
@@ -23,6 +23,7 @@ module Plist4r
23
23
  :hash_of_arrays => [Hash],
24
24
  :hash_of_arrays_of_strings => [Hash],
25
25
  :hash => [Hash],
26
+ :bool_or_hash_of_bools => [TrueClass,FalseClass,Hash],
26
27
  :bool_or_string_or_array_of_strings => [TrueClass,FalseClass,String,Array]
27
28
  }
28
29
 
@@ -181,6 +181,20 @@ class String
181
181
  @blob
182
182
  end
183
183
 
184
+ # Remove the leading spaces of the first line, and same to all lines of a multiline string.
185
+ # This effectively shifts all the lines across to the left, until the first line hits the
186
+ # left margin.
187
+ # @example
188
+ # def usage; <<-EOS.undent
189
+ # # leading indent
190
+ # # subsequent indent
191
+ # # subsequent indent + ' '
192
+ # EOS
193
+ # end
194
+ def undent
195
+ gsub /^.{#{slice(/^ +/).length}}/, ''
196
+ end
197
+
184
198
  # A Camel-ized string. The reverse of {#snake_case}
185
199
  # @example
186
200
  # "my_plist_key".camelcase => "MyPlistKey"
data/lib/plist4r/plist.rb CHANGED
@@ -323,7 +323,7 @@ module Plist4r
323
323
  # p_f_release_version(new_ver)
324
324
  # end
325
325
  def edit *args, &blk
326
- @plist_type.hash @hash
326
+ @plist_type.to_hash @hash
327
327
  instance_eval *args, &blk
328
328
  detect_plist_type if plist_type == :plist
329
329
  end
@@ -335,7 +335,7 @@ module Plist4r
335
335
  # @see Plist4r::DataMethods#method_missing
336
336
  # @see #plist_type
337
337
  def method_missing method_sym, *args, &blk
338
- @plist_type.method_missing method_sym, *args, &blk
338
+ eval "@plist_type.#{method_sym} *args, &blk"
339
339
  end
340
340
 
341
341
  # Backend method to set or return all new plist data resulting from a backend API. Used in load operations.
@@ -467,7 +467,7 @@ module Plist4r
467
467
  def delete_if *keys, &blk
468
468
  delete *keys
469
469
  @hash.delete_if &blk
470
- @plist_type.hash @hash
470
+ @plist_type.to_hash @hash
471
471
  end
472
472
 
473
473
  # Clears all plist keys and their contents
@@ -485,7 +485,7 @@ module Plist4r
485
485
  def merge! other_plist
486
486
  if plist_type == other_plist.plist_type
487
487
  @hash.merge! other_plist.to_hash
488
- @plist_type.hash @hash
488
+ @plist_type.to_hash @hash
489
489
  else
490
490
  raise "plist_type differs, one is #{plist_type.inspect}, and the other is #{plist.plist_type.inspect}"
491
491
  end
@@ -17,7 +17,7 @@ module Plist4r
17
17
  # Set or return the plist's raw data object
18
18
  # @param [Plist4r::OrderedHash] hash Set the hash if not nil
19
19
  # @return [Plist4r::OrderedHash] @hash
20
- def hash hash=nil
20
+ def to_hash hash=nil
21
21
  case hash
22
22
  when ::Plist4r::OrderedHash
23
23
  @hash = @orig = hash
@@ -65,8 +65,8 @@ module Plist4r
65
65
  def array_dict method_sym, *args
66
66
  a = ArrayDict.new @hash
67
67
  result = eval "a.#{method_sym} *args"
68
- @hash = @orig = a.hash
69
- @plist.import_hash a.hash
68
+ @hash = @orig = a.to_hash
69
+ @plist.import_hash a.to_hash
70
70
  end
71
71
  end
72
72
  end
@@ -61,7 +61,7 @@ module Plist4r
61
61
  ValidKeys =
62
62
  {
63
63
  :bool => %w[SuccessfulExit NetworkState],
64
- :hash_of_bools => %w[PathState OtherJobEnabled]
64
+ :bool_or_hash_of_bools => %w[PathState OtherJobEnabled]
65
65
  }
66
66
  end
67
67
 
@@ -115,12 +115,13 @@ module Plist4r
115
115
  key = "KeepAlive"
116
116
 
117
117
  case value
118
- when TrueCass, FalseClass
118
+ when TrueClass, FalseClass
119
119
  @hash[key] = value
120
120
  when nil
121
- if blk
122
- @hash[key] ||= ::Plist4r::OrderedHash.new
123
- @hash[key] = ::LaunchdPlistStructs::KeepAlive.new(@hash[key],&blk).hash
121
+ if block_given?
122
+ puts KeepAlive.new(@hash[key],&blk).to_hash
123
+ @hash[key] = ::Plist4r::OrderedHash.new
124
+ @hash[key] = KeepAlive.new(@hash[key],&blk).to_hash
124
125
  else
125
126
  @hash[key]
126
127
  end
@@ -221,7 +222,7 @@ module Plist4r
221
222
  end
222
223
  if blk
223
224
  @hash[key] ||= []
224
- h = ::LaunchdPlistStructs::StartCalendarInterval.new(@hash[key],index,&blk).hash
225
+ h = StartCalendarInterval.new(@hash[key],index,&blk).to_hash
225
226
  if index
226
227
  @hash[key][index] = h
227
228
  else
@@ -296,7 +297,7 @@ module Plist4r
296
297
  key = "SoftResourceLimits"
297
298
  if blk
298
299
  @hash[key] ||= ::Plist4r::OrderedHash.new
299
- @hash[key] = ::LaunchdPlistStructs::ResourceLimits.new(@hash[key],&blk).hash
300
+ @hash[key] = ResourceLimits.new(@hash[key],&blk).to_hash
300
301
  else
301
302
  @hash[key]
302
303
  end
@@ -361,7 +362,7 @@ module Plist4r
361
362
  key = "HardResourceLimits"
362
363
  if blk
363
364
  @hash[key] ||= ::Plist4r::OrderedHash.new
364
- @hash[key] = ::LaunchdPlistStructs::ResourceLimits.new(@hash[key],&blk).hash
365
+ @hash[key] = ResourceLimits.new(@hash[key],&blk).to_hash
365
366
  else
366
367
  @hash[key]
367
368
  end
@@ -378,7 +379,7 @@ module Plist4r
378
379
  set_or_return_of_type :bool, service, value
379
380
  elsif blk
380
381
  @hash[service] = ::Plist4r::OrderedHash.new
381
- @hash[service] = ::LaunchdPlistStructs::MachServices::MachService.new(@hash[service],&blk).hash
382
+ @hash[service] = MachServices::MachService.new(@hash[service],&blk).to_hash
382
383
  else
383
384
  @orig
384
385
  end
@@ -428,7 +429,7 @@ module Plist4r
428
429
  key = "MachServices"
429
430
  if blk
430
431
  @hash[key] ||= ::Plist4r::OrderedHash.new
431
- @hash[key] = ::LaunchdPlistStructs::MachServices.new(@hash[key],&blk).hash
432
+ @hash[key] = MachServices.new(@hash[key],&blk).to_hash
432
433
  else
433
434
  @hash[key]
434
435
  end
@@ -450,13 +451,13 @@ module Plist4r
450
451
  end
451
452
 
452
453
  def add_socket_to_dictionary key, &blk
453
- @hash[key] = ::LaunchdPlistStructs::Sockets::Socket.new(@hash[key],&blk).hash
454
+ @hash[key] = Sockets::Socket.new(@hash[key],&blk).to_hash
454
455
  end
455
456
 
456
457
  def add_socket_to_array key, index, &blk
457
458
  @orig[key] = [] unless @orig[key].class == Array
458
459
  @hash[key] ||= []
459
- @hash[key][index] = ::LaunchdPlistStructs::Sockets::Socket.new(@orig[key],index,&blk).hash
460
+ @hash[key][index] = Sockets::Socket.new(@orig[key],index,&blk).to_hash
460
461
  end
461
462
 
462
463
  def add_socket plicity, key, index=nil, &blk
@@ -661,7 +662,7 @@ module Plist4r
661
662
  key = "Sockets"
662
663
  if blk
663
664
  @hash[key] ||= ::Plist4r::OrderedHash.new
664
- sockets = ::LaunchdPlistStructs::Sockets.new(@hash[key]).hash
665
+ sockets = Sockets.new(@hash[key]).to_hash
665
666
 
666
667
  case index_or_key
667
668
  when nil
data/plist4r.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{plist4r}
8
- s.version = "1.1.1"
8
+ s.version = "1.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["dreamcat4"]
12
- s.date = %q{2010-08-02}
12
+ s.date = %q{2010-08-18}
13
13
  s.default_executable = %q{plist4r}
14
14
  s.description = %q{Plist4r is for editing Plist files in an easy-to-use, fast, and reliabile way. A comprehensive and fully featured Ruby library. Xml and Binary file formats are supported, with backends for Linux and Mac.}
15
15
  s.email = %q{dreamcat4@gmail.com}
@@ -30,7 +30,7 @@ describe Plist4r::ArrayDict, "#hash" do
30
30
 
31
31
  it "should return @hash" do
32
32
  @array_dict.instance_eval { @hash = "hash" }
33
- @array_dict.hash.should == "hash"
33
+ @array_dict.to_hash.should == "hash"
34
34
  end
35
35
  end
36
36
 
@@ -389,10 +389,10 @@ describe Plist4r::Plist, "#method_missing" do
389
389
  @plist = Plist4r::Plist.new
390
390
  end
391
391
 
392
- it "should call @plist_type.send with the supplied arguments" do
393
- method_missing_args = [:method_sym, :arg1, :arg2, :etc]
394
- @plist_type.should_receive(:method_missing).with(method_missing_args)
395
- @plist.method_missing(method_missing_args)
392
+ it "should call eval with @plist_type.#{:method_sym} and the supplied arguments" do
393
+ method_missing_args = [:arg1, :arg2, :etc]
394
+ @plist_type.should_receive(:method_sym).with(*method_missing_args)
395
+ @plist.method_missing(:method_sym,*method_missing_args)
396
396
  end
397
397
  end
398
398
 
@@ -627,8 +627,8 @@ describe Plist4r::Plist, "#delete_if" do
627
627
  @plist.delete_if :arg1, :arg2
628
628
  end
629
629
 
630
- it "should call @plist_type.hash with @hash" do
631
- @plist_type.should_receive(:hash).with(@hash)
630
+ it "should call @plist_type.to_hash with @hash" do
631
+ @plist_type.should_receive(:to_hash).with(@hash)
632
632
  @plist.delete_if :arg1, :arg2
633
633
  end
634
634
  end
@@ -675,7 +675,7 @@ describe Plist4r::Plist, "#merge!" do
675
675
  @plist.stub!(:plist_type).and_return(:plist_type)
676
676
  @other_plist.stub!(:plist_type).and_return(:plist_type)
677
677
  @hash.should_receive(:merge!).with(@other_hash)
678
- @plist_type.should_receive(:hash).with(@hash)
678
+ @plist_type.should_receive(:to_hash).with(@hash)
679
679
 
680
680
  @plist.merge! @other_plist
681
681
  end
@@ -26,18 +26,18 @@ describe Plist4r::PlistType, "#hash" do
26
26
 
27
27
  it "should set @hash and @orig if the supplied hash is a Plist4r::OrderedHash" do
28
28
  hash = Plist4r::OrderedHash.new
29
- @plist_type.hash(hash)
29
+ @plist_type.to_hash(hash)
30
30
  @plist_type.instance_eval { @hash }.should == hash
31
31
  @plist_type.instance_eval { @orig }.should == hash
32
32
  end
33
33
 
34
34
  it "should return @hash if there are no supplied arguments" do
35
- @plist_type.hash.should == "hash"
35
+ @plist_type.to_hash.should == "hash"
36
36
  end
37
37
 
38
38
  it "should raise an error when the supplied argument is not a Plist4r::OrderedHash, or nil" do
39
39
  not_a_plist4r_ordered_hash_or_nil = false
40
- lambda { @plist_type.hash(not_a_plist4r_ordered_hash_or_nil) }.should raise_error(Exception)
40
+ lambda { @plist_type.to_hash(not_a_plist4r_ordered_hash_or_nil) }.should raise_error(Exception)
41
41
  end
42
42
  end
43
43
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 1
8
- - 1
9
- version: 1.1.1
8
+ - 2
9
+ version: 1.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - dreamcat4
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-02 00:00:00 +01:00
17
+ date: 2010-08-18 00:00:00 +01:00
18
18
  default_executable: plist4r
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency