Skip to content

Commit a937895

Browse files
authored
Use struct instead openstruct in lib code (#2123)
1 parent 1178c8b commit a937895

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

docs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ nav_order: 5
1010

1111
## main
1212

13+
* Use struct instead openstruct in lib code.
14+
15+
*Oleksii Vasyliev*
16+
1317
* Fix bug where stimulus controller was not added to ERB when stimulus was activated by default.
1418

1519
*Denis Pasin*

lib/view_component/template.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
require "ostruct"
1+
# frozen_string_literal: true
22

33
module ViewComponent
44
class Template
5+
DataWithSource = Struct.new(:format, :identifier, :short_identifier, :type, keyword_init: true)
6+
DataNoSource = Struct.new(:source, :identifier, :type, keyword_init: true)
7+
58
attr_reader :variant, :this_format, :type
69

710
def initialize(
@@ -109,13 +112,13 @@ def compiled_source
109112

110113
if handler.method(:call).parameters.length > 1
111114
handler.call(
112-
OpenStruct.new(format: @this_format, identifier: @path, short_identifier: short_identifier, type: type),
115+
DataWithSource.new(format: @this_format, identifier: @path, short_identifier: short_identifier, type: type),
113116
this_source
114117
)
115118
# :nocov:
116119
# TODO: Remove in v4
117120
else
118-
handler.call(OpenStruct.new(source: this_source, identifier: @path, type: type))
121+
handler.call(DataNoSource.new(source: this_source, identifier: @path, type: type))
119122
end
120123
# :nocov:
121124
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# frozen_string_literal: true
22

3+
require "ostruct"
4+
35
class ApplicationController < ActionController::Base
46
end

0 commit comments

Comments
 (0)