simonmenke-deals_with 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,12 +10,14 @@ module DealsWith
10
10
 
11
11
  def deals_with(model_name, options={}, &scope_proc)
12
12
  model_name = model_name.to_s.classify
13
- model_class = model_name.constantize
13
+ model_class = (model_name.constantize rescue nil)
14
14
 
15
15
  unless deals_with_models[model_name]
16
16
 
17
- model_class.reflect_on_all_associations(:belongs_to).each do |reflection|
18
- deals_with(reflection.class_name)
17
+ if model_class
18
+ model_class.reflect_on_all_associations(:belongs_to).each do |reflection|
19
+ deals_with(reflection.class_name)
20
+ end
19
21
  end
20
22
 
21
23
  deals_with_models[model_name] = DealsWith::Resource.new(self,
@@ -26,7 +26,7 @@ module DealsWith
26
26
 
27
27
  def parents
28
28
  @parents ||= model_class.reflect_on_all_associations(:belongs_to).collect do |reflection|
29
- if reflection.klass.instance_methods.include? model_name.tableize
29
+ if reflection.klass.instance_methods.include? model_name.gsub(/.+[:]{2}/, '').tableize
30
30
  controller_class.deals_with_models[reflection.class_name]
31
31
  end
32
32
  end.compact
@@ -40,11 +40,11 @@ module DealsWith
40
40
  base = nil
41
41
  parents.each do |resource|
42
42
  if resource.can_find?(controller)
43
- base = controller.send(resource.model_name.underscore)
43
+ base = controller.send(resource.model_name.gsub(/.+[:]{2}/, '').underscore)
44
44
  break
45
45
  end
46
46
  end
47
- base = base.send(model_name.tableize) if base
47
+ base = base.send(model_name.gsub(/.+[:]{2}/, '').tableize) if base
48
48
  base ||= model_class
49
49
  base = @scope_proc.call(base) if @scope_proc
50
50
  base
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simonmenke-deals_with
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Menke
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-26 00:00:00 -07:00
12
+ date: 2009-09-10 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15