api_client 0.3.2 → 0.3.3
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.
data/lib/api_client.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
module ApiClient
|
2
|
+
module Resource
|
3
|
+
class NameResolver
|
4
|
+
def self.resolve(ruby_path)
|
5
|
+
new(ruby_path).resolve
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :name
|
9
|
+
|
10
|
+
def initialize(name)
|
11
|
+
@name = name
|
12
|
+
end
|
13
|
+
|
14
|
+
def resolve
|
15
|
+
select_last_item
|
16
|
+
underscorize
|
17
|
+
lowercase
|
18
|
+
name
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def select_last_item
|
23
|
+
@name = @name.split('::').last
|
24
|
+
end
|
25
|
+
|
26
|
+
#Inspired by ActiveSupport::Inflector#underscore
|
27
|
+
def underscorize
|
28
|
+
@name.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
|
29
|
+
@name.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
30
|
+
end
|
31
|
+
|
32
|
+
def lowercase
|
33
|
+
@name.downcase!
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/api_client/version.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ApiClient::Resource::NameResolver do
|
4
|
+
describe '.resolve' do
|
5
|
+
subject { described_class }
|
6
|
+
|
7
|
+
it 'changes My::Namespace::MyResouce to my_resource' do
|
8
|
+
subject.resolve('My::Namespace::MyResource').should == 'my_resource'
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'changes Resource to resource' do
|
12
|
+
subject.resolve('Resource').should == 'resource'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'changes My::Resource to resoure' do
|
16
|
+
subject.resolve('My::Resource').should == 'resource'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- lib/api_client/mixins/instantiation.rb
|
97
97
|
- lib/api_client/mixins/scoping.rb
|
98
98
|
- lib/api_client/resource/base.rb
|
99
|
+
- lib/api_client/resource/name_resolver.rb
|
99
100
|
- lib/api_client/resource/scope.rb
|
100
101
|
- lib/api_client/scope.rb
|
101
102
|
- lib/api_client/utils.rb
|
@@ -114,6 +115,7 @@ files:
|
|
114
115
|
- spec/api_client/connection/request/logger_spec.rb
|
115
116
|
- spec/api_client/connection/request/oauth_spec.rb
|
116
117
|
- spec/api_client/resource/base_spec.rb
|
118
|
+
- spec/api_client/resource/name_spec.rb
|
117
119
|
- spec/api_client/resource/scope_spec.rb
|
118
120
|
- spec/api_client/scope_spec.rb
|
119
121
|
- spec/api_client/utils_spec.rb
|
@@ -159,6 +161,7 @@ test_files:
|
|
159
161
|
- spec/api_client/connection/request/logger_spec.rb
|
160
162
|
- spec/api_client/connection/request/oauth_spec.rb
|
161
163
|
- spec/api_client/resource/base_spec.rb
|
164
|
+
- spec/api_client/resource/name_spec.rb
|
162
165
|
- spec/api_client/resource/scope_spec.rb
|
163
166
|
- spec/api_client/scope_spec.rb
|
164
167
|
- spec/api_client/utils_spec.rb
|