Skip to content

Commit

Permalink
Autofix sax_ractor Layout Rubocops
Browse files Browse the repository at this point in the history
  • Loading branch information
nschonni committed Feb 28, 2023
1 parent e0630fe commit 7f1e2ec
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 57 deletions.
34 changes: 0 additions & 34 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,6 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, AllowAdjacentOneLineDefs, NumberOfEmptyLines.
Layout/EmptyLineBetweenDefs:
Exclude:
- 'examples/sax_ractor.rb'

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
Layout/EmptyLines:
Exclude:
- 'examples/sax_ractor.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only
Layout/EmptyLinesAroundClassBody:
Exclude:
- 'examples/sax_ractor.rb'

# Offense count: 5
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
Layout/ExtraSpacing:
Exclude:
- 'examples/sax_ractor.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Layout/HeredocIndentation:
Exclude:
- 'examples/sax_ractor.rb'

# Offense count: 23
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
Expand Down
43 changes: 20 additions & 23 deletions examples/sax_ractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
# In the Real World™ we probably wouldn't create a single-use `Ractor` for
# every argument, but this is primarily a test of `rb_ext_ractor_safe` for Ox.


# Miniature example Ractor-based `shared-mime-info` Ox handler à la `CHECKING::YOU::OUT`:
# https://github.com/okeeblow/DistorteD/tree/NEW-SENSATION/CHECKING-YOU-OUT
class Saxtor < Ox::Sax

# We will fill this `Struct` as we parse,
# yield it if its `ietf` matches our `needle`,
# and throw it away otherwise.
CYO = Struct.new(:ietf, :globs, :description) do
def initialize(ietf = nil, globs = Array.new, description = nil)
def initialize(ietf=nil, globs=Array.new, description=nil)
super(ietf, globs, description)
end
def to_s # Pretty print

def to_s # Pretty print
"#{self[:description]} (#{self[:ietf]}) [#{
self[:globs]&.map(&File.method(:extname)).join(?,)
}]"
end

def inspect; "#<CYO #{self.to_s}>"; end
end

Expand All @@ -48,7 +48,7 @@ def cyo
def start_element(name)
@parse_stack.push(name)
case @parse_stack.last
when :"mime-type" then @cyo = nil # Clear out leftovers between types.
when :"mime-type" then @cyo = nil # Clear out leftovers between types.
end
end

Expand Down Expand Up @@ -103,34 +103,33 @@ def awen(needle, **kwargs)
smart: false, # [boolean] Toggle Ox's built-in hints for HTML parsing: https://github.com/ohler55/ox/blob/master/ext/ox/sax_hint.c
strip_namespace: true, # [nil|String|true|false] (from Element names) Strip no namespaces, all namespaces, or a specific namespace.
symbolize: true, # [boolean] Fill callback method `name` arguments with Symbols instead of with Strings.
intern_string_values: true, # [boolean] Intern (freeze and deduplicate) String return values.
intern_string_values: true, # [boolean] Intern (freeze and deduplicate) String return values.
}.update(kwargs),
)

# Let our parent `#take` our needle-equivalent `CYO`, or `nil`.
Ractor.yield(@out)
end # def awen

end # class Saxtor
end # def awen
end # class Saxtor

# Fancy "usage" help `String` fragment to concat with specific error messages.
usage = <<-PLZ
usage = <<~PLZ
Usage: `sax_ractor.rb [SHARED-MIME-INFO_XML_PATH] [IETF_MEDIA_TYPES]…`
Usage: `sax_ractor.rb [SHARED-MIME-INFO_XML_PATH] [IETF_MEDIA_TYPES]…`
Common file paths:
Common file paths:
- FreeBSD:
`${LOCALBASE}/share/mime/packages/freedesktop.org.xml` (probably `/usr/local`)
https://www.freshports.org/misc/shared-mime-info/
- FreeBSD:
`${LOCALBASE}/share/mime/packages/freedesktop.org.xml` (probably `/usr/local`)
https://www.freshports.org/misc/shared-mime-info/
- Linux:
`/usr/share/mime/packages/freedesktop.org.xml`
- Linux:
`/usr/share/mime/packages/freedesktop.org.xml`
- macOS:
`/opt/homebrew/share/mime/packages/freedesktop.org.xml` (Homebrew)
`/opt/local/share/mime/packages/freedesktop.org.xml` (MacPorts)
https://formulae.brew.sh/formula/shared-mime-info
- macOS:
`/opt/homebrew/share/mime/packages/freedesktop.org.xml` (Homebrew)
`/opt/local/share/mime/packages/freedesktop.org.xml` (MacPorts)
https://formulae.brew.sh/formula/shared-mime-info
PLZ

# Bail out if we were given a nonexistant file.
Expand All @@ -148,7 +147,6 @@ def awen(needle, **kwargs)
haystack = haystack.realpath.freeze
needles = ARGV[1...]


# Hamburger Style.
puts "Parallel Ractors"
# Create one `Ractor` for every given media-type argument
Expand Down Expand Up @@ -179,7 +177,6 @@ def awen(needle, **kwargs)
"#{_1.name} gave us #{_2 || 'nothing'}"
}


# Hotdog Style.
puts
puts "Serial Ractor"
Expand Down

0 comments on commit 7f1e2ec

Please sign in to comment.