Skip to content

Commit

Permalink
Merge pull request #355 from eatwithforks/jylee/underscore
Browse files Browse the repository at this point in the history
make api_service method work
  • Loading branch information
cben authored Mar 10, 2020
2 parents 84f0c18 + 74e6699 commit 5737370
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
6 changes: 5 additions & 1 deletion lib/kubeclient/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,12 @@ def define_entity_methods
end
# rubocop:enable Metrics/BlockLength

# Inspired by https://stackoverflow.com/questions/1509915/converting-camel-case-to-underscore-case-in-ruby
def self.underscore_entity(entity_name)
entity_name.gsub(/([a-z])([A-Z])/, '\1_\2').downcase
entity_name
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') # ABCd -> AB_Cd
.gsub(/([a-z])([A-Z])/, '\1_\2') # AbcD -> Abc_D
.downcase
end

def create_rest_client(path = nil)
Expand Down
23 changes: 7 additions & 16 deletions test/test_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,13 @@ def test_underscore_entity
Image image
ImageStream image_stream
dogstatsd dogstatsd
lowerCamelUPPERCase lower_camel_uppercase
HTTPAPISpecBinding httpapispec_binding
APIGroup apigroup
APIGroupList apigroup_list
APIResourceList apiresource_list
APIService apiservice
APIServiceList apiservice_list
APIVersions apiversions
OAuthAccessToken oauth_access_token
OAuthAccessTokenList oauth_access_token_list
OAuthAuthorizeToken oauth_authorize_token
OAuthAuthorizeTokenList oauth_authorize_token_list
OAuthClient oauth_client
OAuthClientAuthorization oauth_client_authorization
OAuthClientAuthorizationList oauth_client_authorization_list
OAuthClientList oauth_client_list
lowerCamelUPPERCase lower_camel_upper_case
HTTPAPISpecBinding httpapi_spec_binding
APIService api_service
OAuthAccessToken o_auth_access_token
OAuthAuthorizeToken o_auth_authorize_token
OAuthClient o_auth_client
OAuthClientAuthorization o_auth_client_authorization
].each_slice(2) do |kind, expected_underscore|
underscore = Kubeclient::ClientMixin.underscore_entity(kind)
assert_equal(underscore, expected_underscore)
Expand Down

0 comments on commit 5737370

Please sign in to comment.