doodle 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,12 @@
1
+ == 0.1.2 / 2008-05-01
2
+ - avoid wierd interaction with ActiveRecord (where calling inspect on a
3
+ class hits the database). Thanks again to Ryan Garver.
4
+
1
5
  == 0.1.1 / 2008-04-28
2
6
  - changed name of #parent to #doodle_parent to avoid clash with
3
7
  ActiveSupport (thanks to Ryan Garver for reporting this)
4
8
 
9
+
5
10
  == 0.1.0 / 2008-04-26
6
11
  - doodle's first beta version - the API should remain stable from now on
7
12
  - created a Google group: http://groups.google.com/group/ruby-doodle
@@ -20,6 +25,7 @@
20
25
  - removed redundant methods & excised some cruft
21
26
  - refactored project to use newgem
22
27
 
28
+
23
29
  == 0.0.11 / 2008-04-13
24
30
  - refactored attributes and conversions
25
31
 
@@ -62,7 +62,7 @@ class Doodle
62
62
  # note[this uses regex match on object's inspect string - kludgy
63
63
  # - is there a better way?]
64
64
  return :nil if obj.class == NilClass
65
- case obj.real_inspect
65
+ case obj.inspect
66
66
  when /#<Class:#<.*0x[a-z0-9]+>+$/
67
67
  :instance_singleton_class
68
68
  when /#<Class:[A-Z]/
@@ -246,10 +246,10 @@ class Doodle
246
246
  @errors = []
247
247
  @doodle_parent = nil
248
248
  end
249
- real_inspect = Object.instance_method(:inspect)
250
- define_method :real_inspect do
251
- real_inspect.bind(self).call
252
- end
249
+ #real_inspect = Object.instance_method(:inspect)
250
+ #define_method :real_inspect do
251
+ # real_inspect.bind(self).call
252
+ #end
253
253
  def inspect
254
254
  ''
255
255
  end
@@ -261,45 +261,13 @@ class Doodle
261
261
  # (hack to fool yaml and anything else that queries instance_variables)
262
262
  meth = Object.instance_method(:instance_variables)
263
263
  define_method :instance_variables do
264
- meth.bind(self).call.reject{ |x| x =~ /@__doodle__/}
264
+ meth.bind(self).call.reject{ |x| x.to_s =~ /@__doodle__/}
265
265
  end
266
266
 
267
267
  # hide @__doodle__ from inspect
268
- # variants:
269
- # #<Foo:0xb7de0064>
270
- # #<Foo:0xb7c52d28 @name="Arthur Dent", @age=42>
271
- # #<Class:#<Foo:0xb7de0064>>
272
- # #<Class:Class>
273
- # #<Class:#<Class:#<Foo:0xb7de0064>>>
274
-
275
- # strip off all trailing > (count them = nesting)
276
- # take leading chars up to first space (or EOS)
277
- # rebuild rest
278
-
279
- real_inspect = Object.instance_method(:inspect)
280
- define_method :real_inspect do
281
- real_inspect.bind(self).call
282
- end
283
- define_method :inspect do
284
- # have to handle some built-ins as special case
285
- built_in = Doodle::BuiltIns::BUILTINS.select{ |x| self.kind_of?(x) }.first
286
- if built_in
287
- built_in.instance_method(:inspect).bind(self).call
288
- else
289
- istr = real_inspect.bind(self).call
290
- str = istr.gsub(/(>+$)/, '')
291
- trailing = $1
292
- klass = str.split(/\s/, 2).first
293
- ivars = self.kind_of?(Module) ? [] : instance_variables
294
- separator = ivars.size > 0 ? ' ' : ''
295
-
296
- #pp [:istr, istr, :str, str, :trailing, trailing, :klass, klass]
297
- # note to self: changing klass to <self.class will highlight cases that need the hack in parents
298
- #%[<#{self.class}#{separator}#{instance_variables.map{|x| "#{x}=#{instance_variable_get(x).inspect}"}.join(' ')}#{trailing}]
299
- %[#{klass}#{separator}#{ivars.map{|x| "#{x}=#{instance_variable_get(x).inspect}"}.join(' ')}#{trailing}]
300
- end
268
+ def inspect
269
+ super.gsub(/\s*@__doodle__=,/,'').gsub(/,?\s*@__doodle__=/,'')
301
270
  end
302
-
303
271
  end
304
272
 
305
273
  # the core module of Doodle - to get most facilities provided by Doodle
@@ -40,7 +40,7 @@ end
40
40
  ### user code
41
41
  require 'date'
42
42
  require 'uri'
43
- #require 'rfc822'
43
+ require 'rfc822'
44
44
 
45
45
  # note: this doesn't have to be in Doodle namespace
46
46
  class Doodle
@@ -51,7 +51,7 @@ class Doodle
51
51
  n.to_i
52
52
  end
53
53
  from String do |n|
54
- n =~ /[0-9]+(.[0-9]+)?/ or raise "#{name} must be numeric"
54
+ n =~ /[0-9]+(.[0-9]+)?/ or raise ArgumentError, "#{name} must be numeric"
55
55
  n.to_i
56
56
  end
57
57
  end
@@ -74,7 +74,7 @@ class Doodle
74
74
  if params.key?(:size)
75
75
  size = params.delete(:size)
76
76
  # size should be a Range
77
- size.kind_of?(Range) or raise ArgumentError, ":size should be a Range", caller[-1]
77
+ size.kind_of?(Range) or raise ArgumentError, "#{name}: size should be a Range", [caller[-1]]
78
78
  end
79
79
  define name, params, block, { :kind => String } do
80
80
  from String do |s|
@@ -108,10 +108,16 @@ class Doodle
108
108
  end
109
109
 
110
110
  def email(name, params = { }, &block)
111
- string(name, { :max => 255 }.merge(params), &block).instance_eval do
111
+ # for max length, see http://www.imc.org/ietf-fax/archive2/msg01578.html
112
+ # 384 = 128+1+255
113
+ string(name, { :max => 384 }.merge(params), &block).instance_eval do
112
114
  must "be valid email address" do |s|
113
- #s =~ RFC822::EmailAddress
114
- s =~ /\A.*@.*\z/
115
+ if RUBY_VERSION >= '1.9.0'
116
+ # the regex fails in 1.9 with illegal utf byte sequence error
117
+ s =~ /\A.*@.*\z/
118
+ else
119
+ s =~ RFC822::EmailAddress
120
+ end
115
121
  end
116
122
  end
117
123
  end
@@ -136,6 +142,7 @@ class Doodle
136
142
  str =~ /\d+\.\d+.\d+/
137
143
  end
138
144
  from Array do |a|
145
+ a.size == 3 or raise ArgumentError, "#{name}: version array argument must contain exactly 3 elements", [caller[-1]]
139
146
  a.join('.')
140
147
  end
141
148
  end
@@ -2,7 +2,7 @@ class Doodle #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 1
5
+ TINY = 2
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.1
4
+ version: 0.1.2
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-04-28 00:00:00 +01:00
12
+ date: 2008-05-01 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15