doodle 0.1.8 → 0.1.9
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/History.txt +52 -0
- data/Manifest.txt +1 -0
- data/examples/mail-datatypes.rb +1 -0
- data/examples/mail.rb +1 -1
- data/examples/profile-options.rb +1 -1
- data/lib/doodle.rb +332 -103
- data/lib/doodle/app.rb +445 -0
- data/lib/doodle/datatypes.rb +124 -15
- data/lib/doodle/version.rb +1 -1
- data/lib/molic_orderedhash.rb +99 -162
- data/log/debug.log +1 -0
- data/spec/block_init_spec.rb +52 -0
- data/spec/bugs_spec.rb +114 -18
- data/spec/class_var_spec.rb +28 -14
- data/spec/conversion_spec.rb +36 -38
- data/spec/doodle_spec.rb +23 -23
- data/spec/has_spec.rb +19 -1
- data/spec/init_spec.rb +22 -16
- data/spec/member_init_spec.rb +122 -0
- data/spec/readonly_spec.rb +32 -0
- data/spec/singleton_spec.rb +7 -7
- data/spec/spec_helper.rb +1 -1
- data/spec/symbolize_keys_spec.rb +40 -0
- data/spec/to_hash_spec.rb +35 -0
- metadata +39 -22
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
describe 'Doodle', 'readonly attributes' do
|
5
|
+
temporary_constant :Foo do
|
6
|
+
before :each do
|
7
|
+
class Foo < Doodle
|
8
|
+
has :ivar1, :readonly => true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should allow setting readonly attribute during initialization' do
|
13
|
+
proc { Foo.new(:ivar1 => "hello") }.should_not raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should not allow setting readonly attribute after initialization' do
|
17
|
+
foo = Foo.new(:ivar1 => "hello")
|
18
|
+
foo.ivar1.should_be "hello"
|
19
|
+
proc { foo.ivar1 = "world"}.should raise_error(Doodle::ReadOnlyError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should not allow setting readonly attribute after initialization' do
|
23
|
+
foo = Foo do
|
24
|
+
ivar1 "hello"
|
25
|
+
end
|
26
|
+
foo.ivar1.should_be "hello"
|
27
|
+
proc { foo.ivar1 = "world"}.should raise_error(Doodle::ReadOnlyError)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
data/spec/singleton_spec.rb
CHANGED
@@ -8,8 +8,8 @@ describe Doodle, "singletons" do
|
|
8
8
|
has :c1
|
9
9
|
end
|
10
10
|
end
|
11
|
-
Foo.doodle.attributes.should_be OrderedHash.new
|
12
|
-
Foo.singleton_class.doodle.attributes.should_not_be OrderedHash.new
|
11
|
+
Foo.doodle.attributes.should_be Doodle::OrderedHash.new
|
12
|
+
Foo.singleton_class.doodle.attributes.should_not_be Doodle::OrderedHash.new
|
13
13
|
Foo.singleton_class.doodle.attributes.map{ |name, attr| name }.should_be [:c1]
|
14
14
|
Foo.c1 = 1
|
15
15
|
Foo.c1.should_be 1
|
@@ -22,8 +22,8 @@ describe Doodle, "singletons" do
|
|
22
22
|
has :c2
|
23
23
|
end
|
24
24
|
end
|
25
|
-
Foo.doodle.attributes.should_be OrderedHash.new
|
26
|
-
Foo.singleton_class.doodle.attributes.should_not_be OrderedHash.new
|
25
|
+
Foo.doodle.attributes.should_be Doodle::OrderedHash.new
|
26
|
+
Foo.singleton_class.doodle.attributes.should_not_be Doodle::OrderedHash.new
|
27
27
|
Foo.singleton_class.doodle.attributes.map{ |name, attr| name }.should_be [:c2]
|
28
28
|
Foo.c2 = 1
|
29
29
|
Foo.c2.should_be 1
|
@@ -37,7 +37,7 @@ describe Doodle, "singletons" do
|
|
37
37
|
has :i1
|
38
38
|
end
|
39
39
|
foo.doodle.attributes.keys.should_be [:i1]
|
40
|
-
foo.singleton_class.doodle.attributes.should_not_be OrderedHash.new
|
40
|
+
foo.singleton_class.doodle.attributes.should_not_be Doodle::OrderedHash.new
|
41
41
|
foo.singleton_class.doodle.attributes.map{ |name, attr| name }.should_be [:i1]
|
42
42
|
foo.i1 = 1
|
43
43
|
foo.i1.should_be 1
|
@@ -53,8 +53,8 @@ describe Doodle, "singletons" do
|
|
53
53
|
has :i2
|
54
54
|
end
|
55
55
|
end
|
56
|
-
foo.doodle.attributes.should_be OrderedHash.new
|
57
|
-
foo.singleton_class.singleton_class.doodle.attributes.should_not_be OrderedHash.new
|
56
|
+
foo.doodle.attributes.should_be Doodle::OrderedHash.new
|
57
|
+
foo.singleton_class.singleton_class.doodle.attributes.should_not_be Doodle::OrderedHash.new
|
58
58
|
foo.singleton_class.singleton_class.doodle.attributes.map{ |name, attr| name }.should_be [:i2]
|
59
59
|
foo.singleton_class.i2 = 1
|
60
60
|
foo.singleton_class.i2.should_be 1
|
data/spec/spec_helper.rb
CHANGED
@@ -30,7 +30,7 @@ def undefine_const(*consts)
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def raise_if_defined(*args)
|
33
|
-
defined
|
33
|
+
defined = args.select{ |x| Object.const_defined?(x)}
|
34
34
|
raise "Namespace pollution: #{defined.join(', ')}" if defined.size > 0
|
35
35
|
end
|
36
36
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
describe Doodle::Utils, 'normalize_keys' do
|
5
|
+
sym_hash = {
|
6
|
+
:barn => {
|
7
|
+
:animals=>
|
8
|
+
[
|
9
|
+
{
|
10
|
+
:species=>"pig"
|
11
|
+
}
|
12
|
+
]
|
13
|
+
}
|
14
|
+
}
|
15
|
+
string_hash = {
|
16
|
+
"barn" => {
|
17
|
+
"animals" =>
|
18
|
+
[
|
19
|
+
{
|
20
|
+
"species"=>"pig"
|
21
|
+
}
|
22
|
+
]
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
args = [
|
27
|
+
{ :input => [string_hash], :output => {:barn=>{"animals"=>[{"species"=>"pig"}]}} },
|
28
|
+
{ :input => [sym_hash, false, :to_s], :output => {"barn"=>{:animals=>[{:species=>"pig"}]}}},
|
29
|
+
{ :input => [string_hash, true, :to_sym], :output => sym_hash },
|
30
|
+
{ :input => [sym_hash, true, :to_s], :output => string_hash },
|
31
|
+
]
|
32
|
+
|
33
|
+
args.each do |arg|
|
34
|
+
it "should produce output #{arg[:output].inspect} from args #{arg[:input].inspect})" do
|
35
|
+
Doodle::Utils.normalize_keys(*arg[:input]).should == arg[:output]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
describe 'Doodle', 'block initialization of scalar attributes' do
|
5
|
+
temporary_constant :Foo, :Bar, :Farm, :Barn, :Animal do
|
6
|
+
before :each do
|
7
|
+
class Animal < Doodle
|
8
|
+
has :species
|
9
|
+
end
|
10
|
+
class Barn < Doodle
|
11
|
+
has :animals, :collect => Animal
|
12
|
+
end
|
13
|
+
class Farm < Doodle
|
14
|
+
has Barn
|
15
|
+
end
|
16
|
+
class Foo < Doodle
|
17
|
+
has :ivar1, :kind => String
|
18
|
+
end
|
19
|
+
class Bar < Doodle
|
20
|
+
has :block, :kind => Proc
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should initialize an scalar attribute from a block' do
|
25
|
+
farm = Farm do
|
26
|
+
barn do
|
27
|
+
animal "pig"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
farm.to_hash.should_be( {:barn=>{:animals=>[{:species=>"pig"}]}} )
|
31
|
+
farm.to_string_hash.should_be( {"barn"=>{"animals"=>[{"species"=>"pig"}]}} )
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
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.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean O'Halpin
|
@@ -9,10 +9,19 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-12-15 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.8.0
|
24
|
+
version:
|
16
25
|
description: "Doodle is a gem for simplifying the definition of Ruby classes by making attributes and their properties more declarative. Doodle is eco-friendly: it does not globally modify Object, Class or Module."
|
17
26
|
email:
|
18
27
|
- sean.ohalpin@gmail.com
|
@@ -26,6 +35,8 @@ extra_rdoc_files:
|
|
26
35
|
- Manifest.txt
|
27
36
|
- PostInstall.txt
|
28
37
|
- README.txt
|
38
|
+
- examples/example-01.rdoc
|
39
|
+
- examples/example-02.rdoc
|
29
40
|
files:
|
30
41
|
- COPYING
|
31
42
|
- CREDITS
|
@@ -52,6 +63,7 @@ files:
|
|
52
63
|
- examples/yaml-example.rb
|
53
64
|
- examples/yaml-example2.rb
|
54
65
|
- lib/doodle.rb
|
66
|
+
- lib/doodle/app.rb
|
55
67
|
- lib/doodle/datatypes.rb
|
56
68
|
- lib/doodle/rfc822.rb
|
57
69
|
- lib/doodle/utils.rb
|
@@ -117,35 +129,40 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
129
|
requirements: []
|
118
130
|
|
119
131
|
rubyforge_project: doodle
|
120
|
-
rubygems_version: 1.
|
132
|
+
rubygems_version: 1.3.1
|
121
133
|
signing_key:
|
122
134
|
specification_version: 2
|
123
135
|
summary: "Doodle is a gem for simplifying the definition of Ruby classes by making attributes and their properties more declarative. Doodle is eco-friendly: it does not globally modify Object, Class or Module."
|
124
136
|
test_files:
|
137
|
+
- spec/arg_order_spec.rb
|
138
|
+
- spec/attributes_spec.rb
|
139
|
+
- spec/block_init_spec.rb
|
125
140
|
- spec/bugs_spec.rb
|
126
|
-
- spec/
|
141
|
+
- spec/class_spec.rb
|
142
|
+
- spec/class_validation_spec.rb
|
127
143
|
- spec/class_var_spec.rb
|
128
|
-
- spec/
|
144
|
+
- spec/collector_spec.rb
|
145
|
+
- spec/conversion_spec.rb
|
146
|
+
- spec/defaults_spec.rb
|
147
|
+
- spec/doodle_context_spec.rb
|
148
|
+
- spec/doodle_spec.rb
|
149
|
+
- spec/extra_args_spec.rb
|
129
150
|
- spec/factory_spec.rb
|
130
151
|
- spec/flatten_first_level_spec.rb
|
131
|
-
- spec/new_doodle_spec.rb
|
132
|
-
- spec/attributes_spec.rb
|
133
|
-
- spec/kind_spec.rb
|
134
152
|
- spec/from_spec.rb
|
135
|
-
- spec/
|
153
|
+
- spec/has_spec.rb
|
154
|
+
- spec/inheritance_spec.rb
|
155
|
+
- spec/init_spec.rb
|
156
|
+
- spec/kind_spec.rb
|
157
|
+
- spec/member_init_spec.rb
|
158
|
+
- spec/new_doodle_spec.rb
|
159
|
+
- spec/readonly_spec.rb
|
160
|
+
- spec/required_spec.rb
|
136
161
|
- spec/serialization_spec.rb
|
137
162
|
- spec/singleton_spec.rb
|
163
|
+
- spec/specialized_attribute_class_spec.rb
|
138
164
|
- spec/superclass_spec.rb
|
165
|
+
- spec/symbolize_keys_spec.rb
|
166
|
+
- spec/to_hash_spec.rb
|
139
167
|
- spec/validation2_spec.rb
|
140
|
-
- spec/init_spec.rb
|
141
168
|
- spec/validation_spec.rb
|
142
|
-
- spec/class_spec.rb
|
143
|
-
- spec/extra_args_spec.rb
|
144
|
-
- spec/collector_spec.rb
|
145
|
-
- spec/required_spec.rb
|
146
|
-
- spec/defaults_spec.rb
|
147
|
-
- spec/conversion_spec.rb
|
148
|
-
- spec/class_validation_spec.rb
|
149
|
-
- spec/doodle_spec.rb
|
150
|
-
- spec/has_spec.rb
|
151
|
-
- spec/doodle_context_spec.rb
|