From 8fd959fa07e421a2e107b8720b37bab5262937dc Mon Sep 17 00:00:00 2001 From: Yas Okada Date: Fri, 27 Jun 2025 00:50:43 +0000 Subject: [PATCH 1/2] replace String#snakecase to StringUtils.snakecase --- lib/soapforce.rb | 1 + lib/soapforce/client.rb | 4 ++-- lib/soapforce/query_result.rb | 2 +- lib/soapforce/result.rb | 2 +- lib/soapforce/sobject.rb | 2 +- lib/soapforce/string_utils.rb | 21 +++++++++++++++++++++ lib/soapforce/version.rb | 2 +- soapforce.gemspec | 1 - 8 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 lib/soapforce/string_utils.rb diff --git a/lib/soapforce.rb b/lib/soapforce.rb index bfc3a57..a69e328 100644 --- a/lib/soapforce.rb +++ b/lib/soapforce.rb @@ -8,6 +8,7 @@ require "soapforce/result" require "soapforce/query_result" require "soapforce/sobject" +require "soapforce/string_utils" module Soapforce diff --git a/lib/soapforce/client.rb b/lib/soapforce/client.rb index 6d1468c..a8524c4 100644 --- a/lib/soapforce/client.rb +++ b/lib/soapforce/client.rb @@ -38,7 +38,7 @@ def initialize(options = {}) @response_tags = lambda { |key| key } else @tag_style = :snakecase - @response_tags = lambda { |key| key.snakecase.to_sym } + @response_tags = lambda { |key| ::Soapforce::StringUtils.snakecase(key).to_sym } end # Override optional Savon attributes @@ -586,7 +586,7 @@ def method_missing(method, *args) def key_name(key) if @tag_style == :snakecase - key.is_a?(Symbol) ? key : key.snakecase.to_sym + key.is_a?(Symbol) ? key : ::Soapforce::StringUtils.snakecase(key).to_sym else if key.to_s.include?('_') camel_key = key.to_s.gsub(/\_(\w{1})/) {|cap| cap[1].upcase } diff --git a/lib/soapforce/query_result.rb b/lib/soapforce/query_result.rb index 2390061..0244a75 100644 --- a/lib/soapforce/query_result.rb +++ b/lib/soapforce/query_result.rb @@ -61,7 +61,7 @@ def method_missing(method, *args, &block) def key_name(key) if @key_type == :symbol - key.is_a?(String) ? key.snakecase.to_sym : key + key.is_a?(String) ? ::Soapforce::StringUtils.snakecase(key).to_sym : key else key.to_s end diff --git a/lib/soapforce/result.rb b/lib/soapforce/result.rb index df01c82..9f9d3d0 100644 --- a/lib/soapforce/result.rb +++ b/lib/soapforce/result.rb @@ -28,7 +28,7 @@ def [](index) elsif @raw_hash.key?(index.to_sym) @raw_hash[index.to_sym] else - @raw_hash[index.snakecase.to_sym] + @raw_hash[::Soapforce::StringUtils.snakecase(index).to_sym] end end end diff --git a/lib/soapforce/sobject.rb b/lib/soapforce/sobject.rb index 5fdd205..dfbc297 100644 --- a/lib/soapforce/sobject.rb +++ b/lib/soapforce/sobject.rb @@ -52,7 +52,7 @@ def method_missing(method, *args, &block) end if string_method =~ /[A-Z+]/ - string_method = string_method.snakecase + string_method = ::Soapforce::StringUtils.snakecase(string_method) end index = string_method.downcase.to_sym diff --git a/lib/soapforce/string_utils.rb b/lib/soapforce/string_utils.rb new file mode 100644 index 0000000..b102484 --- /dev/null +++ b/lib/soapforce/string_utils.rb @@ -0,0 +1,21 @@ +module Soapforce + module StringUtils + # Converts a string to snake case. + # + # @param inputstring [String] The string to be converted to snake case. + # @return [String] A copy of the input string converted to snake case. + # + # copy from nori + # ref: https://github.com/savonrb/nori/pull/102/files + def self.snakecase(inputstring) + str = inputstring.dup + str.gsub!(/::/, '/') + str.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2') + str.gsub!(/([a-z\d])([A-Z])/, '\1_\2') + str.tr!(".", "_") + str.tr!("-", "_") + str.downcase! + str + end + end +end diff --git a/lib/soapforce/version.rb b/lib/soapforce/version.rb index 35e8b39..4473a60 100644 --- a/lib/soapforce/version.rb +++ b/lib/soapforce/version.rb @@ -1,3 +1,3 @@ module Soapforce - VERSION = "0.8.0" + VERSION = "0.8.0.trocco.0.0.1" end diff --git a/soapforce.gemspec b/soapforce.gemspec index 247b95d..ab83abe 100644 --- a/soapforce.gemspec +++ b/soapforce.gemspec @@ -19,7 +19,6 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_runtime_dependency "savon", ">= 2.3.0", '< 3.0.0' - spec.add_runtime_dependency "nori", "2.6.0" spec.add_development_dependency 'rspec', '>= 2.14.0', '< 4.0.0' spec.add_development_dependency 'webmock', '>=2.3.2' From e64086dd18d1be3105e4f862f156a8a1fad535cd Mon Sep 17 00:00:00 2001 From: Yas Okada Date: Fri, 27 Jun 2025 01:11:14 +0000 Subject: [PATCH 2/2] add publish-gem GitHub Actions --- .github/workflows/publish-gem.yml | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/publish-gem.yml diff --git a/.github/workflows/publish-gem.yml b/.github/workflows/publish-gem.yml new file mode 100644 index 0000000..6e2fd28 --- /dev/null +++ b/.github/workflows/publish-gem.yml @@ -0,0 +1,39 @@ +name: Publish Gem + +on: + push: + tags: + - 'v*' + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.1.6 + bundler-cache: true + + - name: Install dependencies + run: bundle install + + - name: Run tests + run: bundle exec rspec + + - name: Build gem + run: gem build soapforce.gemspec + + - name: Publish to GitHub Packages + run: | + mkdir -p ~/.gem + echo "---" > ~/.gem/credentials + echo ":github: Bearer ${{ secrets.GITHUB_TOKEN }}" >> ~/.gem/credentials + chmod 0600 ~/.gem/credentials + gem push --key github --host https://rubygems.pkg.github.com/${{ github.repository_owner }} *.gem + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}