From 8f5455fa5cd453720cd30b6acbc196528df58a0a Mon Sep 17 00:00:00 2001 From: Sergey Nebolsin Date: Sun, 11 Oct 2020 16:38:26 +0300 Subject: [PATCH 1/6] Cleanup gem spec, fix build warnings --- Gemfile | 12 +++++++++--- README.md | 6 ++++-- xdr.gemspec | 38 +++++++++++++++++++++----------------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/Gemfile b/Gemfile index b811483..6dd363c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,10 @@ -source 'https://rubygems.org' +source "https://rubygems.org" -# Specify your gem's dependencies in xdr.gemspec -gemspec +gemspec development_group: :test + +group :development do + gem "break" + gem "guard-rspec" + gem "pry" + gem "yard" +end diff --git a/README.md b/README.md index 3d86fa5..c4da561 100644 --- a/README.md +++ b/README.md @@ -95,9 +95,11 @@ all of it's children by calling `load_all!` on the module. ## Code generation -ruby-xdr by itself does not have any ability to parse XDR IDL files and produce a parser for your custom data types. Instead, that is the responsibility of [xdrgen](http://github.com/stellar/xdrgen). xdrgen will take your .x files and produce a set of ruby files that target this library to allow for your own custom types. +ruby-xdr by itself does not have any ability to parse XDR IDL files and produce a parser for your custom +data types. Instead, that is the responsibility of [xdrgen](http://github.com/stellar/xdrgen). `xdrgen` will +take your `.x` files and produce a set of ruby files that target this library to allow for your own custom types. -See [ruby-stellar-base](http://github.com/stellar/ruby-stellar-base) for an example (check out the generated directory) +See [ruby-stellar-base](http://github.com/astroband/ruby-stellar-sdk/tree/master/base/generated) for an example. ## Contributing diff --git a/xdr.gemspec b/xdr.gemspec index 58a147e..7ccb8b0 100644 --- a/xdr.gemspec +++ b/xdr.gemspec @@ -1,28 +1,32 @@ -# coding: utf-8 -lib = File.expand_path('../lib', __FILE__) -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'xdr/version' +# frozen_string_literals: true +require_relative "lib/xdr/version" Gem::Specification.new do |spec| spec.name = "xdr" spec.version = XDR::VERSION spec.authors = ["Scott Fleckenstein"] spec.email = ["scott@stellar.org"] - spec.summary = %q{XDR Helper Library} + spec.summary = "XDR Helper Library" spec.homepage = "https://github.com/stellar/ruby-xdr" - spec.license = "Apache 2.0" spec.required_ruby_version = '>= 2.2.0' + spec.license = "Apache-2.0" - spec.files = `git ls-files -z`.split("\x0") - spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } - spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) - spec.require_paths = ["lib"] - spec.add_dependency "activesupport", ">= 5.2.0" - spec.add_dependency "activemodel", ">= 5.2.0" + spec.files = Dir["lib/**/*"] + spec.extra_rdoc_files += Dir["README*", "LICENSE*", "CHANGELOG*"] + spec.bindir = "exe" - spec.add_development_dependency "bundler", "~> 2" - spec.add_development_dependency "rake", "~> 10.0" - spec.add_development_dependency "rspec", "~> 3.1" - spec.add_development_dependency "guard-rspec" - spec.add_development_dependency "simplecov" + spec.metadata = { + "bug_tracker_uri" => "https://github.com/stellar/ruby-xdr/issues", + "changelog_uri" => "https://github.com/stellar/ruby-xdr/blob/v#{spec.version}/CHANGELOG.md", + "documentation_uri" => "https://rubydoc.info/gems/xdr/#{spec.version}/", + "source_code_uri" => "https://github.com/stellar/ruby-xdr/tree/v#{spec.version}" + } + + + spec.add_dependency "activesupport", ">= 4.2", "< 7.0" + spec.add_dependency "activemodel", ">= 4.2", "< 7.0" + + spec.add_development_dependency "rake", "~> 13.0" + spec.add_development_dependency "rspec", "~> 3.0" + spec.add_development_dependency "simplecov", "~> 0.19" end From 43377c2d9a4ddc95d1d16a3f660406d03a019a0e Mon Sep 17 00:00:00 2001 From: Sergey Nebolsin Date: Sun, 11 Oct 2020 16:38:26 +0300 Subject: [PATCH 2/6] Drop support for Ruby 2.2, 2.3, 2.4 The support for these Ruby versions has ended long time ago, with Ruby 2.4 hitting an EOL in April, 2020: https://www.ruby-lang.org/en/news/2020/04/05/support-of-ruby-2-4-has-ended/ So we're dropping the support for Ruby < 2.5 while adding all currently supported versions into Travis build matrix. --- .travis.yml | 24 ++++++++++++++++++++++-- xdr.gemspec | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index e68c2d9..58b5ed6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,27 @@ +version: ~> 1.0 + +dist: focal +os: linux +virt: lxd + language: ruby +cache: +- bundler + +env: +- JRUBY_OPTS="--debug" rvm: -- 2.7.0 - jruby +- 2.7 +- 2.6 +- 2.5 + +before_install: +- yes | gem update --system --force +- bundle config set without 'development debug' + notifications: slack: - secure: fXYggrDRoLB/4yvyW0kWwyrV5yWa/GC0btPyGu7Hx6ZOaXDC+ejiXSfx7nRyY+uZBs5UF12O4gkUXwBbnWDT5JtQRxzZd5s0cyeGQfAakALexI+FuR2jDcV1prCCaYI4IYoUt61MlfDmuCYVm8hGZ3qsgk/GPHHPnZ8a1FBd2ls= + rooms: + - secure: fXYggrDRoLB/4yvyW0kWwyrV5yWa/GC0btPyGu7Hx6ZOaXDC+ejiXSfx7nRyY+uZBs5UF12O4gkUXwBbnWDT5JtQRxzZd5s0cyeGQfAakALexI+FuR2jDcV1prCCaYI4IYoUt61MlfDmuCYVm8hGZ3qsgk/GPHHPnZ8a1FBd2ls= + - secure: Q040tRLdHrElwYAcDkIBkuDFsF7Fql/QcJT9opMfMOUKkKNNXdCts911vhROu3gbgRrfvngPvza0iDNdRETmJM5lyrFw6IQp9FkrDInHDlymwwFx62bmtk4DE56CkNfgnmpKQH0hSmIipJcHYqgkCzSCv9fxzcX5wMO9yl5/Dao= diff --git a/xdr.gemspec b/xdr.gemspec index 7ccb8b0..bbd861d 100644 --- a/xdr.gemspec +++ b/xdr.gemspec @@ -8,7 +8,6 @@ Gem::Specification.new do |spec| spec.email = ["scott@stellar.org"] spec.summary = "XDR Helper Library" spec.homepage = "https://github.com/stellar/ruby-xdr" - spec.required_ruby_version = '>= 2.2.0' spec.license = "Apache-2.0" spec.files = Dir["lib/**/*"] @@ -22,6 +21,7 @@ Gem::Specification.new do |spec| "source_code_uri" => "https://github.com/stellar/ruby-xdr/tree/v#{spec.version}" } + spec.required_ruby_version = ">= 2.4.0" spec.add_dependency "activesupport", ">= 4.2", "< 7.0" spec.add_dependency "activemodel", ">= 4.2", "< 7.0" From e422d7ce09abfbf56f721ba2cbbdcf02842413d7 Mon Sep 17 00:00:00 2001 From: Sergey Nebolsin Date: Sun, 11 Oct 2020 16:38:26 +0300 Subject: [PATCH 3/6] Minor improvements for RSpec setup --- .rspec | 4 ++++ Rakefile | 12 ++++++------ spec/spec_helper.rb | 15 +++++++-------- 3 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 .rspec diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..c773461 --- /dev/null +++ b/.rspec @@ -0,0 +1,4 @@ +--require spec_helper +--order rand +--color +--format documentation diff --git a/Rakefile b/Rakefile index c9437bf..2f996eb 100644 --- a/Rakefile +++ b/Rakefile @@ -1,9 +1,9 @@ +# frozen_string_literal: true + require "bundler/gem_tasks" +require "rspec/core/rake_task" + +RSpec::Core::RakeTask.new(:spec) -begin - require 'rspec/core/rake_task' - RSpec::Core::RakeTask.new(:spec) - task :default => :spec -rescue LoadError -end +task default: :spec diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3f75ff4..7849613 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,14 +1,13 @@ -require 'bundler/setup' -Bundler.setup -require 'simplecov' -SimpleCov.start +# frozen_string_literal: true -require 'pry' -require 'xdr' +require "simplecov" +SimpleCov.start do + enable_coverage :branch +end -__dir__ = File.dirname(__FILE__) +require "xdr" -Dir["#{__dir__}/support/**/*.rb"].each { |f| require f } +Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f } RSpec.configure do |config| From 3d8547d9610bf4e614d97a5602a4db19a0238ce7 Mon Sep 17 00:00:00 2001 From: Sergey Nebolsin Date: Sun, 11 Oct 2020 16:38:26 +0300 Subject: [PATCH 4/6] Add setup and console dev scripts + binstub --- Guardfile | 2 +- bin/bundle | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++ bin/console | 10 +++++ bin/rake | 29 +++++++++++++ bin/rspec | 29 +++++++++++++ bin/setup | 8 ++++ 6 files changed, 191 insertions(+), 1 deletion(-) create mode 100755 bin/bundle create mode 100755 bin/console create mode 100755 bin/rake create mode 100755 bin/rspec create mode 100755 bin/setup diff --git a/Guardfile b/Guardfile index 8e0c334..4a01ccc 100644 --- a/Guardfile +++ b/Guardfile @@ -1,4 +1,4 @@ -guard :rspec, cmd: 'bundle exec rspec' do +guard :rspec, cmd: 'bin/rspec' do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } watch('spec/spec_helper.rb') { "spec" } diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 0000000..a71368e --- /dev/null +++ b/bin/bundle @@ -0,0 +1,114 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'bundle' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "rubygems" + +m = Module.new do + module_function + + def invoked_as_script? + File.expand_path($0) == File.expand_path(__FILE__) + end + + def env_var_version + ENV["BUNDLER_VERSION"] + end + + def cli_arg_version + return unless invoked_as_script? # don't want to hijack other binstubs + return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` + bundler_version = nil + update_index = nil + ARGV.each_with_index do |a, i| + if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN + bundler_version = a + end + next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ + bundler_version = $1 + update_index = i + end + bundler_version + end + + def gemfile + gemfile = ENV["BUNDLE_GEMFILE"] + return gemfile if gemfile && !gemfile.empty? + + File.expand_path("../../Gemfile", __FILE__) + end + + def lockfile + lockfile = + case File.basename(gemfile) + when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) + else "#{gemfile}.lock" + end + File.expand_path(lockfile) + end + + def lockfile_version + return unless File.file?(lockfile) + lockfile_contents = File.read(lockfile) + return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ + Regexp.last_match(1) + end + + def bundler_version + @bundler_version ||= + env_var_version || cli_arg_version || + lockfile_version + end + + def bundler_requirement + return "#{Gem::Requirement.default}.a" unless bundler_version + + bundler_gem_version = Gem::Version.new(bundler_version) + + requirement = bundler_gem_version.approximate_recommendation + + return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0") + + requirement += ".a" if bundler_gem_version.prerelease? + + requirement + end + + def load_bundler! + ENV["BUNDLE_GEMFILE"] ||= gemfile + + activate_bundler + end + + def activate_bundler + gem_error = activation_error_handling do + gem "bundler", bundler_requirement + end + return if gem_error.nil? + require_error = activation_error_handling do + require "bundler/version" + end + return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" + exit 42 + end + + def activation_error_handling + yield + nil + rescue StandardError, LoadError => e + e + end +end + +m.load_bundler! + +if m.invoked_as_script? + load Gem.bin_path("bundler", "bundle") +end diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..31bf209 --- /dev/null +++ b/bin/console @@ -0,0 +1,10 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true +require "break" + +require "bundler/setup" +require "xdr" + +require "pry" +Pry.start + diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000..9275675 --- /dev/null +++ b/bin/rake @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rake' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rake", "rake") diff --git a/bin/rspec b/bin/rspec new file mode 100755 index 0000000..a6c7852 --- /dev/null +++ b/bin/rspec @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rspec' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rspec-core", "rspec") diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..dce67d8 --- /dev/null +++ b/bin/setup @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +bundle install + +# Do any other automated setup that you need to do here From 069b9e75759290d1eba5cd09cd90f7644cb6328f Mon Sep 17 00:00:00 2001 From: Sergey Nebolsin Date: Tue, 20 Oct 2020 16:16:58 +0300 Subject: [PATCH 5/6] Update changelog for 3.0.2 release --- CHANGELOG.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0044b9f..01a199c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,28 +1,31 @@ # Changelog -All notable changes to this project will be documented in this -file. This project adheres to [Semantic Versioning](http://semver.org/). +All notable changes to this project will be documented in this file. -As this project is pre 1.0, breaking changes may happen for minor version -bumps. A breaking change will get clearly notified in this log. +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased](https://github.com/stellar/ruby-xdr/compare/v3.0.1...master) +## [Unreleased](https://github.com/stellar/ruby-xdr/compare/v3.0.2...master) -## [3.0.1](https://github.com/stellar/ruby-xdr/compare/v3.0.0...v3.0.1) +## [3.0.2](https://github.com/stellar/ruby-xdr/compare/v3.0.1...v3.0.2) - 2020-10-20 +### Changed +- Relax lower bound for ActiveSupport dependency to support usage in Rails 4.2 ((#12)[https://github.com/stellar/ruby-xdr/pull/12]) +### Fixed +- Fix non-bang arm accessors for XDR::Union ((#13)[https://github.com/stellar/ruby-xdr/pull/13]) +- Fix .from_xdr encoding param to accept symbols ((#14)[https://github.com/stellar/ruby-xdr/pull/14]) +## [3.0.1](https://github.com/stellar/ruby-xdr/compare/v3.0.0...v3.0.1) - 2020-06-10 ### Added - Add encoding parameter to Union#to_xdr ((#7)[https://github.com/stellar/ruby-xdr/pull/7]). ### Fixed - Padding bytes are now properly validated when reading xdr values. According to the XDR spec, padding must be zeros. -## [1.0.0](https://github.com/stellar/ruby-xdr/compare/v0.1.0...v1.0.0) - +## [1.0.0](https://github.com/stellar/ruby-xdr/compare/v0.1.0...v1.0.0) - 2015-10-02 ### Added - the `to_xdr` helpers can take a second parameter that will encode the resulting output to hex or base64 when requested. - the `from_xdr` helpers can take a second parameter that will trigger a decode from hex or base64 of the provided string before decoding from xdr. ### Changed - - `from_xdr` raises an ArgumentError when the input data is not fully consumed From d545bbf4de624e2c9a889d543ab72ac6f1562c0a Mon Sep 17 00:00:00 2001 From: Sergey Nebolsin Date: Tue, 20 Oct 2020 16:23:25 +0300 Subject: [PATCH 6/6] Bump xdr to 3.0.2 --- lib/xdr/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/xdr/version.rb b/lib/xdr/version.rb index d9f0f78..ff17413 100644 --- a/lib/xdr/version.rb +++ b/lib/xdr/version.rb @@ -1,3 +1,3 @@ module XDR - VERSION = "3.0.1" + VERSION = "3.0.2" end