Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow default rule to be override #120

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/public_suffix/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,17 @@ def self.factory(content, **options)
#
# @return [PublicSuffix::Rule::Wildcard] The default rule.
def self.default
factory(STAR)
return @default if defined?(@default)
@default = factory(STAR)
end

# Override the default rule.
#
# @param [PublicSuffix::Rule, nil] A rule instance or nil.
# @return [PublicSuffix::Rule, nil] The new default rule value.
def self.default=(rule)
@default = rule
end
end

end
7 changes: 7 additions & 0 deletions test/unit/rule_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ def test_default_returns_default_wildcard
assert_equal %w( www.example tldnotlisted ), default.decompose("www.example.tldnotlisted")
end

def test_self_default_setter
default_rule_was = PublicSuffix::Rule.default
assert_not_equal nil, PublicSuffix::Rule.default
PublicSuffix::Rule.default = nil
assert_equal nil, PublicSuffix::Rule.default
PublicSuffix::Rule.default = default_rule_was
end
end


Expand Down