api_client 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
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.4.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -112,6 +112,7 @@ files:
|
|
112
112
|
- lib/api_client/mixins/instantiation.rb
|
113
113
|
- lib/api_client/mixins/scoping.rb
|
114
114
|
- lib/api_client/resource/base.rb
|
115
|
+
- lib/api_client/resource/name_resolver.rb
|
115
116
|
- lib/api_client/resource/scope.rb
|
116
117
|
- lib/api_client/scope.rb
|
117
118
|
- lib/api_client/utils.rb
|
@@ -130,6 +131,7 @@ files:
|
|
130
131
|
- spec/api_client/connection/request/logger_spec.rb
|
131
132
|
- spec/api_client/connection/request/oauth_spec.rb
|
132
133
|
- spec/api_client/resource/base_spec.rb
|
134
|
+
- spec/api_client/resource/name_spec.rb
|
133
135
|
- spec/api_client/resource/scope_spec.rb
|
134
136
|
- spec/api_client/scope_spec.rb
|
135
137
|
- spec/api_client/utils_spec.rb
|
@@ -175,6 +177,7 @@ test_files:
|
|
175
177
|
- spec/api_client/connection/request/logger_spec.rb
|
176
178
|
- spec/api_client/connection/request/oauth_spec.rb
|
177
179
|
- spec/api_client/resource/base_spec.rb
|
180
|
+
- spec/api_client/resource/name_spec.rb
|
178
181
|
- spec/api_client/resource/scope_spec.rb
|
179
182
|
- spec/api_client/scope_spec.rb
|
180
183
|
- spec/api_client/utils_spec.rb
|