Skip to content

Commit c6069f5

Browse files
committed
Replace ostruct with a custom class that acts almost the same.
This removes a warning in 3.4.0 and prepares for Ruby 3.5.0: > warning: ostruct was loaded from the standard library, but will no longer > be part of the default gems since Ruby 3.5.0. Add ostruct to your Gemfile or gemspec. This seems preferable to adding ostruct as a gem dependency especially since older rubies may not support the gem version of ostruct.
1 parent 583f7e4 commit c6069f5

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

lib/fpm/rake_task.rb

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
11
require "fpm/namespace"
2-
require "ostruct"
32
require "rake"
43
require "rake/tasklib"
54

65
class FPM::RakeTask < Rake::TaskLib
6+
class Options
7+
attr_accessor :args
8+
9+
def initialize(defaults=nil)
10+
if defaults.nil?
11+
@h = Hash.new
12+
else
13+
@h = defaults
14+
end
15+
end
16+
17+
def method_missing(m, *args)
18+
if m.end_with?("=")
19+
raise ArgumentError, "#{self.class.name}##{m} ... Expected 1 arg, got #{args.length}" if args.length != 1
20+
@h[m[0...-1]] = args[0]
21+
else
22+
raise ArgumentError, "Expected 0 arg, got #{args.length}" if args.length != 0
23+
return @h[m]
24+
end
25+
end
26+
27+
def to_h
28+
return @h
29+
end
30+
end # Options
31+
732
attr_reader :options
833

934
def initialize(package_name, opts = {}, &block)
10-
@options = OpenStruct.new(:name => package_name.to_s)
35+
#@options = OpenStruct.new(:name => package_name.to_s)
36+
@options = Options.new(:name => package_name.to_s)
1137
@source, @target = opts.values_at(:source, :target).map(&:to_s)
1238
@directory = File.expand_path(opts[:directory].to_s)
1339

@@ -18,8 +44,8 @@ def initialize(package_name, opts = {}, &block)
1844

1945
task(options.name) do |_, task_args|
2046
block.call(*[options, task_args].first(block.arity)) if block_given?
21-
abort("Must specify args") unless options.respond_to?(:args)
22-
@args = options.delete_field(:args)
47+
abort("Must specify args") if options.args.nil?
48+
@args = options.args
2349
run_cli
2450
end
2551
end

0 commit comments

Comments
 (0)