Skip to content

Commit

Permalink
Converted to Tryouts 2
Browse files Browse the repository at this point in the history
  • Loading branch information
delano committed Jul 28, 2010
1 parent c12e54a commit 6d5b05a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 42 deletions.
5 changes: 3 additions & 2 deletions lib/storable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def postprocess
end

# TODO: from_args([HASH or ordered params])


# Accepts field definitions in the one of the follow formats:
#
Expand Down Expand Up @@ -265,10 +266,10 @@ def to_hash
end
tmp
end

def to_json(*from, &blk)
hash = to_hash
if YAJL_LOADED
if YAJL_LOADED # set by Storable
ret = Yajl::Encoder.encode(hash)
#raise "DELANO"
#ret.force_encoding("ISO-8859-1")
Expand Down
75 changes: 35 additions & 40 deletions try/10_basic_usage_tryouts.rb
Original file line number Diff line number Diff line change
@@ -1,46 +1,41 @@
$:.unshift '/Users/delano/Projects/opensource/storable/lib'
load 'storable.rb'
require 'storable'


class A < Storable
field :one => String
field :two => Integer
field :three => Time
field :four => Boolean
end
class B < Storable
field :one => String
field :two
field :three => Time
end
class C < Storable
field :calc => Proc
end

tryouts "Basic Usage", :api do
setup do
class A < Storable
field :one => String
field :two => Integer
field :three => Time
field :four => Boolean
end
class B < Storable
field :one => String
field :two
field :three => Time
end
class C < Storable
field :calc => Proc
end
end

dream ["string", 1, Time.parse("2010-03-04 23:00"), true]
drill "Storable objects have a default initialize method" do
a = A.new "string", 1, Time.parse("2010-03-04 23:00"), true
[a.one, a.two, a.three, a.four]
end

dream ["string", 1, Time.parse("2010-03-04 23:00")]
drill "Field types are optional" do
b = B.new "string", 1, Time.parse("2010-03-04 23:00")
b = B.from_json b.to_json
[b.one, b.two, b.three]
end

dream 4
drill "Can restore a proc" do
calc = Proc.new do
2+2
end
c = C.new calc
c= C.from_json c.to_json
c.calc.call
end
## "Storable objects have a default initialize method"
a = A.new "string", 1, Time.parse("2010-03-04 23:00"), true
[a.one, a.two, a.three, a.four]
#=> ["string", 1, Time.parse("2010-03-04 23:00"), true]

## "Field types are optional"
b = B.new "string", 1, Time.parse("2010-03-04 23:00")
b = B.from_json b.to_json
[b.one, b.two, b.three]
#=> ["string", 1, Time.parse("2010-03-04 23:00")]

## "Can restore a proc"
calc = Proc.new do
2+2
end
c = C.new calc
c= C.from_json c.to_json
c.calc.call
#=> 4


0 comments on commit 6d5b05a

Please sign in to comment.