fontist 3.0.31 → 3.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e9016d35c6100b87e2a7585f7193a8fbac76a1a32ab01e178a2d95bef017fa5
4
- data.tar.gz: 6f02798721c34a5402bf413c9e1c003c3e968d1e01de44ae3562b726cf65bdb4
3
+ metadata.gz: 9138df3c46f325e2909f1312ffbe906d3b6bd6b70b695a751af1576f68cd8903
4
+ data.tar.gz: a496ef4bac70d7b1c414f17d07514bece411a7fc9e8dd1e4901e8fcc8e9d55b5
5
5
  SHA512:
6
- metadata.gz: 7b2a062de85a9d66e0ec4e6e6d726c1d6716f8653c4ee96313eea8ba379941476064121d014851ce15bc6e7cf59ee4dcf3b77d68cd43fef7863238b9bbb55a68
7
- data.tar.gz: 4d92357d6f58a7a1588bf4e6fb7793c94bbd8e47ecd1106cf9bbab87ef4321a4dd7fd172cbafab873f10c27c2563224fb7634fc0ad652baeda59e2ec433597b7
6
+ metadata.gz: 6a179916eb34c002c5635b8e7e6ee9ec6602e8aa1a7a6ab02174fdd6f25a5f183ed307f4db04911f62901a5f44d034850a4225827062503bf606587593918ec0
7
+ data.tar.gz: 23e184310fc3ab3da8b99fa9dc5c3f506f29962d837c36a46f09211873014eadc46379bea2f5788cfdbec7e5cdc80d610458266c9a33985c8fba217875d38d16
data/fontist.gemspec CHANGED
@@ -36,9 +36,9 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency "fontisan", "~> 0.4", ">= 0.4.47"
37
37
  spec.add_dependency "fuzzy_match", "~> 2.1"
38
38
  spec.add_dependency "git", "~> 6.0"
39
- spec.add_dependency "lutaml-model", "~> 0.8.0"
39
+ spec.add_dependency "lutaml-model", "~> 0.8.162"
40
40
  spec.add_dependency "marcel", "~> 1.0"
41
- spec.add_dependency "nokogiri", "~> 1.0"
41
+ spec.add_dependency "moxml", "~> 0.6"
42
42
  spec.add_dependency "octokit", "~> 10.0"
43
43
  spec.add_dependency "paint", "~> 2.3"
44
44
  spec.add_dependency "parallel", "~> 1.24"
@@ -3,8 +3,28 @@ module Fontist
3
3
  module Helpers
4
4
  module HashHelper
5
5
  class << self
6
+ # Converts a formula hash to string-keyed plain data. Values
7
+ # that are lutaml-model models join the document through their
8
+ # own to_hash serializer (the json gem used to call to_json on
9
+ # them implicitly during traversal; Yeptris::JSON does not).
6
10
  def stringify_keys(hash)
7
- Fontist::JSON.parse(Fontist::JSON.dump(hash))
11
+ deep_stringify(hash)
12
+ end
13
+
14
+ private
15
+
16
+ def deep_stringify(value)
17
+ case value
18
+ when Hash then value.to_h { |k, v| [k.to_s, deep_stringify(v)] }
19
+ when Array then value.map { |v| deep_stringify(v) }
20
+ else deep_stringify_model(value)
21
+ end
22
+ end
23
+
24
+ def deep_stringify_model(value)
25
+ return value unless value.respond_to?(:to_hash)
26
+
27
+ deep_stringify(value.to_hash)
8
28
  end
9
29
  end
10
30
  end
@@ -1,5 +1,4 @@
1
1
  require "plist"
2
- require "nokogiri"
3
2
  require "paint"
4
3
 
5
4
  module Fontist
@@ -1,4 +1,4 @@
1
- require "nokogiri"
1
+ require "moxml"
2
2
  require "paint"
3
3
 
4
4
  module Fontist
@@ -277,7 +277,7 @@ module Fontist
277
277
 
278
278
  def font_links
279
279
  html = URI.parse(ROOT).open("User-Agent" => Fontist::Utils::UserAgent.random_user_agent).read
280
- document = Nokogiri::HTML.parse(html)
280
+ document = Moxml.new.parse(html)
281
281
  links = document.css(CARD_LINK_SELECTOR)
282
282
  links = document.css(LEGACY_LINK_SELECTOR) if links.empty?
283
283
  links
@@ -408,7 +408,7 @@ module Fontist
408
408
  response = uri.open("User-Agent" => Fontist::Utils::UserAgent.random_user_agent)
409
409
  current_url = response.base_uri
410
410
  html = response.read
411
- document = Nokogiri::HTML.parse(html)
411
+ document = Moxml.new.parse(html)
412
412
 
413
413
  if @verbose
414
414
  # Debug: Show what selectors find using standardized method
data/lib/fontist/repo.rb CHANGED
@@ -115,16 +115,19 @@ module Fontist
115
115
  end
116
116
  end
117
117
 
118
- def update(name)
118
+ def update(name, rebuild: true)
119
119
  path = repo_path(name)
120
120
  unless Dir.exist?(path)
121
121
  raise(Errors::RepoNotFoundError, "No such repo '#{name}'.")
122
122
  end
123
123
 
124
124
  git = Git.open(path)
125
+ before = git.rev_parse("HEAD")
125
126
  git.pull("origin", git.current_branch)
127
+ changed = git.rev_parse("HEAD") != before
126
128
 
127
- rebuild_index_if_needed
129
+ rebuild_index_if_needed if rebuild && changed
130
+ changed
128
131
  rescue StandardError => e
129
132
  # Catch all git-related errors
130
133
  if e.class.name.include?("Git") || e.message.match?(/git|pull|repository/i)
@@ -9,23 +9,35 @@ module Fontist
9
9
  end
10
10
 
11
11
  def call
12
- update_main_repo
13
- update_private_repos
12
+ main_changed = update_main_repo
13
+ private_changed = update_private_repos
14
14
  ensure
15
- rebuild_index
15
+ # The index is a projection of the corpus: a pull that brought no
16
+ # changes leaves it valid, and a failed pull leaves the corpus
17
+ # untouched. Rebuilding costs a full pass over every formula, so
18
+ # it only runs when some repo actually moved — or when no index
19
+ # exists yet (a fresh clone never had one; lookups self-heal by
20
+ # rebuilding on demand, but an explicit update should leave one
21
+ # behind).
22
+ rebuild_index if main_changed || private_changed || index_missing?
16
23
  end
17
24
 
18
25
  private
19
26
 
27
+ def index_missing?
28
+ !File.exist?(Fontist.formula_filename_index_path)
29
+ end
30
+
20
31
  def update_main_repo
21
32
  dir = File.dirname(Fontist.formulas_repo_path)
22
33
  FileUtils.mkdir_p(dir)
23
34
 
24
35
  unless Dir.exist?(Fontist.formulas_repo_path)
25
- return Git.clone(Fontist.formulas_repo_url,
26
- Fontist.formulas_repo_path,
27
- branch: @branch,
28
- depth: 1)
36
+ Git.clone(Fontist.formulas_repo_url,
37
+ Fontist.formulas_repo_path,
38
+ branch: @branch,
39
+ depth: 1)
40
+ return true
29
41
  end
30
42
 
31
43
  git = if Dir.exist?(Fontist.formulas_repo_path.join(".git"))
@@ -36,21 +48,34 @@ module Fontist
36
48
  end
37
49
  end
38
50
 
39
- return git.pull("origin", @branch) if git.current_branch == @branch
51
+ if git.current_branch != @branch
52
+ git.config_set("remote.origin.fetch",
53
+ "+refs/heads/#{@branch}:refs/remotes/origin/#{@branch}")
54
+ git.fetch
55
+ git.checkout(@branch)
56
+ git.pull("origin", @branch)
57
+ return true
58
+ end
40
59
 
41
- git.config_set("remote.origin.fetch",
42
- "+refs/heads/#{@branch}:refs/remotes/origin/#{@branch}")
43
- git.fetch
44
- git.checkout(@branch)
60
+ # A freshly init-ed repo has no commits yet; nil before the first
61
+ # pull means "changed", since the pull then creates the corpus
62
+ before = head_sha(git)
45
63
  git.pull("origin", @branch)
64
+ head_sha(git) != before
46
65
  end
47
66
 
48
67
  def update_private_repos
49
- Repo.list.each do |name|
50
- Repo.update(name)
68
+ Repo.list.reduce(false) do |changed, name|
69
+ Repo.update(name, rebuild: false) || changed
51
70
  end
52
71
  end
53
72
 
73
+ def head_sha(git)
74
+ git.rev_parse("HEAD")
75
+ rescue Git::FailedError, Git::GitError
76
+ nil
77
+ end
78
+
54
79
  def rebuild_index
55
80
  Index.rebuild
56
81
  end
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "3.0.31".freeze
2
+ VERSION = "3.0.33".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fontist
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.31
4
+ version: 3.0.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -98,14 +98,14 @@ dependencies:
98
98
  requirements:
99
99
  - - "~>"
100
100
  - !ruby/object:Gem::Version
101
- version: 0.8.0
101
+ version: 0.8.162
102
102
  type: :runtime
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - "~>"
107
107
  - !ruby/object:Gem::Version
108
- version: 0.8.0
108
+ version: 0.8.162
109
109
  - !ruby/object:Gem::Dependency
110
110
  name: marcel
111
111
  requirement: !ruby/object:Gem::Requirement
@@ -121,19 +121,19 @@ dependencies:
121
121
  - !ruby/object:Gem::Version
122
122
  version: '1.0'
123
123
  - !ruby/object:Gem::Dependency
124
- name: nokogiri
124
+ name: moxml
125
125
  requirement: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - "~>"
128
128
  - !ruby/object:Gem::Version
129
- version: '1.0'
129
+ version: '0.6'
130
130
  type: :runtime
131
131
  prerelease: false
132
132
  version_requirements: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - "~>"
135
135
  - !ruby/object:Gem::Version
136
- version: '1.0'
136
+ version: '0.6'
137
137
  - !ruby/object:Gem::Dependency
138
138
  name: octokit
139
139
  requirement: !ruby/object:Gem::Requirement