Repository navigation
Drop the ActiveSupport dependency and load on Faraday 2 #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,5 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'active_support/core_ext/string' | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are blocked from upgrading because the gem uses a couple of methods to format strings. It's really a huge overkill |
||
|
|
||
| module ActiveCampaign | ||
| # | ||
| # Utility module for manipulating hashes, arrays and values | ||
|
|
@@ -35,7 +33,7 @@ def transform_keys(hash, *new_case) | |
| # @return [Symbol] the transformed key | ||
| # | ||
| def transform_key(key, *new_case) | ||
| key.to_s.public_send(*new_case).to_sym | ||
| inflect(key.to_s, *new_case).to_sym | ||
| end | ||
|
|
||
| # | ||
|
|
@@ -68,5 +66,38 @@ def transform_array(collection, *new_case) | |
| end | ||
| end | ||
| end | ||
|
|
||
| # | ||
| # Changes the case of a string | ||
| # | ||
| # @param [String] string the string to change | ||
| # @param [Symbol] style `:underscore` or `:camelcase` | ||
| # @param [Symbol] first_letter `:upper` or `:lower`, only used by `:camelcase` | ||
| # | ||
| # @return [String] | ||
| # | ||
|
Comment on lines
+70
to
+78
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is all we need to avoid that dependency. This gem has been abandoned for +2 years, at some point it might be a lot easier to simply refactor it into a client we own with a lot fewer moving parts. Leaving that for future adventures. |
||
| def inflect(string, style, first_letter = :upper) | ||
| case style | ||
| when :underscore then underscore(string) | ||
| when :camelcase then camelize(string, first_letter) | ||
| else raise ArgumentError, "unknown case #{style.inspect}" | ||
| end | ||
| end | ||
|
|
||
| # The rules below are the ActiveSupport ones without acronyms or namespace (::) handling. They live here | ||
| # so an application's inflection config can't change the keys sent to the API. | ||
| def underscore(string) | ||
| return string unless /[A-Z-]/.match?(string) | ||
|
|
||
| string | ||
| .gsub(/([A-Z])(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) { "#{Regexp.last_match(1) || Regexp.last_match(2)}_" } | ||
| .tr('-', '_') | ||
| .downcase | ||
| end | ||
|
|
||
| def camelize(string, first_letter = :upper) | ||
| head = first_letter == :lower ? string.sub(/\A\w/, &:downcase) : string.sub(/\A[a-z\d]*/, &:capitalize) | ||
| head.gsub(/_([a-z\d]*)/i) { Regexp.last_match(1).capitalize } | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # The client raises ResourceNotFound on 404, and cleanup hooks often delete a | ||
| # resource the example itself already deleted. | ||
|
Comment on lines
+3
to
+4
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We made this change on the fork long time ago and never fixed specs |
||
| module Cleanup | ||
| def cleanup | ||
| yield | ||
| rescue ActiveCampaign::ResourceNotFound | ||
| nil | ||
| end | ||
| end | ||
|
|
||
| RSpec.configure do |config| | ||
| config.include Cleanup | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has been broken forever