doodle 0.0.6 → 0.0.7
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/ChangeLog +12 -0
- data/examples/src/sequel_core-1.3/lib/sequel_core/exceptions.rb +48 -0
- data/lib/doodle.rb +44 -23
- data/lib/molic_orderedhash.rb +2 -2
- data/spec/class_spec.rb +4 -4
- data/spec/defaults_spec.rb +8 -8
- data/spec/doodle_spec.rb +20 -39
- metadata +3 -2
data/ChangeLog
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
= ChangeLog for doodle
|
2
2
|
|
3
|
+
== 0.0.7 / 2008-03-22
|
4
|
+
|
5
|
+
- return self from validate! (so you can use idiom foo = YAML::load(yaml).validate!)
|
6
|
+
|
7
|
+
- fix normalization of keys to symbols in initialize_from_hash
|
8
|
+
|
9
|
+
- fix error not allowing nils in :init clause (because can't clone nil)
|
10
|
+
|
11
|
+
- allow more than one class in from clause (e.g. from String, Symbol do ... end)
|
12
|
+
|
13
|
+
- removed :meta as alias for :singleton_class (conflicts with openuri, facets, etc.)
|
14
|
+
|
3
15
|
== 0.0.6 / 2008-03-16
|
4
16
|
|
5
17
|
- fixed Rakefile error (wasn't including examples in rdoc)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Sequel
|
2
|
+
# Represents an error raised in Sequel code.
|
3
|
+
class Error < StandardError
|
4
|
+
|
5
|
+
# Error raised when an invalid statement is executed.
|
6
|
+
class InvalidStatement < Error; end
|
7
|
+
|
8
|
+
# Rollback is a special error used to rollback a transactions.
|
9
|
+
# A transaction block will catch this error and wont pass further up the stack.
|
10
|
+
class Rollback < Error ; end
|
11
|
+
|
12
|
+
# Represents an invalid value stored in the database.
|
13
|
+
class InvalidValue < Error ; end
|
14
|
+
|
15
|
+
# Represents an Invalid transform.
|
16
|
+
class InvalidTransform < Error ; end
|
17
|
+
|
18
|
+
# Represents an Invalid filter.
|
19
|
+
class InvalidFilter < Error ; end
|
20
|
+
|
21
|
+
class InvalidExpression < Error; end
|
22
|
+
|
23
|
+
# Represents an attempt to performing filter operations when no filter has been specified yet.
|
24
|
+
class NoExistingFilter < Error ; end
|
25
|
+
|
26
|
+
# Represents an invalid join type.
|
27
|
+
class InvalidJoinType < Error ; end
|
28
|
+
|
29
|
+
class WorkerStop < RuntimeError ; end
|
30
|
+
|
31
|
+
# Raised when Sequel is unable to load a specified adapter.
|
32
|
+
class AdapterNotFound < Error ; end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Object extensions
|
37
|
+
class Object
|
38
|
+
# Cancels the current transaction without an error:
|
39
|
+
#
|
40
|
+
# DB.tranaction do
|
41
|
+
# ...
|
42
|
+
# rollback! if failed_to_contact_client
|
43
|
+
# ...
|
44
|
+
# end
|
45
|
+
def rollback!
|
46
|
+
raise Sequel::Error::Rollback
|
47
|
+
end
|
48
|
+
end
|
data/lib/doodle.rb
CHANGED
@@ -50,10 +50,7 @@ module Doodle
|
|
50
50
|
# provides more direct access to the singleton class and a way to
|
51
51
|
# treat Modules and Classes equally in a meta context
|
52
52
|
module SelfClass
|
53
|
-
|
54
|
-
def self_class
|
55
|
-
self.kind_of?(Module) ? self : singleton_class
|
56
|
-
end
|
53
|
+
|
57
54
|
# return the 'singleton class' of an object, optionally executing
|
58
55
|
# a block argument in the (module/class) context of that object
|
59
56
|
def singleton_class(&block)
|
@@ -61,10 +58,15 @@ module Doodle
|
|
61
58
|
sc.module_eval(&block) if block_given?
|
62
59
|
sc
|
63
60
|
end
|
64
|
-
|
65
|
-
|
61
|
+
|
62
|
+
# return self if a Module, else the singleton class
|
63
|
+
def self_class
|
64
|
+
self.kind_of?(Module) ? self : singleton_class
|
65
|
+
end
|
66
|
+
|
67
|
+
# frankly a hack to allow init options to work for singleton classes
|
66
68
|
def class_init(params = {}, &block)
|
67
|
-
sc = singleton_class
|
69
|
+
sc = singleton_class(&block)
|
68
70
|
sc.attributes.select{|n, a| a.init_defined? }.each do |n, a|
|
69
71
|
send(n, a.init)
|
70
72
|
end
|
@@ -116,8 +118,8 @@ module Doodle
|
|
116
118
|
if cap = self.to_s.match(regex)
|
117
119
|
if cap.captures.size > 0
|
118
120
|
k = const_get(cap[1])
|
119
|
-
if k.respond_to?(:superclass) && k.superclass.respond_to?(:
|
120
|
-
klasses.unshift k.superclass.
|
121
|
+
if k.respond_to?(:superclass) && k.superclass.respond_to?(:singleton_class)
|
122
|
+
klasses.unshift k.superclass.singleton_class
|
121
123
|
end
|
122
124
|
end
|
123
125
|
#p [:klass_self_klass, klass]
|
@@ -300,7 +302,7 @@ module Doodle
|
|
300
302
|
def handle_error(name, *args)
|
301
303
|
__doodle__.errors << [name, *args]
|
302
304
|
if DoodleInfo.raise_exception_on_error
|
303
|
-
raise
|
305
|
+
raise(*args)
|
304
306
|
end
|
305
307
|
end
|
306
308
|
|
@@ -386,7 +388,7 @@ module Doodle
|
|
386
388
|
def lookup_attribute(name)
|
387
389
|
# (look at singleton attributes first)
|
388
390
|
# fixme[this smells like a hack to me - why not handled in attributes?]
|
389
|
-
|
391
|
+
singleton_class.attributes[name] || attributes[name]
|
390
392
|
end
|
391
393
|
private :lookup_attribute
|
392
394
|
|
@@ -463,8 +465,10 @@ module Doodle
|
|
463
465
|
def from(*args, &block)
|
464
466
|
# d { [:from, self, self.class, self.name, args, block] }
|
465
467
|
if block_given?
|
466
|
-
#
|
467
|
-
|
468
|
+
# set the rule for each arg given
|
469
|
+
args.each do |arg|
|
470
|
+
local_conversions[arg] = block
|
471
|
+
end
|
468
472
|
# d { [:from, conversions] }
|
469
473
|
else
|
470
474
|
convert(*args)
|
@@ -630,26 +634,41 @@ module Doodle
|
|
630
634
|
def initialize_from_hash(*args)
|
631
635
|
defer_validation do
|
632
636
|
# hash initializer
|
633
|
-
# separate into
|
637
|
+
# separate into array of hashes of form [{:k1 => v1}, {:k2 => v2}] and positional args
|
634
638
|
key_values, args = args.partition{ |x| x.kind_of?(Hash)}
|
635
|
-
|
639
|
+
Doodle::Debug.d { [:initialize_from_hash, :key_values, key_values, :args, args] }
|
636
640
|
|
637
|
-
#
|
641
|
+
# match up positional args with attribute names (from arg_order) using idiom to create hash from array of assocs
|
638
642
|
arg_keywords = Hash[*(Utils.flatten_first_level(self.class.arg_order[0...args.size].zip(args)))]
|
639
643
|
# d { [:initialize, :arg_keywords, arg_keywords] }
|
640
644
|
|
641
645
|
# set up initial values with ~clones~ of specified values (so not shared between instances)
|
642
|
-
init_values = attributes.select{|n, a| a.init_defined? }.inject({}) {|hash, (n, a)|
|
643
|
-
|
644
|
-
|
646
|
+
init_values = attributes.select{|n, a| a.init_defined? }.inject({}) {|hash, (n, a)|
|
647
|
+
hash[n] = begin
|
648
|
+
case a.init
|
649
|
+
when NilClass, TrueClass, FalseClass, Fixnum
|
650
|
+
a.init
|
651
|
+
else
|
652
|
+
a.init.clone
|
653
|
+
end
|
654
|
+
rescue
|
655
|
+
a.init
|
656
|
+
end
|
657
|
+
; hash }
|
658
|
+
|
659
|
+
# add to start of key_values array (so can be overridden by params)
|
645
660
|
key_values.unshift(init_values)
|
646
661
|
|
647
662
|
# merge all hash args into one
|
648
|
-
key_values = key_values.inject(arg_keywords){ |hash, item| hash.merge(item)}
|
649
|
-
|
663
|
+
key_values = key_values.inject(arg_keywords) { |hash, item| hash.merge(item)}
|
664
|
+
|
665
|
+
# convert key names to symbols
|
666
|
+
key_values = key_values.inject({}) {|h, (k, v)| h[k.to_sym] = v; h}
|
667
|
+
Doodle::Debug.d { [:initialize_from_hash, :key_values2, key_values, :args2, args] }
|
668
|
+
|
669
|
+
# create attributes
|
650
670
|
key_values.keys.each do |key|
|
651
|
-
key
|
652
|
-
# d { [:initialize_from_hash, :setting, key, key_values[key]] }
|
671
|
+
Doodle::Debug.d { [:initialize_from_hash, :setting, key, key_values[key]] }
|
653
672
|
if respond_to?(key)
|
654
673
|
send(key, key_values[key])
|
655
674
|
else
|
@@ -692,6 +711,8 @@ module Doodle
|
|
692
711
|
end
|
693
712
|
end
|
694
713
|
end
|
714
|
+
# if OK, then return self
|
715
|
+
self
|
695
716
|
end
|
696
717
|
|
697
718
|
# turn off validation, execute block, then set validation to same
|
data/lib/molic_orderedhash.rb
CHANGED
@@ -119,12 +119,12 @@ class OrderedHash < ::Hash
|
|
119
119
|
end
|
120
120
|
def reject &block
|
121
121
|
#--{{{
|
122
|
-
self.dup.delete_if
|
122
|
+
self.dup.delete_if(&block)
|
123
123
|
#--}}}
|
124
124
|
end
|
125
125
|
def reject! &block
|
126
126
|
#--{{{
|
127
|
-
hsh2 = reject
|
127
|
+
hsh2 = reject(&block)
|
128
128
|
self == hsh2 ? nil : hsh2
|
129
129
|
#--}}}
|
130
130
|
end
|
data/spec/class_spec.rb
CHANGED
@@ -36,11 +36,11 @@ describe Doodle, 'class attributes' do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should list all class's own attributes" do
|
39
|
-
Foo.
|
39
|
+
Foo.singleton_class.attributes(false).keys.should == [:metadata]
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should list all class's own attributes" do
|
43
|
-
Foo.
|
43
|
+
Foo.singleton_class.attributes.keys.should == [:metadata]
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'should create Bar class attribute' do
|
@@ -73,11 +73,11 @@ describe Doodle, 'class attributes' do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should list all class's own attributes" do
|
76
|
-
Bar.
|
76
|
+
Bar.singleton_class.attributes(false).keys.should == [:doc]
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should list all class's own attributes" do
|
80
|
-
Bar.
|
80
|
+
Bar.singleton_class.attributes.keys.should == [:metadata, :doc]
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
data/spec/defaults_spec.rb
CHANGED
@@ -23,16 +23,16 @@ describe Doodle, 'attributes with defaults' do
|
|
23
23
|
@foo.attributes[:name].default.should == 'D1'
|
24
24
|
end
|
25
25
|
it 'should have class attribute default via class.meta' do
|
26
|
-
Foo.
|
26
|
+
Foo.singleton_class.attributes(false)[:metadata].default.should == 'D2'
|
27
27
|
end
|
28
28
|
it 'should have class attribute default via class.meta' do
|
29
|
-
Foo.
|
29
|
+
Foo.singleton_class.attributes[:metadata].default.should == 'D2'
|
30
30
|
end
|
31
|
-
it 'should have singleton attribute default via instance.
|
32
|
-
@foo.
|
31
|
+
it 'should have singleton attribute default via instance.singleton_class.attributes(false)' do
|
32
|
+
@foo.singleton_class.attributes(false)[:special].default.should == 'D3'
|
33
33
|
end
|
34
|
-
it 'should have singleton attribute default via instance.
|
35
|
-
@foo.
|
34
|
+
it 'should have singleton attribute default via instance.singleton_class.attributes' do
|
35
|
+
@foo.singleton_class.attributes[:special].default.should == 'D3'
|
36
36
|
end
|
37
37
|
it 'should have singleton attribute name by default' do
|
38
38
|
@foo.name.should == 'D1'
|
@@ -53,8 +53,8 @@ describe Doodle, 'attributes with defaults' do
|
|
53
53
|
Foo.instance_variables.sort.should == []
|
54
54
|
end
|
55
55
|
it 'should not have @special singleton instance variable' do
|
56
|
-
@foo.
|
57
|
-
@foo.
|
56
|
+
@foo.singleton_class.instance_variables.include?("@special").should == false
|
57
|
+
@foo.singleton_class.instance_variables.sort.should == []
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
data/spec/doodle_spec.rb
CHANGED
@@ -1,24 +1,5 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
|
3
|
-
describe Doodle, 'basics' do
|
4
|
-
temporary_constant :Foo do
|
5
|
-
before(:each) do
|
6
|
-
class Foo
|
7
|
-
include Doodle::Helper
|
8
|
-
end
|
9
|
-
@foo = Foo.new
|
10
|
-
end
|
11
|
-
after :each do
|
12
|
-
remove_ivars :foo
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should have meta as synonym for singleton_class' do
|
16
|
-
Foo.singleton_class.should == Foo.meta
|
17
|
-
@foo.singleton_class.should == @foo.meta
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
3
|
describe Doodle, 'instance attributes' do
|
23
4
|
temporary_constant :Foo do
|
24
5
|
before(:each) do
|
@@ -87,11 +68,11 @@ describe Doodle, 'class attributes(false)' do
|
|
87
68
|
end
|
88
69
|
|
89
70
|
it "should list all class's own attributes" do
|
90
|
-
Foo.
|
71
|
+
Foo.singleton_class.attributes(false).keys.should == [:metadata]
|
91
72
|
end
|
92
73
|
|
93
74
|
it "should list all class's own attributes" do
|
94
|
-
Foo.
|
75
|
+
Foo.singleton_class.attributes.keys.should == [:metadata]
|
95
76
|
end
|
96
77
|
end
|
97
78
|
end
|
@@ -156,19 +137,19 @@ describe Doodle, 'inherited class attributes(false)' do
|
|
156
137
|
end
|
157
138
|
|
158
139
|
it "should list class's own attributes" do
|
159
|
-
Foo.
|
140
|
+
Foo.singleton_class.attributes(false).keys.should == [:metadata]
|
160
141
|
end
|
161
142
|
|
162
143
|
it "should list all class's own attributes" do
|
163
|
-
Foo.
|
144
|
+
Foo.singleton_class.attributes.keys.should == [:metadata]
|
164
145
|
end
|
165
146
|
|
166
147
|
it "should list class's own attributes(false)" do
|
167
|
-
Bar.
|
148
|
+
Bar.singleton_class.attributes(false).keys.should == [:doc]
|
168
149
|
end
|
169
150
|
|
170
151
|
it "should list all inherited meta class attributes" do
|
171
|
-
Bar.
|
152
|
+
Bar.singleton_class.attributes.keys.should == [:metadata, :doc]
|
172
153
|
end
|
173
154
|
|
174
155
|
it "should list all inherited class's attributes" do
|
@@ -203,11 +184,11 @@ describe Doodle, 'singleton class attributes' do
|
|
203
184
|
end
|
204
185
|
|
205
186
|
it 'should list instance attributes' do
|
206
|
-
@foo.
|
187
|
+
@foo.singleton_class.attributes(false).keys.should == [:special]
|
207
188
|
end
|
208
189
|
|
209
190
|
it 'should list instance attributes' do
|
210
|
-
@foo.
|
191
|
+
@foo.singleton_class.attributes.keys.should == [:metadata, :special]
|
211
192
|
end
|
212
193
|
end
|
213
194
|
end
|
@@ -261,20 +242,20 @@ describe Doodle, 'inherited singleton class attributes' do
|
|
261
242
|
end
|
262
243
|
|
263
244
|
it 'should list instance meta attributes' do
|
264
|
-
@foo.
|
265
|
-
@bar.
|
245
|
+
@foo.singleton_class.attributes(false).keys.should == [:special]
|
246
|
+
@bar.singleton_class.attributes(false).keys.should == [:extra]
|
266
247
|
end
|
267
248
|
|
268
249
|
it 'should list instance attributes' do
|
269
|
-
@foo.
|
270
|
-
@bar.
|
250
|
+
@foo.singleton_class.attributes.keys.should == [:metadata, :special]
|
251
|
+
@bar.singleton_class.attributes.keys.should == [:metadata, :doc, :extra]
|
271
252
|
end
|
272
253
|
|
273
254
|
it 'should keep meta attributes separate' do
|
274
255
|
@foo.special = 'foo special'
|
275
256
|
@foo.special.should == 'foo special'
|
276
|
-
@foo.
|
277
|
-
@foo.
|
257
|
+
@foo.singleton_class.metadata = 'foo meta'
|
258
|
+
@foo.singleton_class.metadata.should == 'foo meta'
|
278
259
|
# note: you cannot set any other values on @bar until you have set @bar.extra because it's defined as required
|
279
260
|
@bar.extra = 'bar extra'
|
280
261
|
@bar.extra.should == 'bar extra'
|
@@ -287,7 +268,7 @@ describe Doodle, 'inherited singleton class attributes' do
|
|
287
268
|
|
288
269
|
# now make sure they haven't bumped each other off
|
289
270
|
@foo.special.should == 'foo special'
|
290
|
-
@foo.
|
271
|
+
@foo.singleton_class.metadata.should == 'foo meta'
|
291
272
|
@bar.extra.should == 'bar extra'
|
292
273
|
Foo.metadata.should == 'Foo meta'
|
293
274
|
Bar.metadata.should == 'Bar meta'
|
@@ -298,11 +279,11 @@ describe Doodle, 'inherited singleton class attributes' do
|
|
298
279
|
@bar.extra = 'bar extra'
|
299
280
|
@bar.extra.should == 'bar extra'
|
300
281
|
# pending 'working out how to make this work' do
|
301
|
-
# @bar.
|
302
|
-
# @bar.
|
303
|
-
# @bar.
|
304
|
-
# @bar.
|
305
|
-
# proc { @foo.
|
282
|
+
# @bar.singleton_class.metadata = 'bar meta metadata'
|
283
|
+
# @bar.singleton_class.metadata.should == 'bar meta metadata'
|
284
|
+
# @bar.singleton_class.doc = 'bar doc'
|
285
|
+
# @bar.singleton_class.doc.should == 'bar doc'
|
286
|
+
# proc { @foo.singleton_class.doc = 1 }.should raise_error(NoMethodError)
|
306
287
|
# end
|
307
288
|
end
|
308
289
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doodle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean O'Halpin
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-03-
|
12
|
+
date: 2008-03-24 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- examples/example-01.rdoc
|
35
35
|
- examples/example-02.rb
|
36
36
|
- examples/example-02.rdoc
|
37
|
+
- examples/src/sequel_core-1.3/lib/sequel_core/exceptions.rb
|
37
38
|
- README
|
38
39
|
- COPYING
|
39
40
|
- ChangeLog
|