Skip to content

Commit e4b3903

Browse files
committed
Fix attribute fixer inheritance
1 parent 5b19352 commit e4b3903

File tree

9 files changed

+34
-2
lines changed

9 files changed

+34
-2
lines changed

lib/block_kit/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def self.fix(method_name, dangerous: false)
2929
attribute_fixers[:base] << {name: method_name, dangerous: dangerous}
3030
end
3131

32-
def self.inherited(base)
33-
base.attribute_fixers = attribute_fixers.dup
32+
def self.inherited(subclass)
33+
subclass.attribute_fixers = attribute_fixers.deep_dup
3434
end
3535

3636
def initialize(attributes = {})

lib/block_kit/composition/option.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class Option < Base
2525
validates :description, presence: true, length: {maximum: MAX_DESCRIPTION_LENGTH}, allow_nil: true
2626
fixes :description, truncate: {maximum: MAX_DESCRIPTION_LENGTH}, null_value: [:blank]
2727

28+
def self.inherited(subclass)
29+
subclass.attribute_fixers = attribute_fixers.deep_dup
30+
end
31+
2832
def initial?
2933
!!initial
3034
end

lib/block_kit/composition/text.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ class Text < Base
1111

1212
delegate :blank?, :present?, to: :text
1313

14+
def self.inherited(subclass)
15+
subclass.attribute_fixers = attribute_fixers.deep_dup
16+
end
17+
1418
def length
1519
text&.length || 0
1620
end

lib/block_kit/elements/base.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class Base < BlockKit::Base
99
validates :action_id, presence: true, length: {maximum: MAX_ACTION_ID_LENGTH}, allow_nil: true
1010
fixes :action_id, truncate: {maximum: MAX_ACTION_ID_LENGTH, dangerous: true, omission: ""}, null_value: {error_types: [:blank]}
1111

12+
def self.inherited(subclass)
13+
subclass.attribute_fixers = attribute_fixers.deep_dup
14+
end
15+
1216
def initialize(attributes = {})
1317
raise NotImplementedError, "#{self.class} is an abstract class and can't be instantiated." if instance_of?(Base)
1418

lib/block_kit/elements/base_button.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class BaseButton < Base
2727
validates :accessibility_label, presence: true, length: {maximum: MAX_ACCESSIBILITY_LABEL_LENGTH}, allow_nil: true
2828
fixes :accessibility_label, truncate: {maximum: MAX_ACCESSIBILITY_LABEL_LENGTH}, null_value: {error_types: [:blank]}
2929

30+
def self.inherited(subclass)
31+
subclass.attribute_fixers = attribute_fixers.deep_dup
32+
end
33+
3034
def initialize(attributes = {})
3135
raise NotImplementedError, "#{self.class} is an abstract class and can't be instantiated." if instance_of?(BaseButton)
3236

lib/block_kit/elements/multi_select.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ class MultiSelect < Select
77
validates :max_selected_items, presence: true, numericality: {only_integer: true, greater_than: 0}, allow_nil: true
88
fixes :max_selected_items, null_value: {error_types: [:greater_than]}
99

10+
def self.inherited(subclass)
11+
subclass.attribute_fixers = attribute_fixers.deep_dup
12+
end
13+
1014
def initialize(attributes = {})
1115
raise NotImplementedError, "#{self.class} is an abstract class and can't be instantiated." if instance_of?(MultiSelect)
1216

lib/block_kit/elements/select.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ class Select < Base
88
include Concerns::HasPlaceholder
99
include Concerns::PlainTextEmojiAssignment.new(:placeholder)
1010

11+
def self.inherited(subclass)
12+
subclass.attribute_fixers = attribute_fixers.deep_dup
13+
end
14+
1115
def initialize(attributes = {})
1216
raise NotImplementedError, "#{self.class} is an abstract class and can't be instantiated." if instance_of?(Select)
1317

lib/block_kit/layout/base.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class Base < BlockKit::Base
99
validates :block_id, presence: true, length: {maximum: MAX_BLOCK_ID_LENGTH}, allow_nil: true
1010
fixes :block_id, truncate: {maximum: MAX_BLOCK_ID_LENGTH, dangerous: true, omission: ""}, null_value: {error_types: [:blank]}
1111

12+
def self.inherited(subclass)
13+
subclass.attribute_fixers = attribute_fixers.deep_dup
14+
end
15+
1216
def initialize(attributes = {})
1317
raise NotImplementedError, "#{self.class} is an abstract class and can't be instantiated." if instance_of?(Base)
1418

lib/block_kit/surfaces/base.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class Base < BlockKit::Base
4545
dsl_method :blocks, as: :section, type: Layout::Section
4646
dsl_method :blocks, as: :video, type: Layout::Video, required_fields: [:alt_text, :title, :thumbnail_url, :video_url], yields: false
4747

48+
def self.inherited(subclass)
49+
subclass.attribute_fixers = attribute_fixers.deep_dup
50+
end
51+
4852
def initialize(attributes = {})
4953
raise NotImplementedError, "#{self.class} is an abstract class and can't be instantiated." if instance_of?(Base)
5054

0 commit comments

Comments
 (0)