Skip to content

Commit

Permalink
Merge 1f1b03b into a08e806
Browse files Browse the repository at this point in the history
  • Loading branch information
gam3 committed Aug 16, 2016
2 parents a08e806 + 1f1b03b commit 85afc76
Show file tree
Hide file tree
Showing 19 changed files with 110 additions and 68 deletions.
3 changes: 3 additions & 0 deletions .rubocop_defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ AllCops:
# Exclude vendored folders
- 'tmp/**/*'
- 'vendor/**/*'
- 'pkg/**/*'
- 'public_suffix.gemspec'


Lint/AmbiguousRegexpLiteral:
Enabled: false
Expand Down
1 change: 0 additions & 1 deletion .yardopts
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
--title 'Ruby Public Suffix API Documentation'
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Changelog


#### Release 2.0.2-gam3

- CHANGED: made rubocop optional
- CHANGED: have links in markdown files work for Github and YARD
- CHANGED: Minitest::Unit::TestCase -> Minitest::Test
- FIXED: Typo in docs for Domain#new
- FIXED: dead publicsuffix/format link


#### Release 2.0.2

- CHANGED: Updated definitions.
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ source "http://rubygems.org"
gemspec

gem "rake", "< 11"
gem "minitest"
gem "minitest", ">= 5.0"
gem "minitest-reporters"
gem "coveralls", require: false
gem "rubocop", require: false
gem "redcarpet", ">= 3.3"

gem "memory_profiler", require: false if !RUBY_VERSION.start_with?("2.0")
54 changes: 47 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ require "bundler"
$LOAD_PATH.unshift(File.dirname(__FILE__) + "/lib")
require "public_suffix"

default_tasks = [:test]

begin
require "rubocop/rake_task"
RuboCop::RakeTask.new
default_tasks.push :rubocop
rescue LoadError
$stderr.puts "Note 'rubocop' is not installed."
end

# By default, run tests and linter.
task default: [:test, :rubocop]
task default: default_tasks

spec = Gem::Specification.new do |s|
s.name = "public_suffix"
Expand Down Expand Up @@ -64,21 +73,52 @@ Rake::TestTask.new do |t|
t.warning = !ENV["WARNING"].nil?
end

require "rubocop/rake_task"

RuboCop::RakeTask.new


require "yard"
require "yard/rake/yardoc_task"
require "redcarpet"

# Inject Updated markdown into YARD
module YARD
module Templates
module Helpers
module HtmlHelper # rubocop:disable Documentation
def self.included(*)
raise "HERE"
end
# This class fixes up the \.md links in the extra files
class MyRenderHTML < Redcarpet::Render::HTML
def link(link, title, contents)
if link.=~(/\.md$/)
%(<a href="file.#{link.gsub(/\.md$/, '.html')}">#{contents}</a>)
elsif title
%(<a href="#{link}" title="#{title}"></a>)
else
%(<a href="#{link}">#{contents}</a>)
end
end
end
def html_markup_markdown(text)
if @markdown.nil?
# :no_intraemphasis, :gh_blockcode, :fenced_code, :autolink, :tables, :lax_spacing
renderer = MyRenderHTML.new
@markdown = Redcarpet::Markdown.new(renderer, :no_intra_emphasis => true, :gh_blockcode => true, :fenced_code_blocks => true, :autolink => true)
end
@markdown.render(text)
end
end
end
end
end

YARD::Rake::YardocTask.new(:yardoc) do |y|
y.options = %w( --output-dir yardoc )
y.options = %w( --output-dir yardoc --title 'Ruby Public Suffix API Documentation')
y.files = ["lib/**/*.rb", "-", "2.0-Upgrade.md", "CHANGELOG.md", "README.md"]
end

namespace :yardoc do
task :clobber do
rm_r "yardoc" rescue nil
rm_r ".yardoc" rescue nil
end
end
task clobber: ["yardoc:clobber"]
Expand Down
15 changes: 9 additions & 6 deletions lib/public_suffix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
# but was originally created to meet the needs of browser manufacturers.
module PublicSuffix

DOT = ".".freeze
BANG = "!".freeze
STAR = "*".freeze
# Character used to join parts of a domain
DOT = ".".freeze
# In the list represent an exception entry
BANG = "!".freeze
# In the list this represent a wildcard character.
STAR = "*".freeze

# Parses +name+ and returns the {PublicSuffix::Domain} instance.
#
Expand Down Expand Up @@ -128,9 +131,9 @@ def self.valid?(name, list: List.default, default_rule: list.default_rule, ignor
#
# This method doesn't raise. Instead, it returns nil if the domain is not valid for whatever reason.
#
# @param [String, #to_s] name The domain name or fully qualified domain name to parse.
# @param [PublicSuffix::List] list The rule list to search, defaults to the default {PublicSuffix::List}
# @param [Boolean] ignore_private
# @param name [String, #to_s] The domain name or fully qualified domain name to parse.
# @param list [PublicSuffix::List] The rule list to search, defaults to the default {PublicSuffix::List}
# @param ignore_private [Boolean] Ignore the private domains
# @return [String]
def self.domain(name, **options)
parse(name, **options).domain
Expand Down
6 changes: 1 addition & 5 deletions lib/public_suffix/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def self.name_to_labels(name)
# Initializes with a +tld+, +sld+ and +trd+.
# @param [String] tld The TLD (extension)
# @param [String] sld The SLD (domain)
# @param [String] tld The TRD (subdomain)
# @param [String] trd The TRD (subdomain)
#
# @yield [self] Yields on self.
# @yieldparam [PublicSuffix::Domain] self The newly creates instance
Expand Down Expand Up @@ -173,8 +173,6 @@ def subdomain
# This method doesn't actually validate the domain.
# It only checks whether the instance contains
# a value for the {#tld} and {#sld} attributes.
# If you also want to validate the domain,
# use {#valid_domain?} instead.
#
# @example
#
Expand Down Expand Up @@ -204,8 +202,6 @@ def domain?
# This method doesn't actually validate the subdomain.
# It only checks whether the instance contains
# a value for the {#tld}, {#sld} and {#trd} attributes.
# If you also want to validate the domain,
# use {#valid_subdomain?} instead.
#
# @example
#
Expand Down
1 change: 1 addition & 0 deletions lib/public_suffix/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

module PublicSuffix

# catch all error class for PublicSuffix
class Error < StandardError
end

Expand Down
5 changes: 3 additions & 2 deletions lib/public_suffix/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module PublicSuffix
class List
include Enumerable

# The default location for the public_suffix list data
DEFAULT_LIST_PATH = File.join(File.dirname(__FILE__), "..", "..", "data", "list.txt")

# Gets the default rule list.
Expand Down Expand Up @@ -76,8 +77,8 @@ def self.clear
#
# See http://publicsuffix.org/format/ for more details about input format.
#
# @param string [#each_line] The list to parse.
# @param private_domain [Boolean] whether to ignore the private domains section.
# @param input [String] The list to parse.
# @param private_domains [Boolean] Whether to ignore the private domains section.
# @return [Array<PublicSuffix::Rule::*>]
def self.parse(input, private_domains: true)
comment_token = "//".freeze
Expand Down
16 changes: 8 additions & 8 deletions lib/public_suffix/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Rule
# = Abstract rule class
#
# This represent the base class for a Rule definition
# in the {Public Suffix List}[https://publicsuffix.org].
# in the {https://publicsuffix.org Public Suffix List}.
#
# This is intended to be an Abstract class
# and you shouldn't create a direct instance. The only purpose
Expand All @@ -38,7 +38,7 @@ module Rule
# A rule is composed by 4 properties:
#
# value - A normalized version of the rule name.
# The normalization process depends on rule tpe.
# The normalization process depends on rule type.
#
# Here's an example
#
Expand Down Expand Up @@ -79,7 +79,7 @@ module Rule
# # => false
#
# Rule order is significant. A name can match more than one rule.
# See the {Public Suffix Documentation}[http://publicsuffix.org/format/]
# See the {http://publicsuffix.org/list/ Public Suffix Documentation}
# to learn more about rule priority.
#
# When you have the right rule, you can use it to tokenize the domain name.
Expand Down Expand Up @@ -166,8 +166,8 @@ def length
# @abstract
# @param [String, #to_s] name The domain name to decompose
# @return [Array<String, nil>]
def decompose(*)
raise NotImplementedError
def decompose(name) # rubocop: disable
raise NotImplementedError, "for #{name}"
end

end
Expand All @@ -191,7 +191,7 @@ def rule

# Decomposes the domain name according to rule properties.
#
# @param [String, #to_s] name The domain name to decompose
# @param [String] domain The domain name to decompose
# @return [Array<String>] The array with [trd + sld, tld].
def decompose(domain)
suffix = parts.join('\.')
Expand Down Expand Up @@ -239,7 +239,7 @@ def rule

# Decomposes the domain name according to rule properties.
#
# @param [String, #to_s] name The domain name to decompose
# @param [String] domain The domain name to decompose
# @return [Array<String>] The array with [trd + sld, tld].
def decompose(domain)
suffix = ([".*?"] + parts).join('\.')
Expand Down Expand Up @@ -288,7 +288,7 @@ def rule

# Decomposes the domain name according to rule properties.
#
# @param [String, #to_s] name The domain name to decompose
# @param [String] domain The domain name to decompose
# @return [Array<String>] The array with [trd + sld, tld].
def decompose(domain)
suffix = parts.join('\.')
Expand Down
4 changes: 2 additions & 2 deletions public_suffix.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib"]
s.authors = ["Simone Carletti"]
s.date = "2016-06-10"
s.date = "2016-08-15"
s.description = "PublicSuffix can parse and decompose a domain name into top level domain, domain and subdomains."
s.email = "weppos@weppos.net"
s.files = [".gitignore", ".rubocop.yml", ".rubocop_defaults.yml", ".ruby-gemset", ".travis.yml", ".yardopts", "2.0-Upgrade.md", "CHANGELOG.md", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "data/list.txt", "lib/public_suffix.rb", "lib/public_suffix/domain.rb", "lib/public_suffix/errors.rb", "lib/public_suffix/list.rb", "lib/public_suffix/rule.rb", "lib/public_suffix/version.rb", "public_suffix.gemspec", "test/acceptance_test.rb", "test/benchmark_helper.rb", "test/execution_profiler.rb", "test/initialization_profiler.rb", "test/performance_benchmark.rb", "test/psl_test.rb", "test/test_helper.rb", "test/tests.txt", "test/unit/domain_test.rb", "test/unit/errors_test.rb", "test/unit/list_test.rb", "test/unit/public_suffix_test.rb", "test/unit/rule_test.rb"]
s.homepage = "https://simonecarletti.com/code/publicsuffix-ruby"
s.licenses = ["MIT"]
s.required_ruby_version = Gem::Requirement.new(">= 2.0")
s.rubygems_version = "2.5.1"
s.rubygems_version = "2.2.2"
s.summary = "Domain name parser based on the Public Suffix List."
s.test_files = ["test/acceptance_test.rb", "test/benchmark_helper.rb", "test/execution_profiler.rb", "test/initialization_profiler.rb", "test/performance_benchmark.rb", "test/psl_test.rb", "test/test_helper.rb", "test/tests.txt", "test/unit/domain_test.rb", "test/unit/errors_test.rb", "test/unit/list_test.rb", "test/unit/public_suffix_test.rb", "test/unit/rule_test.rb"]

Expand Down
2 changes: 1 addition & 1 deletion test/acceptance_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class AcceptanceTest < Minitest::Unit::TestCase
class AcceptanceTest < Minitest::Test

VALID_CASES = [
["example.com", "example.com", [nil, "example", "com"]],
Expand Down
2 changes: 1 addition & 1 deletion test/psl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# This test runs against the current PSL file and ensures
# the definitions satisfies the test suite.
class PslTest < Minitest::Unit::TestCase
class PslTest < Minitest::Test

ROOT = File.expand_path("../../", __FILE__)

Expand Down
10 changes: 0 additions & 10 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@
end

require "minitest/autorun"
require "minitest/reporters"
require "mocha/setup"

Minitest::Reporters.use! Minitest::Reporters::DefaultReporter.new(color: true)

$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
require "public_suffix"

Minitest::Unit::TestCase.class_eval do
def assert_not_equal(exp, act, msg = nil)
assert_operator(exp, :!=, act, msg)
end unless method_exists?(:assert_not_equal)
end
2 changes: 1 addition & 1 deletion test/unit/domain_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class PublicSuffix::DomainTest < Minitest::Unit::TestCase
class PublicSuffix::DomainTest < Minitest::Test

def setup
@klass = PublicSuffix::Domain
Expand Down
2 changes: 1 addition & 1 deletion test/unit/errors_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class ErrorsTest < Minitest::Unit::TestCase
class ErrorsTest < Minitest::Test

# Inherits from StandardError
def test_error_inheritance
Expand Down
15 changes: 8 additions & 7 deletions test/unit/list_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class PublicSuffix::ListTest < Minitest::Unit::TestCase
class PublicSuffix::ListTest < Minitest::Test

def setup
@list = PublicSuffix::List.new
Expand Down Expand Up @@ -158,23 +158,24 @@ def test_select_ignore_private


def test_self_default_getter
assert_equal nil, PublicSuffix::List.class_eval { @default }
PublicSuffix::List.default = nil
assert_nil PublicSuffix::List.class_eval { @default; }
PublicSuffix::List.default
assert_not_equal nil, PublicSuffix::List.class_eval { @default }
refute_nil PublicSuffix::List.class_eval { @default }
end

def test_self_default_setter
PublicSuffix::List.default
assert_not_equal nil, PublicSuffix::List.class_eval { @default }
refute_nil PublicSuffix::List.class_eval { @default }
PublicSuffix::List.default = nil
assert_equal nil, PublicSuffix::List.class_eval { @default }
assert_nil PublicSuffix::List.class_eval { @default }
end

def test_self_clear
PublicSuffix::List.default
assert_not_equal nil, PublicSuffix::List.class_eval { @default }
refute_nil PublicSuffix::List.class_eval { @default }
PublicSuffix::List.clear
assert_equal nil, PublicSuffix::List.class_eval { @default }
assert_nil PublicSuffix::List.class_eval { @default }
end

def test_self_parse
Expand Down
2 changes: 1 addition & 1 deletion test/unit/public_suffix_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class PublicSuffixTest < Minitest::Unit::TestCase
class PublicSuffixTest < Minitest::Test

def test_private_domains_enabled_by_default
domain = PublicSuffix.parse("www.example.blogspot.com")
Expand Down
Loading

0 comments on commit 85afc76

Please sign in to comment.