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 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
@@ -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
- # return self if a Module, else the singleton class
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
- # an alias for singleton_class
65
- alias :meta :singleton_class
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 &block
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?(:meta)
120
- klasses.unshift k.superclass.meta
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 *args
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
- meta.attributes[name] || attributes[name]
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
- # setting rule
467
- local_conversions[*args] = block
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 positional args and hashes (keyword => value)
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
- # d { [:initialize, :key_values, key_values, :args, args] }
639
+ Doodle::Debug.d { [:initialize_from_hash, :key_values, key_values, :args, args] }
636
640
 
637
- # use idiom to create hash from array of assocs
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)| hash[n] = a.init.clone rescue a.init; hash }
643
-
644
- # add to start of key_values (so can be overridden by params)
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
- # d { [:initialize, :key_values, key_values] }
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 = key.to_sym
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
@@ -119,12 +119,12 @@ class OrderedHash < ::Hash
119
119
  end
120
120
  def reject &block
121
121
  #--{{{
122
- self.dup.delete_if &block
122
+ self.dup.delete_if(&block)
123
123
  #--}}}
124
124
  end
125
125
  def reject! &block
126
126
  #--{{{
127
- hsh2 = reject &block
127
+ hsh2 = reject(&block)
128
128
  self == hsh2 ? nil : hsh2
129
129
  #--}}}
130
130
  end
@@ -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.meta.attributes(false).keys.should == [:metadata]
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.meta.attributes.keys.should == [:metadata]
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.meta.attributes(false).keys.should == [:doc]
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.meta.attributes.keys.should == [:metadata, :doc]
80
+ Bar.singleton_class.attributes.keys.should == [:metadata, :doc]
81
81
  end
82
82
  end
83
83
  end
@@ -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.meta.attributes(false)[:metadata].default.should == 'D2'
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.meta.attributes[:metadata].default.should == 'D2'
29
+ Foo.singleton_class.attributes[:metadata].default.should == 'D2'
30
30
  end
31
- it 'should have singleton attribute default via instance.meta.attributes(false)' do
32
- @foo.meta.attributes(false)[:special].default.should == 'D3'
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.meta.attributes' do
35
- @foo.meta.attributes[:special].default.should == 'D3'
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.meta.instance_variables.include?("@special").should == false
57
- @foo.meta.instance_variables.sort.should == []
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
@@ -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.meta.attributes(false).keys.should == [:metadata]
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.meta.attributes.keys.should == [:metadata]
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.meta.attributes(false).keys.should == [:metadata]
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.meta.attributes.keys.should == [:metadata]
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.meta.attributes(false).keys.should == [:doc]
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.meta.attributes.keys.should == [:metadata, :doc]
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.meta.attributes(false).keys.should == [:special]
187
+ @foo.singleton_class.attributes(false).keys.should == [:special]
207
188
  end
208
189
 
209
190
  it 'should list instance attributes' do
210
- @foo.meta.attributes.keys.should == [:metadata, :special]
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.meta.attributes(false).keys.should == [:special]
265
- @bar.meta.attributes(false).keys.should == [:extra]
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.meta.attributes.keys.should == [:metadata, :special]
270
- @bar.meta.attributes.keys.should == [:metadata, :doc, :extra]
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.meta.metadata = 'foo meta'
277
- @foo.meta.metadata.should == 'foo meta'
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.meta.metadata.should == 'foo meta'
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.meta.metadata = 'bar meta metadata'
302
- # @bar.meta.metadata.should == 'bar meta metadata'
303
- # @bar.meta.doc = 'bar doc'
304
- # @bar.meta.doc.should == 'bar doc'
305
- # proc { @foo.meta.doc = 1 }.should raise_error(NoMethodError)
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.6
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-16 00:00:00 +00:00
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