Skip to content

Commit

Permalink
Remove dependency on ostruct
Browse files Browse the repository at this point in the history
Requiring ostruct on Ruby 3.4 warns:
```
/home/user/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/gem-release-2.2.2/lib/gem/release/data.rb:2: warning: /home/user/.rbenv/versions/3.4.1/lib/ruby/3.4.0/ostruct.rb was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.5.0.
You can add ostruct to your Gemfile or gemspec to silence this warning.
Also please contact the author of gem-release-2.2.2 to request adding ostruct into its gemspec.
```

But since the values that this ostruct will take is known, there is no need to use ostruct all all. I've simply replaced it with a normal struct.
It's a bit akward because of support for such old ruby versions (no `keyword_init`) but works out.
  • Loading branch information
Earlopain committed Dec 27, 2024
1 parent 84486c5 commit 2789df1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
32 changes: 16 additions & 16 deletions lib/gem/release/data.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
require 'erb'
require 'ostruct'
require_relative 'helper/string'

module Gem
module Release
class Data < Struct.new(:git, :gem, :opts)
include Helper::String

KEYS = %i[
gem_name gem_path module_names author email homepage
licenses summary description files bin_files
].freeze

def data
{
gem_name: gem_name,
gem_path: gem_path,
module_names: module_names,
author: user_name,
email: user_email,
homepage: homepage,
licenses: licenses,
summary: '[summary]',
description: '[description]',
files: files,
bin_files: bin_files
}
KEYS.map { |key| [key, send(key)] }.to_h
end

private
Expand All @@ -41,11 +33,11 @@ def user_login
git.user_login || '[your login]'
end

def user_name
def author
git.user_name || '[your name]'
end

def user_email
def email
git.user_email || '[your email]'
end

Expand All @@ -72,6 +64,14 @@ def bin_files
def strategy
STRATEGIES[(opts[:strategy] || :glob).to_sym] || STRATEGIES[:glob]
end

def summary
'[summary]'
end

def description
'[description]'
end
end
end
end
2 changes: 1 addition & 1 deletion lib/gem/release/files/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def binding
end

def context
Context.new(data)
Context.new(*data.values)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/gem/release/files/template/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Gem
module Release
module Files
class Template
class Context < OpenStruct
class Context < Struct.new(*Gem::Release::Data::KEYS)
class Const < Struct.new(:type, :names)
def define(&block)
lines = build(names) { |name| "#{type} #{name}" }
Expand Down

0 comments on commit 2789df1

Please sign in to comment.