sequel_model 0.4 → 0.4.1
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/CHANGELOG +8 -0
- data/Rakefile +1 -1
- data/lib/sequel_model.rb +19 -17
- data/lib/sequel_model/base.rb +1 -1
- data/lib/sequel_model/record.rb +3 -8
- data/spec/model_spec.rb +14 -6
- metadata +13 -13
data/CHANGELOG
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
=== 0.4.1 (2008-02-10)
|
2
|
+
|
3
|
+
* Implemented Model#inspect (#151).
|
4
|
+
|
5
|
+
* Changed Model#method_missing to short-circuit and bypass checking #columns if the values hash already contains the relevant column (#150).
|
6
|
+
|
7
|
+
* Updated to reflect changes in sequel_core (Dataset#clone_merge renamed to Dataset#clone).
|
8
|
+
|
1
9
|
=== 0.4 (2008-02-05)
|
2
10
|
|
3
11
|
* Fixed Model#set to work with string keys (#143).
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ include FileUtils
|
|
9
9
|
# Configuration
|
10
10
|
##############################################################################
|
11
11
|
NAME = "sequel_model"
|
12
|
-
VERS = "0.4"
|
12
|
+
VERS = "0.4.1"
|
13
13
|
CLEAN.include ["**/.*.sw?", "pkg/*", ".config", "doc/*", "coverage/*"]
|
14
14
|
RDOC_OPTS = [
|
15
15
|
"--quiet",
|
data/lib/sequel_model.rb
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
module Sequel
|
2
|
+
class Model
|
3
|
+
alias_method :model, :class
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
# TODO: add relationships when complete:
|
8
|
+
files = %w[
|
9
|
+
base hooks record schema relations
|
10
|
+
caching plugins validations
|
11
|
+
]
|
12
|
+
dir = File.join(File.dirname(__FILE__), "sequel_model")
|
13
|
+
files.each {|f| require(File.join(dir, f))}
|
14
|
+
|
1
15
|
module Sequel
|
2
16
|
# == Sequel Models
|
3
17
|
#
|
@@ -225,22 +239,11 @@ module Sequel
|
|
225
239
|
# Post.create_table! # drops the table if it exists and then recreates it
|
226
240
|
#
|
227
241
|
class Model
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
# TODO: add relationships when complete:
|
234
|
-
files = %w[
|
235
|
-
base hooks record schema relations
|
236
|
-
caching plugins validations
|
237
|
-
]
|
238
|
-
dir = File.join(File.dirname(__FILE__), "sequel_model")
|
239
|
-
files.each {|f| require(File.join(dir, f))}
|
240
|
-
|
241
|
-
module Sequel
|
242
|
-
|
243
|
-
class Model
|
242
|
+
# Returns a string representation of the model instance including
|
243
|
+
# the class name and values.
|
244
|
+
def inspect
|
245
|
+
"#<%s @values=%s>" % [self.class.name, @values.inspect]
|
246
|
+
end
|
244
247
|
|
245
248
|
# Defines a method that returns a filtered dataset.
|
246
249
|
def self.subset(name, *args, &block)
|
@@ -316,5 +319,4 @@ module Sequel
|
|
316
319
|
dataset.all
|
317
320
|
end
|
318
321
|
end
|
319
|
-
|
320
322
|
end
|
data/lib/sequel_model/base.rb
CHANGED
data/lib/sequel_model/record.rb
CHANGED
@@ -299,20 +299,15 @@ module Sequel
|
|
299
299
|
end
|
300
300
|
|
301
301
|
ATTR_RE = /^([a-zA-Z_]\w*)(=)?$/.freeze
|
302
|
+
EQUAL_SIGN = '='.freeze
|
302
303
|
|
303
304
|
def method_missing(m, *args) #:nodoc:
|
304
305
|
if m.to_s =~ ATTR_RE
|
305
306
|
att = $1.to_sym
|
306
|
-
write = $2 ==
|
307
|
+
write = $2 == EQUAL_SIGN
|
307
308
|
|
308
309
|
# check whether the column is legal
|
309
|
-
unless columns.include?(att)
|
310
|
-
# if read accessor and a value exists for the column, we return it
|
311
|
-
if !write && @values.has_key?(att)
|
312
|
-
return @values[att]
|
313
|
-
end
|
314
|
-
|
315
|
-
# otherwise, raise an error
|
310
|
+
unless @values.has_key?(att) || columns.include?(att)
|
316
311
|
raise Error, "Invalid column (#{att.inspect}) for #{self}"
|
317
312
|
end
|
318
313
|
|
data/spec/model_spec.rb
CHANGED
@@ -439,10 +439,9 @@ describe Sequel::Model, "attribute accessors" do
|
|
439
439
|
MODEL_DB.reset
|
440
440
|
|
441
441
|
@c = Class.new(Sequel::Model(:items)) do
|
442
|
-
def columns
|
443
|
-
[:id, :x, :y]
|
444
|
-
end
|
445
442
|
end
|
443
|
+
|
444
|
+
@c.dataset.meta_def(:columns) {[:id, :x, :y]}
|
446
445
|
end
|
447
446
|
|
448
447
|
it "should be created dynamically" do
|
@@ -469,7 +468,7 @@ describe Sequel::Model, "attribute accessors" do
|
|
469
468
|
|
470
469
|
proc {o.yy?}.should raise_error(NoMethodError)
|
471
470
|
end
|
472
|
-
|
471
|
+
|
473
472
|
it "should not raise for a column not in the dataset, but for which there's a value" do
|
474
473
|
o = @c.new
|
475
474
|
|
@@ -484,9 +483,8 @@ describe Sequel::Model, "attribute accessors" do
|
|
484
483
|
o.xx.should == 123
|
485
484
|
o.yy.should == nil
|
486
485
|
|
487
|
-
proc {o.xx = 3}.
|
486
|
+
proc {o.xx = 3}.should_not raise_error(Sequel::Error)
|
488
487
|
end
|
489
|
-
|
490
488
|
end
|
491
489
|
|
492
490
|
describe Sequel::Model, ".[]" do
|
@@ -533,3 +531,13 @@ describe Sequel::Model, ".[]" do
|
|
533
531
|
/^SELECT \* FROM items WHERE (\(node_id = 3921\) AND \(kind = 201\))|(\(kind = 201\) AND \(node_id = 3921\)) LIMIT 1$/
|
534
532
|
end
|
535
533
|
end
|
534
|
+
|
535
|
+
context "Model#inspect" do
|
536
|
+
setup do
|
537
|
+
@o = Sequel::Model.load(:x => 333)
|
538
|
+
end
|
539
|
+
|
540
|
+
specify "should include the class name and the values" do
|
541
|
+
@o.inspect.should == '#<Sequel::Model @values={:x=>333}>'
|
542
|
+
end
|
543
|
+
end
|
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:
|
4
|
+
version: 0.4.1
|
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-02-
|
12
|
+
date: 2008-02-10 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -44,28 +44,28 @@ files:
|
|
44
44
|
- COPYING
|
45
45
|
- README
|
46
46
|
- Rakefile
|
47
|
-
- spec/hooks_spec.rb
|
48
47
|
- spec/base_spec.rb
|
49
48
|
- spec/caching_spec.rb
|
50
|
-
- spec/
|
51
|
-
- spec/record_spec.rb
|
52
|
-
- spec/spec_helper.rb
|
49
|
+
- spec/hooks_spec.rb
|
53
50
|
- spec/model_spec.rb
|
51
|
+
- spec/plugins_spec.rb
|
52
|
+
- spec/rcov.opts
|
53
|
+
- spec/record_spec.rb
|
54
54
|
- spec/relations_spec.rb
|
55
55
|
- spec/schema_spec.rb
|
56
|
-
- spec/rcov.opts
|
57
|
-
- spec/plugins_spec.rb
|
58
56
|
- spec/spec.opts
|
57
|
+
- spec/spec_helper.rb
|
58
|
+
- spec/validations_spec.rb
|
59
59
|
- lib/sequel_model
|
60
|
-
- lib/sequel_model/
|
60
|
+
- lib/sequel_model/base.rb
|
61
|
+
- lib/sequel_model/caching.rb
|
62
|
+
- lib/sequel_model/hooks.rb
|
63
|
+
- lib/sequel_model/plugins.rb
|
61
64
|
- lib/sequel_model/pretty_table.rb
|
62
65
|
- lib/sequel_model/record.rb
|
63
66
|
- lib/sequel_model/relations.rb
|
64
67
|
- lib/sequel_model/schema.rb
|
65
|
-
- lib/sequel_model/
|
66
|
-
- lib/sequel_model/hooks.rb
|
67
|
-
- lib/sequel_model/base.rb
|
68
|
-
- lib/sequel_model/caching.rb
|
68
|
+
- lib/sequel_model/validations.rb
|
69
69
|
- lib/sequel_model.rb
|
70
70
|
- CHANGELOG
|
71
71
|
has_rdoc: true
|