Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #35 from rightscale/yellow_13_08_acu104862_remove_…

…activesupport_dependency

acu104862 remove activesupport dependency and replace inflector
  • Loading branch information...
commit d0e26468ba92916fe8b9dcc25b2368bcbf5311f4 2 parents 83b0b36 + 9d2e96d
Magne Land authored
View
33 lib/right_api_client/helper.rb
@@ -1,5 +1,3 @@
-require 'active_support/inflector'
-
# Methods shared by the Client, Resource and Resources.
module RightApi::Helper
# Some resource_types are not the same as the last thing in the URL, put these here to ensure consistency
@@ -154,8 +152,19 @@ def insert_in_path(path, term)
# Helper method that checks whether the string is singular
def is_singular?(str)
- return true if ['data'].include?(str.to_s)
- (str.to_s)[-1, 1] != 's' # use legacy syntax for Ruby 1.8.7
+ test_str = str.to_s
+ return true if ['data'].include?(test_str)
+
+ case test_str
+ when "audit_entry"
+ return true
+ when "ip_address"
+ return true
+ when "process"
+ return true
+ else
+ (test_str)[-1, 1] != 's' # use legacy syntax for Ruby 1.8.7
+ end
end
# Does not modify links
@@ -176,9 +185,23 @@ def get_and_delete_href_from_links(links)
return nil
end
+ # HACK: instead of pulling in activesupport gem, just hardcode some words
+ def simple_singularize(word)
+ case word
+ when "audit_entries"
+ "audit_entry"
+ when "ip_addresses"
+ "ip_address"
+ when "processes"
+ "process"
+ else
+ word.chop
+ end
+ end
+
# Will not change obj
def get_singular(obj)
- obj.to_s.singularize
+ simple_singularize(obj.to_s.downcase)
end
# rest client does not post params correctly for all the keys whose values are arrays of hashes
View
1  right_api_client.gemspec
@@ -26,6 +26,5 @@ fine details involved in making HTTP calls and translating their responses.
s.add_development_dependency 'rspec', '2.9.0'
s.add_development_dependency 'flexmock', '0.8.7'
s.add_development_dependency 'simplecov', '0.4.2'
- s.add_development_dependency 'activesupport', '< 4.0.0' # this avoids Gem::InstallError: activesupport requires Ruby version >= 1.9.3.
s.add_development_dependency 'bundler'
end
View
1  spec/functional/client_spec.rb
@@ -88,6 +88,7 @@
@client.get_singular('deployments').should == 'deployment'
@client.get_singular('audit_entries').should == 'audit_entry'
@client.get_singular('processes').should == 'process'
+ @client.get_singular('ip_addresses').should == 'ip_address'
end
it "returns the resource when calling #resource(href)" do
View
38 spec/unit/helper_spec.rb
@@ -3,26 +3,36 @@
describe RightApi::Helper do
+ API_MEDIA_TYPES = %w{audit_entry ip_address process server}
+
+ context "#is_singular?" do
+ API_MEDIA_TYPES.each do |media_type|
+ it "should identify media type #{media_type} as singular" do
+ is_singular?(media_type).should == true
+ end
+ end
+ end
+
context "#fix_array_of_hashes" do
it "fixes all the keys that have the value as array of hashes" do
res = fix_array_of_hashes(
- 'a' => '1',
- 'b' => [1, 2, 3],
- 'c' => {1 => 2, 3 => 4},
- 'd' => [
- {5 => 6, 7 => 8},
- {9 => 10, 11 => 12}
- ]
+ 'a' => '1',
+ 'b' => [1, 2, 3],
+ 'c' => {1 => 2, 3 => 4},
+ 'd' => [
+ {5 => 6, 7 => 8},
+ {9 => 10, 11 => 12}
+ ]
)
res.should == {
- 'a' => '1',
- 'b' => [1, 2, 3],
- 'c' => {1 => 2, 3 => 4},
- 'd[]' => [
- {5 => 6, 7 => 8},
- {9 => 10, 11 => 12}
- ]
+ 'a' => '1',
+ 'b' => [1, 2, 3],
+ 'c' => {1 => 2, 3 => 4},
+ 'd[]' => [
+ {5 => 6, 7 => 8},
+ {9 => 10, 11 => 12}
+ ]
}
end

2 comments on commit d0e2646

@rightscale-ci
Collaborator

RS-COMPLIANCE: COMPLIANCE-AUTHORIZATION-PASS Build: #28604(2013-06-26_01-00-01), repo: right_api_client, branch/tag: master, sha: d0e2646, status: PASS, reason: Master/release branch and pusher is on the whitelist.

@rightscale-ci
Collaborator

RS-COMPLIANCE: COMPLIANCE-COMMITMESSAGE-PASS Build: #28604(2013-06-26_01-00-01), repo: right_api_client, branch/tag: master, sha: d0e2646, status: PASS, reason: Was a merge commit

Please sign in to comment.
Something went wrong with that request. Please try again.