fossil 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.5
1
+ 0.3.6
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.5"
8
+ s.version = "0.3.6"
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-02-03}
12
+ s.date = %q{2010-02-05}
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 = [
@@ -5,28 +5,38 @@ class Sequel::Model
5
5
  self.use_transactions=false
6
6
  plugin :validation_helpers
7
7
 
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.
8
+ # Passing in an array of attribute / method names, fills a hash with values from
9
+ # the model. Can pass in attributes with __ like :passenger__name and the 'name'
10
+ # value will be delegated to 'passenger' with the delegator being created on the fly.
11
11
  def fill_hash(attributes)
12
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
- unless respond_to?(method_call + "_" + next_call)
22
- self.class.delegate next_call.to_sym, :to => method_call.to_sym, :prefix => true, :allow_nil => true
23
- end
24
- method_call = method_call + "_" + next_call
25
- end
13
+ attribute_name = attribute.to_s.gsub('__','_').to_sym
14
+ generate_delegator(attribute) unless respond_to? attribute_name
15
+ hash[attribute_name] = send(attribute_name) if respond_to? attribute_name
16
+ hash
17
+ end
18
+ end
19
+
20
+ def method_missing(method, *args, &block)
21
+ if method.to_s.split(/__/).size > 1
22
+ generate_delegator(method)
23
+ else
24
+ super
25
+ end
26
+ end
27
+
28
+ def generate_delegator(method)
29
+ arr = method.to_s.split(/__/)
30
+ # check to see if method_name ( delegator ) exists first to ensure its not created again
31
+ unless respond_to? arr.join('_')
32
+ # create delegator on the fly
33
+ method_call = arr.shift
34
+ arr.each do |next_call|
35
+ unless respond_to?(method_call + "_" + next_call)
36
+ self.class.delegate next_call.to_sym, :to => method_call.to_sym, :prefix => true, :allow_nil => true
26
37
  end
38
+ method_call = method_call + "_" + next_call
27
39
  end
28
- hash[attribute] = send(attribute) if respond_to? attribute
29
- hash
30
40
  end
31
41
  end
32
42
 
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.5
4
+ version: 0.3.6
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-02-03 00:00:00 -08:00
12
+ date: 2010-02-05 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency