Skip to content

Commit

Permalink
Restore Ruby 2.6 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfairh committed May 24, 2024
1 parent 8343f1c commit 199bf83
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

##### Bug Fixes

* None.
* Restore compatibility with Ruby 2.6
[John Fairhurst](https://github.com/johnfairh)
[#1388](https://github.com/realm/jazzy/issues/1388)

## 0.15.0

Expand Down
4 changes: 2 additions & 2 deletions lib/jazzy/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -717,12 +717,12 @@ def parse_module_configs

if modules.first.is_a?(String)
# Massage format (2) into (3)
self.modules = modules.map { { 'module' => _1 } }
self.modules = modules.map { |mod| { 'module' => mod } }
end

# Allow per-module overrides of only some config options
attrs_by_conf_key, attrs_by_name =
grouped_attributes { _1.select(&:per_module) }
grouped_attributes { |attr| attr.select(&:per_module) }

modules.map do |module_hash|
mod_name = module_hash['module'] || ''
Expand Down
12 changes: 6 additions & 6 deletions lib/jazzy/grouper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def self.group_docs(docs, doc_index)
# Group root-level docs by type
def self.group_docs_by_type(docs, type_category_prefix)
type_groups = SourceDeclaration::Type.all.map do |type|
children, docs = docs.partition { _1.type == type }
children, docs = docs.partition { |doc| doc.type == type }
make_type_group(children, type, type_category_prefix)
end
merge_categories(type_groups.compact) + docs
Expand All @@ -49,7 +49,7 @@ def self.group_docs_by_module(docs, type_category_prefix)

def self.group_custom_categories(docs, doc_index)
group = config.custom_categories.map do |category|
children = category['children'].filter_map do |name|
children = category['children'].map do |name|
unless doc = doc_index.lookup(name)
warn 'WARNING: No documented top-level declarations match ' \
"name \"#{name}\" specified in categories file"
Expand All @@ -64,7 +64,7 @@ def self.group_custom_categories(docs, doc_index)
end

docs.delete(doc)
end
end.compact
# Category config overrides alphabetization
children.each.with_index { |child, i| child.nav_order = i }
make_group(children, category['name'], '')
Expand All @@ -73,7 +73,7 @@ def self.group_custom_categories(docs, doc_index)
end

def self.group_guides(docs, prefix)
guides, others = docs.partition { _1.type.markdown? }
guides, others = docs.partition { |doc| doc.type.markdown? }
return [[], others] unless guides.any?

[[make_type_group(guides, guides.first.type, prefix)], others]
Expand All @@ -92,7 +92,7 @@ def self.make_type_group(docs, type, type_category_prefix)
def self.merge_categories(categories)
merged = []
categories.each do |new_category|
if existing = merged.find { _1.name == new_category.name }
if existing = merged.find { |cat| cat.name == new_category.name }
existing.children += new_category.children
else
merged.append(new_category)
Expand All @@ -102,7 +102,7 @@ def self.merge_categories(categories)
end

def self.make_group(group, name, abstract, url_name = nil)
group.reject! { _1.name.empty? }
group.reject! { |decl| decl.name.empty? }
unless group.empty?
SourceDeclaration.new.tap do |sd|
sd.type = SourceDeclaration::Type.overview
Expand Down
10 changes: 6 additions & 4 deletions lib/jazzy/sourcekitten.rb
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ def self.mergeable_objc?(decl, root_decls)
decl.type.objc_class? ||
(decl.type.objc_category? &&
(category_classname = decl.objc_category_name[0]) &&
root_decls.any? { _1.name == category_classname })
root_decls.any? { |d| d.name == category_classname })
end

# Returns if a Swift declaration is mergeable.
Expand Down Expand Up @@ -919,7 +919,9 @@ def self.merge_code_declaration(decls)

# Grab all the extensions from the same doc module
def self.next_doc_module_group(decls)
decls.partition { _1.doc_module_name == decls.first.doc_module_name }
decls.partition do |decl|
decl.doc_module_name == decls.first.doc_module_name
end
end

# Does this extension/type need a note explaining which doc module it is from?
Expand Down Expand Up @@ -1055,12 +1057,12 @@ def self.reject_objc_types(docs)
# Remove top-level enum cases because it means they have an ACL lower
# than min_acl
def self.reject_swift_types(docs)
docs.reject { _1.type.swift_enum_element? }
docs.reject { |doc| doc.type.swift_enum_element? }
end

# Spot and mark any categories on classes not declared in these docs
def self.mark_objc_external_categories(docs)
class_names = docs.select { _1.type.objc_class? }.to_set(&:name)
class_names = docs.select { |doc| doc.type.objc_class? }.to_set(&:name)

docs.map do |doc|
if (names = doc.objc_category_name) && !class_names.include?(names.first)
Expand Down

0 comments on commit 199bf83

Please sign in to comment.