sequel_model 0.5.0.1 → 0.5.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/Rakefile +1 -1
- data/lib/sequel_model/associations.rb +14 -3
- data/spec/associations_spec.rb +17 -0
- metadata +2 -2
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ include FileUtils
|
|
9
9
|
# Configuration
|
10
10
|
##############################################################################
|
11
11
|
NAME = "sequel_model"
|
12
|
-
VERS = "0.5.0.
|
12
|
+
VERS = "0.5.0.2"
|
13
13
|
CLEAN.include ["**/.*.sw?", "pkg/*", ".config", "doc/*", "coverage/*"]
|
14
14
|
RDOC_OPTS = [
|
15
15
|
"--quiet",
|
@@ -107,17 +107,28 @@ module Sequel::Model::Associations
|
|
107
107
|
# check arguments
|
108
108
|
raise ArgumentError unless [:many_to_one, :one_to_many, :many_to_many].include?(type) && Symbol === name
|
109
109
|
|
110
|
+
# merge early so we don't modify opts
|
111
|
+
opts = opts.merge(:type => type, :name => name, :block => block)
|
112
|
+
|
110
113
|
# deprecation
|
111
114
|
if opts[:from]
|
112
115
|
STDERR << "The :from option is deprecated, please use the :class option instead.\r\n"
|
113
116
|
opts[:class] = opts[:from]
|
114
117
|
end
|
115
118
|
|
116
|
-
#
|
117
|
-
|
118
|
-
|
119
|
+
# find class
|
120
|
+
case opts[:class]
|
121
|
+
when String, Symbol
|
122
|
+
# Delete :class to allow late binding
|
123
|
+
opts[:class_name] ||= opts.delete(:class).to_s
|
124
|
+
when Class
|
125
|
+
opts[:class_name] ||= opts[:class].name
|
126
|
+
end
|
119
127
|
|
120
128
|
send(:"def_#{type}", name, opts)
|
129
|
+
|
130
|
+
# don't add to association_reflections until we are sure there are no errors
|
131
|
+
association_reflections[name] = opts
|
121
132
|
end
|
122
133
|
|
123
134
|
# The association reflection hash for the association of the given name.
|
data/spec/associations_spec.rb
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
2
|
|
3
|
+
describe Sequel::Model, "associate" do
|
4
|
+
it "should use explicit class if given a class, symbol, or string" do
|
5
|
+
MODEL_DB.reset
|
6
|
+
klass = Class.new(Sequel::Model(:nodes))
|
7
|
+
class ParParent < Sequel::Model
|
8
|
+
end
|
9
|
+
|
10
|
+
klass.associate :many_to_one, :par_parent0, :class=>ParParent
|
11
|
+
klass.associate :one_to_many, :par_parent1s, :class=>'ParParent'
|
12
|
+
klass.associate :many_to_many, :par_parent2s, :class=>:ParParent
|
13
|
+
|
14
|
+
klass.send(:associated_class, klass.association_reflection(:"par_parent0")).should == ParParent
|
15
|
+
klass.send(:associated_class, klass.association_reflection(:"par_parent1s")).should == ParParent
|
16
|
+
klass.send(:associated_class, klass.association_reflection(:"par_parent2s")).should == ParParent
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
3
20
|
describe Sequel::Model, "many_to_one" do
|
4
21
|
|
5
22
|
before(:each) do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.0.
|
4
|
+
version: 0.5.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-03-
|
12
|
+
date: 2008-03-12 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|