Class: Plist4r::PlistCache
Instance Method Summary collapse
- #from_string ⇒ Object
-
#initialize(plist, *args, &blk) ⇒ PlistCache
constructor
A new instance of PlistCache.
- #needs_update_for(fmt) ⇒ Object
- #open ⇒ Object
- #save ⇒ Object
- #to_binary ⇒ Object
- #to_gnustep ⇒ Object
- #to_xml ⇒ Object
- #update_checksum_for(fmt) ⇒ Object
Constructor Details
#initialize(plist, *args, &blk) ⇒ PlistCache
Returns a new instance of PlistCache.
7 8 9 10 11 |
# File 'lib/plist4r/plist_cache.rb', line 7 def initialize plist, *args, &blk @checksum = {} @plist = plist @backend = Backend.new plist, *args, &blk end |
Instance Method Details
#from_string ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/plist4r/plist_cache.rb', line 13 def from_string if @from_string == @plist.from_string unless @from_string_plist_type == @plist.plist_type @from_string_plist_type = @plist.detect_plist_type end unless @from_string_file_format == @plist.file_format @plist.file_format @from_string_file_format end else @backend.call :from_string @from_string = @plist.from_string @from_string_file_format = @plist.file_format @plist.detect_plist_type unless @from_string_plist_type == @plist.plist_type @from_string_plist_type = @plist.plist_type end end @plist end |
#needs_update_for(fmt) ⇒ Object
38 39 40 |
# File 'lib/plist4r/plist_cache.rb', line 38 def needs_update_for fmt @checksum[fmt] != @plist.to_hash.hash end |
#open ⇒ Object
66 67 68 69 |
# File 'lib/plist4r/plist_cache.rb', line 66 def open @backend.call :open @plist end |
#save ⇒ Object
71 72 73 74 |
# File 'lib/plist4r/plist_cache.rb', line 71 def save @backend.call :save @plist.filename_path end |
#to_binary ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/plist4r/plist_cache.rb', line 50 def to_binary if needs_update_for(:binary) || @binary.nil? @binary = @backend.call :to_binary update_checksum_for(:binary) end @binary end |
#to_gnustep ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/plist4r/plist_cache.rb', line 58 def to_gnustep if needs_update_for(:gnustep) || @gnustep.nil? @gnustep = @backend.call :to_gnustep update_checksum_for(:gnustep) end @gnustep end |
#to_xml ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/plist4r/plist_cache.rb', line 42 def to_xml if needs_update_for(:xml) || @xml.nil? @xml = @backend.call :to_xml update_checksum_for(:xml) end @xml end |
#update_checksum_for(fmt) ⇒ Object
34 35 36 |
# File 'lib/plist4r/plist_cache.rb', line 34 def update_checksum_for fmt @checksum[fmt] = @plist.to_hash.hash end |