deals_with 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
@@ -9,8 +9,15 @@ module DealsWith
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def deals_with(model_name, options={}, &scope_proc)
|
12
|
-
|
13
|
-
model_class =
|
12
|
+
tmp_model_name = model_name.to_s.classify
|
13
|
+
model_class = nil
|
14
|
+
begin
|
15
|
+
model_class = tmp_model_name.constantize
|
16
|
+
rescue
|
17
|
+
tmp_model_name = model_name.to_s.camelize
|
18
|
+
model_class = (tmp_model_name.constantize rescue nil)
|
19
|
+
end
|
20
|
+
model_name = tmp_model_name
|
14
21
|
|
15
22
|
unless deals_with_models[model_name]
|
16
23
|
|
@@ -31,8 +38,8 @@ module DealsWith
|
|
31
38
|
def generate_resource_methods(model_name)
|
32
39
|
short_name = model_name.gsub(/.+[:]{2}/, '')
|
33
40
|
class_eval %{
|
34
|
-
def #{short_name.
|
35
|
-
@#{short_name.
|
41
|
+
def #{short_name.pluralize.underscore}
|
42
|
+
@#{short_name.pluralize.underscore} ||=
|
36
43
|
self.class.deals_with_models[#{model_name.inspect}].all(self)
|
37
44
|
end
|
38
45
|
def #{short_name.underscore}
|
data/lib/deals_with/resource.rb
CHANGED
@@ -13,7 +13,7 @@ module DealsWith
|
|
13
13
|
|
14
14
|
def initialize(controller_class, model_name, options={}, &scope_proc)
|
15
15
|
@controller_class = controller_class
|
16
|
-
@model_name = model_name.to_s
|
16
|
+
@model_name = model_name.to_s
|
17
17
|
@options = options
|
18
18
|
@scope_proc = scope_proc
|
19
19
|
end
|
@@ -26,8 +26,12 @@ module DealsWith
|
|
26
26
|
|
27
27
|
def parents
|
28
28
|
@parents ||= model_class.reflect_on_all_associations(:belongs_to).collect do |reflection|
|
29
|
-
|
30
|
-
|
29
|
+
begin
|
30
|
+
if reflection.klass.instance_methods.include? model_name.gsub(/.+[:]{2}/, '').tableize
|
31
|
+
controller_class.deals_with_models[reflection.class_name]
|
32
|
+
end
|
33
|
+
rescue
|
34
|
+
nil
|
31
35
|
end
|
32
36
|
end.compact
|
33
37
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deals_with
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
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:
|
12
|
+
date: 2010-01-05 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|