Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 104 lines (64 sloc) 2.503 kb
a465c458 »
2010-04-04 Release 0.7.1
1 = Storable - v0.7
a18d78d8 »
2009-05-07 Extracted from Rudy
2
d74243f8 »
2009-05-07 Updated README
3 Marshal Ruby classes into and out of multiple formats (yaml, json, csv, tsv)
a18d78d8 »
2009-05-07 Extracted from Rudy
4
6f6579a9 »
2009-05-07 Added example to README
5 == Example
6
7 require 'storable'
8
9 class Machine < Storable
10 field :environment # Define field names for Machine. The
11 field :role # default type is String, but you can
12 field :position => Integer # specify a type using a hash syntax.
13 end
14
15 mac1 = Machine.new # Instances of Machine have accessors
16 mac1.environment = "stage" # just like regular attributes.
17 mac1.role = "app"
18 mac1.position = 1
19
20 puts "# YAML", mac1.to_yaml # Note: the field order is maintained
21 puts "# CSV", mac1.to_csv # => stage,app,1
22 puts "# JSON", mac1.to_json # Note: field order not maintained.
23
24 mac2 = Machine.from_yaml(mac1.to_yaml)
25 puts mac2.environment # => "stage"
26 puts mac2.position.class # => Fixnum
27
c17a6e75 »
2010-07-28 Supports to_a
28 == Sensitive Fields
6f6579a9 »
2009-05-07 Added example to README
29
c17a6e75 »
2010-07-28 Supports to_a
30 require 'storable'
31
32 class Calc < Storable
33 field :one
34 field :two
35 field :three
36 sensitive_fields :three
37 end
38
39 calc = Calc.new 1, 2, 3
40 calc.to_s
41
f13def2f »
2010-04-09 ADDED: Storable#call for calling Proc fields via instance_eval
42 == Storing Procs
43
44 Storable can also marshal Proc objects to and from their actual source code.
45
46 require 'storable'
47
48 class Maths < Storable
87e937b1 »
2010-04-09 Release 0.7.3 (Storable#call, Storable::Anonymous, Range support)
49 field :x => Float
50 field :y => Float
f13def2f »
2010-04-09 ADDED: Storable#call for calling Proc fields via instance_eval
51 field :calculate => Proc
52 end
53
54 mat1 = Maths.new 2.0, 3.0
55 mat1.calculate = Proc.new { @x * @y }
56
57 mat1.calculate.source # => "{ @x * @y }"
58 mat1.call :calculate # => 6.0
59
60 dump = mat1.to_json
61
62 mat2 = Maths.from_json dump
63 mat2.call :calculate # => 6.0
64
c17a6e75 »
2010-07-28 Supports to_a
65
87e937b1 »
2010-04-09 Release 0.7.3 (Storable#call, Storable::Anonymous, Range support)
66 Anything is possible when you keep your mind open and you use Ruby.
67
68
a18d78d8 »
2009-05-07 Extracted from Rudy
69 == Installation
70
71 Via Rubygems, one of:
72
73 $ sudo gem install storable
74 $ sudo gem install delano-storable --source http://gems.github.com/
75
76 or via download:
77 * storable-latest.tar.gz[http://github.com/delano/storable/tarball/latest]
78 * storable-latest.zip[http://github.com/delano/storable/zipball/latest]
79
80
6f6579a9 »
2009-05-07 Added example to README
81 == Prerequisites
82
f13def2f »
2010-04-09 ADDED: Storable#call for calling Proc fields via instance_eval
83 * Ruby 1.8, Ruby 1.9, or JRuby 1.2+
6f6579a9 »
2009-05-07 Added example to README
84
85
2bb23514 »
2010-04-14 Updated readme
86 == Credits
87
88 * Delano Mandelbaum (delano@solutious.com)
89 * lib/proc_source.rb is based on http://github.com/imedo/background
90 * OrderedHash implementation by Jan Molic
91
92
93efb51b »
2009-07-17 Added Thanks to README
93 == Thanks
94
95 * Pierre Riteau (priteau[http://github.com/priteau]) for bug fixes.
96
97
2bb23514 »
2010-04-14 Updated readme
98 == More Info
a18d78d8 »
2009-05-07 Extracted from Rudy
99
2bb23514 »
2010-04-14 Updated readme
100 * Codes[http://github.com/delano/storable]
a18d78d8 »
2009-05-07 Extracted from Rudy
101
102 == License
103
104 See: LICENSE.txt
Something went wrong with that request. Please try again.