kelredd-resourceful 0.7.3 → 0.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -81,6 +81,36 @@ module Resourceful
81
81
  end
82
82
  end
83
83
  end
84
+
85
+ unless "".respond_to?(:camelize)
86
+ # "active_record/errors".camelize # => "ActiveRecord::Errors"
87
+ def camelize(first_letter_in_uppercase = true)
88
+ if first_letter_in_uppercase
89
+ self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
90
+ else
91
+ self[0..0].downcase + camelize(self)[1..-1]
92
+ end
93
+ end
94
+
95
+ end
96
+
97
+ unless "".respond_to?(:underscore)
98
+ # "ActiveRecord::Errors".underscore # => active_record/errors
99
+ def underscore
100
+ self.to_s.gsub(/::/, '/').
101
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
102
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
103
+ tr("-", "_").
104
+ downcase
105
+ end
106
+ end
107
+
108
+ unless "".respond_to?(:demodulize)
109
+ # "ActiveRecord::CoreExtensions::String::Inflections".demodulize # => "Inflections"
110
+ def demodulize
111
+ self.to_s.gsub(/^.*::/, '')
112
+ end
113
+ end
84
114
 
85
115
  end
86
116
  end
@@ -22,7 +22,7 @@ module Resourceful
22
22
  unless klass.respond_to?(:find)
23
23
  raise NotImplementedError, "has_many expects #{klass} to be findable (ie mixin the Findable helper)"
24
24
  end
25
- fk = config.delete(:foreign_key) || "#{self.class.name.downcase.to_s.gsub(/^.*::/, '')}_id"
25
+ fk = config.delete(:foreign_key) || "#{self.class.name.demodulize.underscore}_id"
26
26
  fk_method = config.delete(:foreign_key_method) || 'id'
27
27
  config[fk] = self.send(fk_method)
28
28
  instance_variable_get("@#{clean_name}") || \
@@ -30,7 +30,7 @@ module Resourceful
30
30
 
31
31
  def findable_search
32
32
  # defaults to non namespaced downcased name of the class
33
- self.name.downcase.to_s.gsub(/^.*::/, '')
33
+ self.name.demodulize.underscore.to_s.gsub(/^.*::/, '')
34
34
  end
35
35
 
36
36
  end
@@ -14,9 +14,7 @@ module Resourceful
14
14
  :force => force,
15
15
  :on_response => block
16
16
  }
17
- result = super(path, opts)
18
- hsh_keys = search.kind_of?(String) ? search.split(/\s+/) : nil
19
- new(!hsh_keys.nil? && !hsh_keys.empty? && result.respond_to?(:get_value) ? result.get_value(hsh_keys) : result)
17
+ new(get_result_data(super(path, opts), search))
20
18
  end
21
19
  def self.get_collection(path, params, search=nil, force=false, &block)
22
20
  opts = {
@@ -25,9 +23,8 @@ module Resourceful
25
23
  :force => force,
26
24
  :on_response => block
27
25
  }
28
- hsh_keys = search.kind_of?(String) ? search.split(/\s+/) : nil
29
26
  super(path, opts) do |data|
30
- data.collect{|item| !hsh_keys.nil? && !hsh_keys.empty? && item.respond_to?(:get_value) ? item.get_value(hsh_keys) : item}
27
+ data.collect {|item| get_result_data(item, search) }
31
28
  end
32
29
  end
33
30
 
@@ -38,6 +35,11 @@ module Resourceful
38
35
 
39
36
  protected
40
37
 
38
+ def self.get_result_data(result, search)
39
+ hsh_keys = search.kind_of?(String) ? search.split(/\s+/) : nil
40
+ result_data = !hsh_keys.nil? && !hsh_keys.empty? && result.respond_to?(:get_value) ? result.get_value(hsh_keys) || result : result
41
+ end
42
+
41
43
  def self.format
42
44
  Resourceful::Resource::Json.to_s
43
45
  end
@@ -14,7 +14,8 @@ module Resourceful
14
14
  :force => force,
15
15
  :on_response => block
16
16
  }
17
- new(super(path, opts).search(search))
17
+ data = super(path, opts)
18
+ new(data.search(search) || data)
18
19
  end
19
20
  def self.get_collection(path, params, search, force=false, &block)
20
21
  opts = {
@@ -24,7 +25,7 @@ module Resourceful
24
25
  :on_response => block
25
26
  }
26
27
  super(path, opts) do |data|
27
- data.search(search)
28
+ data.search(search) || data
28
29
  end
29
30
  end
30
31
 
@@ -3,7 +3,7 @@ module Resourceful
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 7
6
- TINY = 3
6
+ TINY = 4
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.3
4
+ version: 0.7.4
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-12 00:00:00 -07:00
12
+ date: 2009-09-14 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -111,7 +111,6 @@ files:
111
111
  - lib/resourceful.rb
112
112
  has_rdoc: false
113
113
  homepage: ""
114
- licenses:
115
114
  post_install_message:
116
115
  rdoc_options:
117
116
  - --main
@@ -133,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
132
  requirements: []
134
133
 
135
134
  rubyforge_project:
136
- rubygems_version: 1.3.5
135
+ rubygems_version: 1.2.0
137
136
  signing_key:
138
137
  specification_version: 3
139
138
  summary: A ruby gem to abstract web resource handling.