Skip to content

Commit

Permalink
supports_feature_mixin. move lookup supports into check_supports
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Mar 7, 2024
1 parent 853d57a commit 6b815bf
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions app/models/mixins/supports_feature_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,7 @@ def unsupported_reason(feature)

# query the instance if the feature is supported or not
def supports?(feature)
if self.class.supports_features.key?(feature.to_sym)
self.class.check_supports(feature.to_sym, supports_features[feature.to_sym], instance: self)
else
unsupported_reason_add(feature, SupportsFeatureMixin.default_supports_reason)
false
end
self.class.check_supports(feature.to_sym, :instance => self)
end

private
Expand Down Expand Up @@ -105,16 +100,15 @@ def supports_not(feature, reason: nil)

# query the class if the feature is supported or not
def supports?(feature)
if supports_features.key?(feature.to_sym)
check_supports(feature.to_sym, supports_features[feature.to_sym], instance: self)
else
unsupported_reason_add(feature, SupportsFeatureMixin.default_supports_reason)
false
end
check_supports(feature.to_sym, :instance => self)
end

def check_supports(feature, value, instance:)
def check_supports(feature, instance:)
instance.send(:unsupported).delete(feature)

# undeclared features are not supported
value = supports_features[feature.to_sym]

if value.respond_to?(:call)
begin
# for class level supports, blocks are not evaluated and assumed to be true
Expand Down

0 comments on commit 6b815bf

Please sign in to comment.