0001-Documentation-for-YAML-Store.patch

Justin Collins, 05/14/2011 06:18 AM

Download (1.78 KB)

View differences:

lib/yaml/store.rb
4 4
require 'yaml'
5 5
require 'pstore'
6 6

  
7
# YAML::Store provides the same functionality as PStore, except it uses YAML
8
# to dump objects instead of Marshal.
9
#
10
# == Example
11
#
12
#  require 'yaml/store'
13
#
14
#  Person = Struct.new :first_name, :last_name
15
#
16
#  people = [Person.new("Bob", "Smith"), Person.new("Mary", "Johnson")]
17
#
18
#  store = YAML::Store.new "test.store"
19
#
20
#  store.transaction do
21
#    store["people"] = people
22
#    store["greeting"] = { "hello" => "world" }
23
#  end
24
#
25
# After running the above code, the contents of "test.store" will be:
26
#
27
#  --- 
28
#  people: 
29
#  - !ruby/struct:Person 
30
#    first_name: Bob
31
#    last_name: Smith
32
#  - !ruby/struct:Person 
33
#    first_name: Mary
34
#    last_name: Johnson
35
#  greeting: 
36
#    hello: world
37
#
7 38
class YAML::Store < PStore
39

  
40
  # :call-seq:
41
  #   initialize( file_name, yaml_opts = {} )
42
  #
43
  # Creates a new YAML::Store object, which will store data in +file_name+.
44
  # If the file does not already exist, it will be created.
45
  #
46
  #
47
  # Options passed in through +yaml_opts+ will be used when converting the
48
  # store to YAML via Hash#to_yaml().
8 49
  def initialize( *o )
9 50
    @opt = {}
10 51
    if String === o.first
......
15 56
    end
16 57
  end
17 58

  
59
  # :stopdoc:
60

  
18 61
  def dump(table)
19 62
    @table.to_yaml(@opt)
20 63
  end
21
-