Skip to content

Commit

Permalink
Merge pull request #853 from shaicoleman/remove-ostruct
Browse files Browse the repository at this point in the history
Remove OpenStruct
  • Loading branch information
jkowens authored Oct 4, 2024
2 parents d713bd2 + 64cca62 commit 53d69e1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
9 changes: 6 additions & 3 deletions benchmarks/lib/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ def benchmark( table_types, num )
end
end

# Returns an OpenStruct which contains two attritues, +description+ and +tms+ after performing an
# Returns a struct which contains two attritues, +description+ and +tms+ after performing an
# actual benchmark.
#
# == PARAMETERS
# * description - the description of the block that is getting benchmarked
# * blk - the block of code to benchmark
#
# == RETURNS
# An OpenStruct object with the following attributes:
# A struct object with the following attributes:
# * description - the description of the benchmark ran
# * tms - a Benchmark::Tms containing the results of the benchmark

BmStruct = Struct.new( :description, :tms, :failed, keyword_init: true )

def bm( description, &block )
tms = nil
puts "Benchmarking #{description}"
Expand All @@ -35,7 +38,7 @@ def bm( description, &block )
delete_all
failed = false

OpenStruct.new description: description, tms: tms, failed: failed
BmStruct.new( description: description, tms: tms, failed: failed )
end

# Given a model class (ie: Topic), and an array of columns and value sets
Expand Down
12 changes: 7 additions & 5 deletions benchmarks/lib/cli_parser.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'optparse'
require 'ostruct'

#
# == PARAMETERS
Expand Down Expand Up @@ -38,8 +37,11 @@ def self.print_valid_table_types( options, hsh = { prefix: '' } )
end
end

OptionsStruct = Struct.new( :adapter, :table_types, :delete_on_finish, :number_of_objects, :outputs,
:benchmark_all_types, keyword_init: true )
OutputStruct = Struct.new( :format, :filename, keyword_init: true )
def self.parse( args )
options = OpenStruct.new(
options = OptionsStruct.new(
adapter: 'mysql2',
table_types: {},
delete_on_finish: true,
Expand Down Expand Up @@ -81,12 +83,12 @@ def self.parse( args )

# print results in CSV format
opts.on( "--to-csv [String]", "Print results in a CSV file format" ) do |filename|
options.outputs << OpenStruct.new( format: 'csv', filename: filename)
options.outputs << OutputStruct.new( format: 'csv', filename: filename)
end

# print results in HTML format
opts.on( "--to-html [String]", "Print results in HTML format" ) do |filename|
options.outputs << OpenStruct.new( format: 'html', filename: filename )
options.outputs << OutputStruct.new( format: 'html', filename: filename )
end
end # end opt.parse!

Expand All @@ -100,7 +102,7 @@ def self.parse( args )
end

options.number_of_objects = [1000] if options.number_of_objects.empty?
options.outputs = [OpenStruct.new( format: 'html', filename: 'benchmark.html')] if options.outputs.empty?
options.outputs = [OutputStruct.new( format: 'html', filename: 'benchmark.html')] if options.outputs.empty?

print_options( options )

Expand Down
2 changes: 0 additions & 2 deletions lib/activerecord-import/import.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "ostruct"

module ActiveRecord::Import::ConnectionAdapters; end

module ActiveRecord::Import # :nodoc:
Expand Down

0 comments on commit 53d69e1

Please sign in to comment.