Skip to content

Commit f478b3d

Browse files
authored
Handling Version Loading in Gems Properly (#504)
If the version file is not loaded in the library code but is loaded in the gemspec file, issues like (#379) load errors or missing constants can occur. To be cautious, the gemspec avoids requiring the version file directly. Instead, it reads the file content. This approach also includes a simple validation to ensure the version string follows the SemVer format, so mistakes in the version file can be detected early. Additionally, this change fixes an actual case where the version file was not being required properly.
1 parent 9ea2782 commit f478b3d

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

lib/line/bot/v2/http_client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require 'uri'
33
require 'json'
44
require 'net/http/post/multipart'
5+
require 'line/bot/v2/version'
56

67
module Line
78
module Bot

line-bot-api.gemspec

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
lib = File.expand_path('lib', __dir__)
2-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3-
require 'line/bot/v2/version'
1+
version = File.read("#{__dir__}/lib/line/bot/v2/version.rb").match(/VERSION *= *['"]([^'"]+)/)[1] or raise
2+
raise "Invalid version format <#{version}>" unless version.match?(/\A\d+\.\d+\.\d+(?:[+-][\w.-]+)?\z/)
43

54
Gem::Specification.new do |spec|
65
spec.name = "line-bot-api"
7-
spec.version = Line::Bot::V2::VERSION
6+
spec.version = version
87
spec.authors = ["LINE Corporation"]
98
spec.email = ["kimoto@linecorp.com", "todaka.yusuke@linecorp.com", "masaki_kurosawa@linecorp.com"]
109

0 commit comments

Comments
 (0)