fossil 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/fossil.gemspec +2 -2
- data/lib/sequel/model_patch.rb +17 -2
- data/spec/sequel/model_patch_spec.rb +12 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/fossil.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{fossil}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Patrick Lardin, Daniel Sudol"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-02-03}
|
13
13
|
s.description = %q{Access FOS/betrieve db with this Sequel based orm wrapper}
|
14
14
|
s.email = %q{plardin@xojet.com}
|
15
15
|
s.files = [
|
data/lib/sequel/model_patch.rb
CHANGED
@@ -6,9 +6,24 @@ class Sequel::Model
|
|
6
6
|
plugin :validation_helpers
|
7
7
|
|
8
8
|
# passing in an array of attribute names, fills a hash with values from the model.
|
9
|
+
# can pass in attributes with __ like :passenger__name and the name value will be
|
10
|
+
# delegated to passenger. the delegator is created on the fly.
|
9
11
|
def fill_hash(attributes)
|
10
|
-
attributes.inject({}) do |hash,attribute|
|
11
|
-
|
12
|
+
attributes.inject({}) do |hash, attribute|
|
13
|
+
arr = attribute.to_s.split(/__/)
|
14
|
+
if arr.size > 1
|
15
|
+
attribute = arr.join("_").to_sym
|
16
|
+
# check to see if method_name ( delegator ) exists first to ensure its not created again
|
17
|
+
unless respond_to? attribute
|
18
|
+
# create delegator on the fly
|
19
|
+
method_call = arr.shift
|
20
|
+
arr.each do |next_call|
|
21
|
+
self.class.delegate next_call.to_sym, :to => method_call.to_sym, :prefix => true, :allow_nil => true
|
22
|
+
method_call = method_call + "_" + next_call
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
hash[attribute] = send(attribute) if respond_to? attribute
|
12
27
|
hash
|
13
28
|
end
|
14
29
|
end
|
@@ -15,6 +15,18 @@ describe "Sequel::Model extentions" do
|
|
15
15
|
Dude.first.fill_hash([:doo]).should == {:doo=>1}
|
16
16
|
end
|
17
17
|
|
18
|
+
describe "recognizes __ in method name" do
|
19
|
+
it "and creates delegator only once" do
|
20
|
+
mock.proxy(Dude).delegate(:name, :to => :my_friend, :prefix => true, :allow_nil => true)
|
21
|
+
Dude.first.fill_hash([:my_friend__name,:my_friend__name]).should == {:my_friend_name=>'dans buddy'}
|
22
|
+
end
|
23
|
+
|
24
|
+
it "and creates delegator two levels deep" do
|
25
|
+
mock.proxy(Horse).delegate(:my_friend, :to => :dude, :prefix => true, :allow_nil => true)
|
26
|
+
mock.proxy(Horse).delegate(:name, :to => :dude_my_friend, :prefix => true, :allow_nil => true)
|
27
|
+
Horse.first.fill_hash([:dude__my_friend__name]).should == {:dude_my_friend_name=>'dans buddy'}
|
28
|
+
end
|
29
|
+
end
|
18
30
|
end
|
19
31
|
|
20
32
|
it "can update and save" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fossil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Lardin, Daniel Sudol
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-02-03 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|