doodle 0.0.10 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/CREDITS +22 -0
  2. data/{ChangeLog → History.txt} +22 -3
  3. data/License.txt +20 -0
  4. data/Manifest.txt +61 -0
  5. data/README.txt +166 -0
  6. data/Rakefile +4 -0
  7. data/config/hoe.rb +77 -0
  8. data/config/requirements.rb +15 -0
  9. data/examples/doodle-errors.rb +25 -0
  10. data/examples/event-location.rb +3 -7
  11. data/examples/example-01.rb +1 -1
  12. data/examples/example-01.rdoc +3 -3
  13. data/examples/example-02.rb +15 -4
  14. data/examples/example-02.rdoc +17 -5
  15. data/examples/mail-datatypes.rb +104 -0
  16. data/examples/mail.rb +85 -0
  17. data/examples/parent.rb +40 -0
  18. data/examples/profile-options.rb +67 -0
  19. data/examples/smtp_tls.rb +65 -0
  20. data/examples/test-datatypes.rb +55 -0
  21. data/examples/yaml-example.rb +40 -0
  22. data/examples/yaml-example2.rb +42 -0
  23. data/lib/doodle.rb +364 -301
  24. data/lib/doodle/datatypes.rb +148 -0
  25. data/lib/doodle/rfc822.rb +31 -0
  26. data/lib/doodle/utils.rb +13 -0
  27. data/lib/doodle/version.rb +9 -0
  28. data/log/debug.log +0 -0
  29. data/script/console +10 -0
  30. data/script/destroy +14 -0
  31. data/script/generate +14 -0
  32. data/script/txt2html +82 -0
  33. data/setup.rb +1585 -0
  34. data/spec/arg_order_spec.rb +5 -5
  35. data/spec/attributes_spec.rb +66 -24
  36. data/spec/bugs_spec.rb +109 -6
  37. data/spec/class_spec.rb +7 -4
  38. data/spec/class_validation_spec.rb +46 -0
  39. data/spec/class_var_spec.rb +76 -0
  40. data/spec/collector_spec.rb +16 -30
  41. data/spec/conversion_spec.rb +8 -3
  42. data/spec/defaults_spec.rb +4 -4
  43. data/spec/doodle_context_spec.rb +3 -4
  44. data/spec/doodle_spec.rb +25 -15
  45. data/spec/extra_args_spec.rb +1 -1
  46. data/spec/factory_spec.rb +3 -3
  47. data/spec/init_spec.rb +11 -11
  48. data/spec/new_doodle_spec.rb +19 -0
  49. data/spec/required_spec.rb +1 -1
  50. data/spec/serialization_spec.rb +3 -6
  51. data/spec/singleton_spec.rb +5 -5
  52. data/spec/spec.opts +1 -0
  53. data/spec/spec_helper.rb +44 -0
  54. data/spec/superclass_spec.rb +6 -5
  55. data/spec/validation2_spec.rb +248 -0
  56. data/spec/validation_spec.rb +26 -37
  57. data/tasks/deployment.rake +34 -0
  58. data/tasks/environment.rake +7 -0
  59. data/tasks/rspec.rake +21 -0
  60. data/tasks/website.rake +17 -0
  61. metadata +76 -20
  62. data/COPYING +0 -18
  63. data/README +0 -57
  64. data/examples/event.rb +0 -39
  65. data/examples/example-03.rb +0 -45
  66. data/examples/example-03.rdoc +0 -55
  67. data/lib/semantic.cache +0 -8
data/CREDITS ADDED
@@ -0,0 +1,22 @@
1
+ Doodle grew out of my response to Ruby Quiz 49 - "Lisp
2
+ Game":[http://www.rubyquiz.com/quiz49.html] and is in effect a ~very~
3
+ late entry to the justly renowned Quiz 67 -
4
+ "metakoans":[http://www.rubyquiz.com/quiz67.html]. I learnt a lot from
5
+ the answers to that quiz, in particular Christian Neukirchen's and
6
+ Florian Gross's solutions (though I took a different path). I've also
7
+ been inspired by Ara Howard's traits and attributes libraries.
8
+
9
+ == Similar and related libraries
10
+
11
+ * traits[http://www.codeforpeople.com/lib/ruby/traits/]
12
+ * attributes[http://www.codeforpeople.com/lib/ruby/attributes/]
13
+
14
+ == Thanks
15
+
16
+ *doodle* is developed using
17
+ BDD[http://en.wikipedia.org/wiki/Behavior_driven_development] with
18
+ RSpec[http://rspec.rubyforge.org/], autotest (part of the
19
+ ZenTest[http://www.zenspider.com/ZSS/Products/ZenTest/] suite) and
20
+ rcov[http://eigenclass.org/hiki.rb?rcov]. Thanks for the fantastic
21
+ tools guys!
22
+
@@ -1,8 +1,27 @@
1
- = ChangeLog for doodle
1
+ == 0.1.0 / 2008-04-26
2
+ - doodle's first beta version - the API should remain stable from now on
3
+ - created a Google group: http://groups.google.com/group/ruby-doodle
4
+ - major change: changed Doodle from module to class so you now use
5
+ class Foo < Doodle
6
+ instead of
7
+ class Foo < Doodle::Base
8
+ - Doodle::Helper renamed Doodle::Core
9
+ - added #parent method - returns outer object in initialization blocks
10
+ (see spec/doodle_context_spec for example usage)
11
+ - fixed class and singleton attribute inheritance
12
+ - rake spec now passes all specs with ruby 1.8.6, ruby 1.9.0 and JRuby 1.1.1
13
+ - added more specs
14
+ - added lib/doodle/utils.rb (used by examples)
15
+ - removed (half-hearted) support for 1.8.5
16
+ - removed redundant methods & excised some cruft
17
+ - refactored project to use newgem
18
+
19
+ == 0.0.11 / 2008-04-13
20
+ - refactored attributes and conversions
2
21
 
3
22
  == 0.0.10 / 2008-04-13
4
- - fixed bug in class attribute initialization
5
-
23
+ - fixed bug with setting class and singleton attributes & added spec
24
+
6
25
  == 0.0.9 / 2008-04-12
7
26
 
8
27
  - new features:
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Sean O'Halpin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,61 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ CREDITS
6
+ Rakefile
7
+ config/hoe.rb
8
+ config/requirements.rb
9
+ examples/smtp_tls.rb
10
+ examples/example-01.rdoc
11
+ examples/profile-options.rb
12
+ examples/doodle-errors.rb
13
+ examples/event-location.rb
14
+ examples/parent.rb
15
+ examples/example-02.rb
16
+ examples/example-02.rdoc
17
+ examples/example-01.rb
18
+ examples/mail.rb
19
+ examples/yaml-example2.rb
20
+ examples/yaml-example.rb
21
+ examples/test-datatypes.rb
22
+ examples/mail-datatypes.rb
23
+ lib/doodle.rb
24
+ lib/molic_orderedhash.rb
25
+ lib/doodle/datatypes.rb
26
+ lib/doodle/rfc822.rb
27
+ lib/doodle/utils.rb
28
+ lib/doodle/version.rb
29
+ log/debug.log
30
+ script/console
31
+ script/destroy
32
+ script/generate
33
+ script/txt2html
34
+ setup.rb
35
+ spec/arg_order_spec.rb
36
+ spec/attributes_spec.rb
37
+ spec/bugs_spec.rb
38
+ spec/class_spec.rb
39
+ spec/class_var_spec.rb
40
+ spec/collector_spec.rb
41
+ spec/conversion_spec.rb
42
+ spec/defaults_spec.rb
43
+ spec/doodle_context_spec.rb
44
+ spec/doodle_spec.rb
45
+ spec/extra_args_spec.rb
46
+ spec/factory_spec.rb
47
+ spec/flatten_first_level_spec.rb
48
+ spec/init_spec.rb
49
+ spec/new_doodle_spec.rb
50
+ spec/required_spec.rb
51
+ spec/serialization_spec.rb
52
+ spec/singleton_spec.rb
53
+ spec/spec.opts
54
+ spec/spec_helper.rb
55
+ spec/superclass_spec.rb
56
+ spec/validation_spec.rb
57
+ spec/validation2_spec.rb
58
+ tasks/deployment.rake
59
+ tasks/environment.rake
60
+ tasks/rspec.rake
61
+ tasks/website.rake
@@ -0,0 +1,166 @@
1
+ = doodle
2
+
3
+ * http://doodle.rubyforge.org
4
+
5
+ == DESCRIPTION:
6
+
7
+ Doodle is a Ruby library for simplifying the definition of Ruby
8
+ classes by making attributes and their properties more declarative.
9
+
10
+ Doodle is eco-friendly: it does not globally modify Object, Class or
11
+ Module, nor does it pollute instances with its own instance variables
12
+ (i.e. it plays nice with yaml).
13
+
14
+ Doodle has been tested with Ruby 1.8.6 and JRuby 1.1. It does not yet
15
+ work with Ruby 1.9 or Rubinius.
16
+
17
+ Please feel free to post bug reports, feature requests, and any
18
+ comments or discussion topics to the doodle Google group:
19
+ http://groups.google.com/group/ruby-doodle
20
+
21
+ == FEATURES:
22
+
23
+ * initialization
24
+ * using positional arguments
25
+ * with named arguments
26
+ * by block
27
+ * defaults
28
+ * initial values
29
+ * validation at attribute and class levels
30
+ * conversions for attributes and classes
31
+ * collectors to help in defining simple DSLs
32
+ * works for classes, instances and singletons
33
+
34
+ == SYNOPSIS:
35
+
36
+ === Example 1
37
+
38
+ require 'rubygems'
39
+ require 'date'
40
+ require 'doodle'
41
+
42
+ class DateRange < Doodle
43
+ has :start_date do
44
+ default { Date.today }
45
+ end
46
+ has :end_date do
47
+ default { start_date }
48
+ end
49
+ end
50
+
51
+ dr = DateRange.new
52
+ dr.start_date # => #<Date: 4909159/2,0,2299161>
53
+ dr.end_date # => #<Date: 4909159/2,0,2299161>
54
+
55
+ === Example 2
56
+
57
+ require 'rubygems'
58
+ require 'date'
59
+ require 'doodle'
60
+ require 'doodle/utils' # for try
61
+
62
+ class DateRange < Doodle
63
+ has :start_date, :kind => Date do
64
+ default { Date.today }
65
+ from String do |s|
66
+ Date.parse(s)
67
+ end
68
+ must "be >= 2000-01-01" do |d|
69
+ d >= Date.parse('2000-01-01')
70
+ end
71
+ end
72
+ has :end_date do
73
+ default { start_date }
74
+ from String do |s|
75
+ Date.parse(s)
76
+ end
77
+ end
78
+ must 'have end_date >= start_date' do
79
+ end_date >= start_date
80
+ end
81
+ from String do |s|
82
+ m = /(\d{4}-\d{2}-\d{2})\s*(?:to|-|\s)\s*(\d{4}-\d{2}-\d{2})/.match(s)
83
+ if m
84
+ self.new(*m.captures)
85
+ else
86
+ raise Exception, "Cannot parse date: '#{s}'"
87
+ end
88
+ end
89
+ end
90
+
91
+ dr = DateRange.new '2007-12-31', '2008-01-01'
92
+ dr.start_date # => #<Date: 4908931/2,0,2299161>
93
+ dr.end_date # => #<Date: 4908933/2,0,2299161>
94
+
95
+ dr = DateRange '2007-12-31', '2008-01-01'
96
+ dr.start_date # => #<Date: 4908931/2,0,2299161>
97
+ dr.end_date # => #<Date: 4908933/2,0,2299161>
98
+
99
+ dr = DateRange :start_date => '2007-12-31', :end_date => '2008-01-01'
100
+ dr.start_date # => #<Date: 4908931/2,0,2299161>
101
+ dr.end_date # => #<Date: 4908933/2,0,2299161>
102
+
103
+ dr = DateRange do
104
+ start_date '2007-12-31'
105
+ end_date '2008-01-01'
106
+ end
107
+ dr.start_date # => #<Date: 4908931/2,0,2299161>
108
+ dr.end_date # => #<Date: 4908933/2,0,2299161>
109
+
110
+
111
+ dr = DateRange.from '2007-01-01 to 2008-12-31'
112
+ dr.start_date # => #<Date: 4908203/2,0,2299161>
113
+ dr.end_date # => #<Date: 4909663/2,0,2299161>
114
+
115
+ dr = DateRange.from '2007-01-01 2007-12-31'
116
+ dr.start_date # => #<Date: 4908203/2,0,2299161>
117
+ dr.end_date # => #<Date: 4908931/2,0,2299161>
118
+
119
+ p try {
120
+ dr = DateRange.from 'Hello World'
121
+ dr.start_date # =>
122
+ dr.end_date # =>
123
+ }
124
+
125
+ p try {
126
+ dr = DateRange '2008-01-01', '2007-12-31'
127
+ dr.start_date # =>
128
+ dr.end_date # =>
129
+ }
130
+ # >> #<Doodle::ConversionError: Cannot parse date: 'Hello World'>
131
+ # >> #<Doodle::ValidationError: DateRange must have end_date >= start_date>
132
+
133
+ == INSTALL:
134
+
135
+ * Linux/Mac OS X
136
+
137
+ $ sudo gem install doodle
138
+
139
+ * Windows
140
+
141
+ C:\> gem install doodle
142
+
143
+ == LICENSE:
144
+
145
+ (The MIT License)
146
+
147
+ Copyright (c) 2008 Sean O'Halpin
148
+
149
+ Permission is hereby granted, free of charge, to any person obtaining
150
+ a copy of this software and associated documentation files (the
151
+ 'Software'), to deal in the Software without restriction, including
152
+ without limitation the rights to use, copy, modify, merge, publish,
153
+ distribute, sublicense, and/or sell copies of the Software, and to
154
+ permit persons to whom the Software is furnished to do so, subject to
155
+ the following conditions:
156
+
157
+ The above copyright notice and this permission notice shall be
158
+ included in all copies or substantial portions of the Software.
159
+
160
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
161
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
162
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
163
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
164
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
165
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
166
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
@@ -0,0 +1,77 @@
1
+ require 'doodle/version'
2
+
3
+ AUTHOR = "Sean O'Halpin" # can also be an array of Authors
4
+ EMAIL = "sean.ohalpin@gmail.com"
5
+ DESCRIPTION = "Doodle is a gem for simplifying the definition of Ruby classes by
6
+ making attributes and their properties more declarative. Doodle is
7
+ eco-friendly: it does not globally modify Object, Class or Module."
8
+
9
+ GEM_NAME = 'doodle' # what ppl will type to install your gem
10
+ RUBYFORGE_PROJECT = 'doodle' # The unix name for your project
11
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
12
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
13
+ EXTRA_DEPENDENCIES = [
14
+ # ['activesupport', '>= 1.3.1']
15
+ ] # An array of rubygem dependencies [name, version]
16
+
17
+ @config_file = "~/.rubyforge/user-config.yml"
18
+ @config = nil
19
+ RUBYFORGE_USERNAME = "unknown"
20
+ def rubyforge_username
21
+ unless @config
22
+ begin
23
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
24
+ rescue
25
+ puts <<-EOS
26
+ ERROR: No rubyforge config file found: #{@config_file}
27
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
28
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
29
+ EOS
30
+ exit
31
+ end
32
+ end
33
+ RUBYFORGE_USERNAME.replace @config["username"]
34
+ end
35
+
36
+
37
+ REV = nil
38
+ # UNCOMMENT IF REQUIRED:
39
+ # REV = YAML.load(`svn info`)['Revision']
40
+ VERS = Doodle::VERSION::STRING + (REV ? ".#{REV}" : "")
41
+ RDOC_OPTS = ['--quiet', '--title', 'doodle documentation',
42
+ "--opname", "index.html",
43
+ "--line-numbers",
44
+ "--main", "README",
45
+ "--inline-source"]
46
+
47
+ class Hoe
48
+ def extra_deps
49
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
50
+ @extra_deps
51
+ end
52
+ end
53
+
54
+ # Generate all the Rake tasks
55
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
56
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
57
+ p.developer(AUTHOR, EMAIL)
58
+ p.description = DESCRIPTION
59
+ p.summary = DESCRIPTION
60
+ p.url = HOMEPATH
61
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
62
+ p.test_globs = ["spec/**/*_spec.rb"]
63
+ # p.test_globs = ["test/**/test_*.rb"]
64
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
65
+
66
+ # == Optional
67
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
68
+ #p.extra_deps = EXTRA_DEPENDENCIES
69
+
70
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
71
+ end
72
+
73
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
74
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
75
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
76
+ $hoe.rsync_args = '-av --delete --ignore-errors'
77
+ $hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
@@ -0,0 +1,25 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'doodle'
3
+ require 'doodle/utils'
4
+ require 'pp'
5
+
6
+ class Foo < Doodle
7
+ has :name, :kind => String
8
+ end
9
+
10
+ params = {
11
+ :name => 1,
12
+ :extra => 42
13
+ }
14
+
15
+ rv = try {
16
+ foo = Foo(params)
17
+ }
18
+ pp rv
19
+
20
+ rv = try {
21
+ Doodle.raise_exception_on_error = false
22
+ foo = Foo(params)
23
+ foo.errors
24
+ }
25
+ pp rv
@@ -5,14 +5,14 @@ require 'doodle'
5
5
  require "yaml"
6
6
  require "pp"
7
7
 
8
- class Location < Doodle::Base
8
+ class Location < Doodle
9
9
  has :name, :kind => String
10
10
  has :events, :init => [], :collect => :Event
11
11
  end
12
12
 
13
13
  class Event
14
14
  # or if you want to inherit from another class
15
- include Doodle::Helper
15
+ include Doodle::Core
16
16
  include Doodle::Factory
17
17
 
18
18
  has :name, :kind => String
@@ -26,11 +26,7 @@ class Event
26
26
  Date.parse(s)
27
27
  end
28
28
  end
29
- has :locations, :init => [], :collect => {:place => "Location"} do
30
- from Array do |array|
31
- array.map{|x| Location(x)}
32
- end
33
- end
29
+ has :locations, :collect => {:place => :Location}
34
30
  end
35
31
 
36
32
  event = Event "Festival" do