Skip to content

Commit 6955290

Browse files
committed
DRY up decorator boilerplate with SimpleDelegator
1 parent 3bfe5d1 commit 6955290

File tree

2 files changed

+16
-30
lines changed

2 files changed

+16
-30
lines changed

app/forms/settings/form_object_decorator.rb

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,19 @@
3434
# It automatically sets the label, value, and disabled properties from the
3535
# setting name and its definition attributes.
3636
module Settings
37-
class FormObjectDecorator
37+
class FormObjectDecorator < SimpleDelegator
3838
include ::ApplicationHelper
3939
include InputMethods
4040

41-
attr_reader :object
41+
# @!attribute [r] object
42+
# @return [Primer::Forms::Dsl::FormObject] the original form object
43+
alias object __getobj__
4244

43-
# Initializes a new Settings::FormObjectDecorator
45+
# @!method initialize(object)
46+
# Initializes a new {Settings::FormObjectDecorator}
4447
#
45-
# @param object [Primer::Forms::Dsl::FormObject] The form object to be decorated
46-
def initialize(object)
47-
@object = object
48-
end
49-
50-
def method_missing(method, ...)
51-
object.send(method, ...)
52-
end
53-
54-
def respond_to_missing?(method, include_private = false)
55-
object.respond_to?(method, include_private)
56-
end
48+
# @param object [Primer::Forms::Dsl::FormObject] The form object to be decorated
49+
# @return [FormObjectDecorator]
5750

5851
# Creates a group for a setting
5952
#

app/forms/settings/input_group_decorator.rb

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,18 @@
3434
# It automatically sets the label, value, and disabled properties from the
3535
# setting name and its definition attributes.
3636
module Settings
37-
class InputGroupDecorator
37+
class InputGroupDecorator < SimpleDelegator
3838
include ::ApplicationHelper
3939
include InputMethods
4040

41-
attr_reader :object
41+
# @!attribute [r] object
42+
# @return [Primer::Forms::Dsl::InputGroup] the original input group
43+
alias object __getobj__
4244

43-
# Initializes a new Settings::InputGroupDecorator
45+
# @!method initialize(object)
46+
# Initializes a new {Settings::InputGroupDecorator}
4447
#
45-
# @param object [Primer::Forms::Dsl::InputGroup] The input group to be decorated
46-
def initialize(object)
47-
@object = object
48-
end
49-
50-
def method_missing(method, ...)
51-
object.send(method, ...)
52-
end
53-
54-
def respond_to_missing?(method, include_private = false)
55-
object.respond_to?(method, include_private)
56-
end
48+
# @param object [Primer::Forms::Dsl::InputGroup] The input group to be decorated
49+
# @return [InputGroupDecorator]
5750
end
5851
end

0 commit comments

Comments
 (0)