arbs 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/behavior_appender.rb +17 -0
- data/rakefile.rb +1 -1
- data/test/behavior_appender_test.rb +47 -0
- metadata +42 -35
data/lib/behavior_appender.rb
CHANGED
@@ -15,4 +15,21 @@ class BehaviorAppender #:nodoc:
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
[:string, :text, :integer, :datetime, :boolean].each do |column_type|
|
20
|
+
define_method column_type do |*args|
|
21
|
+
args.pop if args.last.is_a?(Hash)
|
22
|
+
args.each do |arg|
|
23
|
+
klass.class_eval do
|
24
|
+
attr_reader arg.to_sym unless instance_methods.include?(arg.to_s)
|
25
|
+
attr_writer arg.to_sym unless instance_methods.include?("#{arg}=")
|
26
|
+
if column_type == :boolean
|
27
|
+
define_method "#{arg}?".to_sym do
|
28
|
+
self.send name
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
18
35
|
end
|
data/rakefile.rb
CHANGED
@@ -33,7 +33,7 @@ Gem::manage_gems
|
|
33
33
|
specification = Gem::Specification.new do |s|
|
34
34
|
s.name = "arbs"
|
35
35
|
s.summary = "A duck that acts like ActiveRecord::Base, but doesn't have any of the AR::B functionality."
|
36
|
-
s.version = "0.0
|
36
|
+
s.version = "0.1.0"
|
37
37
|
s.author = 'Jay Fields'
|
38
38
|
s.description = "A duck that acts like ActiveRecord::Base, but doesn't have any of the AR::B functionality."
|
39
39
|
s.homepage = 'http://arbs.rubyforge.org'
|
@@ -42,5 +42,52 @@ unit_tests do
|
|
42
42
|
BehaviorAppender.new(klass).column("foo", "boolean")
|
43
43
|
assert_equal true, klass.instance_methods.include?("foo?")
|
44
44
|
end
|
45
|
+
|
46
|
+
test "string columns are created" do
|
47
|
+
klass = Class.new
|
48
|
+
BehaviorAppender.new(klass).string("foo")
|
49
|
+
assert_equal true, klass.instance_methods.include?("foo")
|
50
|
+
end
|
51
|
+
|
52
|
+
test "datetime columns are created" do
|
53
|
+
klass = Class.new
|
54
|
+
BehaviorAppender.new(klass).datetime("foo")
|
55
|
+
assert_equal true, klass.instance_methods.include?("foo")
|
56
|
+
end
|
57
|
+
|
58
|
+
test "boolean columns are created" do
|
59
|
+
klass = Class.new
|
60
|
+
BehaviorAppender.new(klass).boolean("foo")
|
61
|
+
assert_equal true, klass.instance_methods.include?("foo")
|
62
|
+
end
|
63
|
+
|
64
|
+
test "boolean columns are created with writer" do
|
65
|
+
klass = Class.new
|
66
|
+
BehaviorAppender.new(klass).boolean("foo")
|
67
|
+
assert_equal true, klass.instance_methods.include?("foo=")
|
68
|
+
end
|
69
|
+
|
70
|
+
test "boolean columns are created with ?" do
|
71
|
+
klass = Class.new
|
72
|
+
BehaviorAppender.new(klass).boolean("foo")
|
73
|
+
assert_equal true, klass.instance_methods.include?("foo?")
|
74
|
+
end
|
45
75
|
|
76
|
+
test "integer columns are created" do
|
77
|
+
klass = Class.new
|
78
|
+
BehaviorAppender.new(klass).integer("foo")
|
79
|
+
assert_equal true, klass.instance_methods.include?("foo")
|
80
|
+
end
|
81
|
+
|
82
|
+
test "text columns are created" do
|
83
|
+
klass = Class.new
|
84
|
+
BehaviorAppender.new(klass).text("foo")
|
85
|
+
assert_equal true, klass.instance_methods.include?("foo")
|
86
|
+
end
|
87
|
+
|
88
|
+
test "string options are ignored" do
|
89
|
+
klass = Class.new
|
90
|
+
BehaviorAppender.new(klass).string("foo" => "bar")
|
91
|
+
assert_equal true, klass.instance_methods(false).empty?
|
92
|
+
end
|
46
93
|
end
|
metadata
CHANGED
@@ -1,33 +1,26 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.2
|
3
|
-
specification_version: 1
|
4
2
|
name: arbs
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0
|
7
|
-
|
8
|
-
summary: A duck that acts like ActiveRecord::Base, but doesn't have any of the AR::B functionality.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email:
|
12
|
-
homepage: http://arbs.rubyforge.org
|
13
|
-
rubyforge_project: arbs
|
14
|
-
description: A duck that acts like ActiveRecord::Base, but doesn't have any of the AR::B functionality.
|
15
|
-
autorequire: arbs
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
25
|
-
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ""
|
29
6
|
authors:
|
30
7
|
- Jay Fields
|
8
|
+
autorequire: arbs
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2007-12-21 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A duck that acts like ActiveRecord::Base, but doesn't have any of the AR::B functionality.
|
17
|
+
email:
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
31
24
|
files:
|
32
25
|
- lib/active_record/base.rb
|
33
26
|
- lib/active_record/schema.rb
|
@@ -42,21 +35,35 @@ files:
|
|
42
35
|
- test/test_helper.rb
|
43
36
|
- rakefile.rb
|
44
37
|
- README
|
45
|
-
|
46
|
-
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: http://arbs.rubyforge.org
|
40
|
+
post_install_message:
|
47
41
|
rdoc_options:
|
48
42
|
- --title
|
49
43
|
- arbs
|
50
44
|
- --main
|
51
45
|
- README
|
52
46
|
- --line-numbers
|
53
|
-
|
54
|
-
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
59
61
|
requirements: []
|
60
62
|
|
61
|
-
|
62
|
-
|
63
|
+
rubyforge_project: arbs
|
64
|
+
rubygems_version: 0.9.5
|
65
|
+
signing_key:
|
66
|
+
specification_version: 2
|
67
|
+
summary: A duck that acts like ActiveRecord::Base, but doesn't have any of the AR::B functionality.
|
68
|
+
test_files:
|
69
|
+
- test/all_tests.rb
|