doodle 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/History.txt +5 -2
  2. data/lib/doodle.rb +24 -30
  3. data/lib/doodle/version.rb +1 -1
  4. metadata +1 -1
@@ -1,3 +1,8 @@
1
+ == 0.1.3 / 2008-05-01
2
+ - really avoid wierd interaction with ActiveRecord this time
3
+ - also, managed to get rid of crufty reliance on inspect and found
4
+ a tidy way to determine singletons :)
5
+
1
6
  == 0.1.2 / 2008-05-01
2
7
  - avoid wierd interaction with ActiveRecord (where calling inspect on a
3
8
  class hits the database). Thanks again to Ryan Garver.
@@ -6,7 +11,6 @@
6
11
  - changed name of #parent to #doodle_parent to avoid clash with
7
12
  ActiveSupport (thanks to Ryan Garver for reporting this)
8
13
 
9
-
10
14
  == 0.1.0 / 2008-04-26
11
15
  - doodle's first beta version - the API should remain stable from now on
12
16
  - created a Google group: http://groups.google.com/group/ruby-doodle
@@ -25,7 +29,6 @@
25
29
  - removed redundant methods & excised some cruft
26
30
  - refactored project to use newgem
27
31
 
28
-
29
32
  == 0.0.11 / 2008-04-13
30
33
  - refactored attributes and conversions
31
34
 
@@ -59,20 +59,15 @@ class Doodle
59
59
  end
60
60
  # what kind of object are we dealing with?
61
61
  def doodle_category(obj)
62
- # note[this uses regex match on object's inspect string - kludgy
63
- # - is there a better way?]
64
62
  return :nil if obj.class == NilClass
65
- case obj.inspect
66
- when /#<Class:#<.*0x[a-z0-9]+>+$/
67
- :instance_singleton_class
68
- when /#<Class:[A-Z]/
69
- :class_singleton_class
70
- else
71
- if obj.kind_of?(Module)
63
+ if obj.kind_of?(Module)
64
+ if obj.ancestors.include?(obj)
72
65
  :class
73
66
  else
74
- :instance
67
+ :singleton_class
75
68
  end
69
+ else
70
+ :instance
76
71
  end
77
72
  end
78
73
  end
@@ -135,11 +130,9 @@ class Doodle
135
130
  case Doodle::Utils.doodle_category(self)
136
131
  when :instance
137
132
  klass = self.class
138
- when :instance_singleton_class
139
- klass = nil
140
133
  when :class
141
134
  klass = superclass
142
- when :class_singleton_class
135
+ when :singleton_class
143
136
  klass = nil
144
137
  end
145
138
  klasses = []
@@ -246,10 +239,6 @@ class Doodle
246
239
  @errors = []
247
240
  @doodle_parent = nil
248
241
  end
249
- #real_inspect = Object.instance_method(:inspect)
250
- #define_method :real_inspect do
251
- # real_inspect.bind(self).call
252
- #end
253
242
  def inspect
254
243
  ''
255
244
  end
@@ -452,16 +441,17 @@ class Doodle
452
441
 
453
442
  # set an attribute by name - apply validation if defined
454
443
  def _setter(name, *args, &block)
455
- Doodle::Debug.d { [:_setter, name, args] }
444
+ #Doodle::Debug.d { [:_setter, name, args] }
456
445
  ivar = "@#{name}"
457
446
  if block_given?
458
447
  args.unshift(DeferredBlock.new(block))
459
448
  end
460
449
  if att = lookup_attribute(name)
461
- Doodle::Debug.d { [:_setter, name, args] }
450
+ #Doodle::Debug.d { [:_setter, name, args] }
462
451
  v = instance_variable_set(ivar, att.validate(self, *args))
452
+ #v = instance_variable_set(ivar, *args)
463
453
  else
464
- Doodle::Debug.d { [:_setter, "no attribute"] }
454
+ #Doodle::Debug.d { [:_setter, "no attribute"] }
465
455
  v = instance_variable_set(ivar, *args)
466
456
  end
467
457
  validate!(false)
@@ -524,10 +514,14 @@ class Doodle
524
514
 
525
515
  # validate that args meet rules defined with +must+
526
516
  def validate(owner, *args)
527
- Doodle::Debug.d { [:validate, self, :owner, owner, :args, args ] }
517
+ #Doodle::Debug.d { [:validate, self, :owner, owner, :args, args ] }
518
+ # if I bypass convert here, the AR inspect wierdness stops
519
+ # so what is going on?
520
+ #return args.first
528
521
  value = convert(owner, *args)
522
+ #return args.first
529
523
  validations.each do |v|
530
- Doodle::Debug.d { [:validate, self, v, args, value] }
524
+ #Doodle::Debug.d { [:validate, self, v, args, value] }
531
525
  if !v.block[value]
532
526
  owner.handle_error name, ValidationError, "#{ name } must #{ v.message } - got #{ value.class }(#{ value.inspect })", [caller[-1]]
533
527
  end
@@ -694,22 +688,22 @@ class Doodle
694
688
  # validate this object by applying all validations in sequence
695
689
  # - if all == true, validate all attributes, e.g. when loaded from YAML, else validate at object level only
696
690
  def validate!(all = true)
697
- Doodle::Debug.d { [:validate!, all, caller] }
691
+ #Doodle::Debug.d { [:validate!, all, caller] }
698
692
  if all
699
693
  clear_errors
700
694
  end
701
695
  if __doodle__.validation_on
702
696
  if self.class == Class
703
697
  attribs = class_attributes
704
- Doodle::Debug.d { [:validate!, "using class_attributes", class_attributes] }
698
+ #Doodle::Debug.d { [:validate!, "using class_attributes", class_attributes] }
705
699
  else
706
700
  attribs = attributes
707
- Doodle::Debug.d { [:validate!, "using instance_attributes", attributes] }
701
+ #Doodle::Debug.d { [:validate!, "using instance_attributes", attributes] }
708
702
  end
709
703
  attribs.each do |name, att|
710
704
  # treat default as special case
711
705
  if att.default_defined?
712
- Doodle::Debug.d { [:validate!, "default_defined - breaking" ]}
706
+ #Doodle::Debug.d { [:validate!, "default_defined - breaking" ]}
713
707
  break
714
708
  end
715
709
  ivar_name = "@#{att.name}"
@@ -718,8 +712,8 @@ class Doodle
718
712
  # validations are applied to raw instance variables
719
713
  # e.g. when loaded from YAML
720
714
  if all
721
- Doodle::Debug.d { [:validate!, :sending, att.name, instance_variable_get(ivar_name) ] }
722
- __send__(att.name, instance_variable_get(ivar_name))
715
+ #Doodle::Debug.d { [:validate!, :sending, att.name, instance_variable_get(ivar_name) ] }
716
+ __send__("#{att.name}=", instance_variable_get(ivar_name))
723
717
  end
724
718
  elsif self.class != Class
725
719
  handle_error name, Doodle::ValidationError, "#{self} missing required attribute '#{name}'", [caller[-1]]
@@ -727,9 +721,9 @@ class Doodle
727
721
  end
728
722
  # now apply instance level validations
729
723
 
730
- Doodle::Debug.d { [:validate!, "validations", validations ]}
724
+ #Doodle::Debug.d { [:validate!, "validations", validations ]}
731
725
  validations.each do |v|
732
- Doodle::Debug.d { [:validate!, self, v ] }
726
+ #Doodle::Debug.d { [:validate!, self, v ] }
733
727
  begin
734
728
  if !instance_eval(&v.block)
735
729
  handle_error self, ValidationError, "#{ self.class } must #{ v.message }", [caller[-1]]
@@ -2,7 +2,7 @@ class Doodle #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  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.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean O'Halpin