kelredd-resourceful 0.7.10 → 0.7.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,19 +15,20 @@ module Resourceful
15
15
  config ||= {}
16
16
  raise ArgumentError, "has_many_resourceful requires a :class_name option to be specified" unless config[:class_name]
17
17
  class_name = config.delete(:class_name).to_s
18
+ find_method_name = config.delete(:method).to_s || 'find'
18
19
  force = config.delete(:force) || true
19
20
  define_method(name) do
20
21
  klass = class_name.resourceful_constantize
21
22
  raise ArgumentError, "has_many_resourceful :class_name '#{class_name}' is not defined" if klass.nil?
22
- unless klass.respond_to?(:find)
23
- raise NotImplementedError, "has_many_resourceful expects #{klass} to be findable (ie mixin the Findable helper)"
23
+ unless klass.respond_to?(find_method_name)
24
+ raise NotImplementedError, "has_many_resourceful expects #{klass} to implement a Findable method named '#{find_method_name}'"
24
25
  end
25
26
  fk = config.delete(:foreign_key) || "#{self.class.name.demodulize.underscore}_id"
26
27
  fk_method = config.delete(:foreign_key_method) || 'id'
27
28
  config[fk] = self.send(fk_method)
28
29
  instance_variable_get("@#{clean_name}") || \
29
30
  instance_variable_set("@#{clean_name}", \
30
- klass.find(:all, config, force)
31
+ klass.send(find_method_name, :all, config, force)
31
32
  )
32
33
  end
33
34
  end
@@ -38,6 +39,7 @@ module Resourceful
38
39
  raise ArgumentError, "belongs_to_resourceful requires a :class_name option to be specified" unless config[:class_name]
39
40
  class_name = config.delete(:class_name).to_s
40
41
  foreign_key = config.delete(:foreign_key) || "#{clean_name}_id"
42
+ find_method_name = config.delete(:method).to_s || 'find'
41
43
  force = config.delete(:force) || true
42
44
  define_method(name) do
43
45
  klass = class_name.resourceful_constantize
@@ -45,8 +47,8 @@ module Resourceful
45
47
  unless self.respond_to?(foreign_key)
46
48
  raise ArgumentError, "belongs_to_resourceful requires a '#{foreign_key}' method defined to return the foreign_key"
47
49
  end
48
- unless klass.respond_to?(:find)
49
- raise NotImplementedError, "belongs_to_resourceful expects #{klass} to be findable (ie mixin the Findable helper)"
50
+ unless klass.respond_to?(find_method_name)
51
+ raise NotImplementedError, "belongs_to_resourceful expects #{klass} to implement a Findable method named '#{find_method_name}'"
50
52
  end
51
53
  fk = self.send(foreign_key)
52
54
  if fk.nil? || (fk.respond_to?('empty?') && fk.empty?)
@@ -54,7 +56,7 @@ module Resourceful
54
56
  else
55
57
  instance_variable_get("@#{clean_name}") || \
56
58
  instance_variable_set("@#{clean_name}", \
57
- klass.find(fk, config, force)
59
+ klass.send(find_method_name, fk, config, force)
58
60
  )
59
61
  end
60
62
  end
@@ -15,19 +15,20 @@ module Resourceful
15
15
  config ||= {}
16
16
  raise ArgumentError, "has_many requires a :class option to be specified" unless config[:class]
17
17
  class_name = config.delete(:class).to_s
18
+ find_method_name = config.delete(:method).to_s || 'find'
18
19
  force = config.delete(:force) || true
19
20
  define_method(name) do
20
21
  klass = self.class.get_namespaced_klass(class_name)
21
22
  raise ArgumentError, "has_many :class '#{class_name}' is not defined in any given namespaces" if klass.nil?
22
- unless klass.respond_to?(:find)
23
- raise NotImplementedError, "has_many expects #{klass} to be findable (ie mixin the Findable helper)"
23
+ unless klass.respond_to?(find_method_name)
24
+ raise NotImplementedError, "has_many expects #{klass} to implement a Findable method named '#{find_method_name}'"
24
25
  end
25
26
  fk = config.delete(:foreign_key) || "#{self.class.name.demodulize.underscore}_id"
26
27
  fk_method = config.delete(:foreign_key_method) || 'id'
27
28
  config[fk] = self.send(fk_method)
28
29
  instance_variable_get("@#{clean_name}") || \
29
30
  instance_variable_set("@#{clean_name}", \
30
- klass.find(:all, config, force)
31
+ klass.send(find_method_name, :all, config, force)
31
32
  )
32
33
  end
33
34
  end
@@ -38,6 +39,7 @@ module Resourceful
38
39
  raise ArgumentError, "belongs_to requires a :class option to be specified" unless config[:class]
39
40
  class_name = config.delete(:class).to_s
40
41
  foreign_key = config.delete(:foreign_key) || "#{clean_name}_id"
42
+ find_method_name = config.delete(:method).to_s || 'find'
41
43
  force = config.delete(:force) || true
42
44
  define_method(name) do
43
45
  klass = self.class.get_namespaced_klass(class_name)
@@ -45,8 +47,8 @@ module Resourceful
45
47
  unless self.respond_to?(foreign_key)
46
48
  raise ArgumentError, "belongs_to requires a '#{foreign_key}' method defined to return the foreign_key"
47
49
  end
48
- unless klass.respond_to?(:find)
49
- raise NotImplementedError, "belongs_to expects #{klass} to be findable (ie mixin the Findable helper)"
50
+ unless klass.respond_to?(find_method_name)
51
+ raise NotImplementedError, "belongs_to expects #{klass} to implement a Findable method named '#{find_method_name}'"
50
52
  end
51
53
  fk = self.send(foreign_key)
52
54
  if fk.nil? || (fk.respond_to?('empty?') && fk.empty?)
@@ -54,7 +56,7 @@ module Resourceful
54
56
  else
55
57
  instance_variable_get("@#{clean_name}") || \
56
58
  instance_variable_set("@#{clean_name}", \
57
- klass.find(fk, config, force)
59
+ klass.send(find_method_name, fk, config, force)
58
60
  )
59
61
  end
60
62
  end
@@ -3,7 +3,7 @@ module Resourceful
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 7
6
- TINY = 10
6
+ TINY = 13
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kelredd-resourceful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.10
4
+ version: 0.7.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-21 00:00:00 -07:00
12
+ date: 2009-09-23 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency