slither 0.99.5 → 0.99.7

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: 67bb6ad8dd4ac38f63231d77f9e366543cf9b11589e89760da6c85da9912995b
4
- data.tar.gz: 9b7be1bf9747a39d72ee06097226676c2d7c7a634f56fcbb290bf5d665b23fbb
3
+ metadata.gz: 8b051e82db86d3c7b5e19f807d932b639be6d9a63f90cdd7a8eb3ea4b2a5bdad
4
+ data.tar.gz: f4888aa4cadca12afe03740ff902218d75c39bec16f2e542182e7eb85b6580ba
5
5
  SHA512:
6
- metadata.gz: 72590afbfbceec05c54e67fa4f534c16207579a6fc3412ff19739e7ecc805864e044f6625b468827cb6dae7d627960a7b24895b25cced9b57ea5884bb217a82e
7
- data.tar.gz: e695c7f0871aae93d0fb2ae8c8e7cd10e36737304f5f9b244009728f44153bd9028c6f3085c0c433eb6e703cb4ba558c11e27479e80c416d460448b5eeed8a38
6
+ metadata.gz: a3f1b0e492b6a39e89cfe2a0db34b649fda0794f744c212fcba1d0b4d40e8a5e830342db67ff9285b5b526ece0e2aaa1f2833218c999acd0f5c57e0b69e18dab
7
+ data.tar.gz: af9d062e3c0a4653cd1670f4e07fd85533c5dba52ad127062a8e2b5ea09f4bff742aed87f12369b70a536a041fb4ef235fec28ea96a5d2ab16750ca35008ca6e
data/.rubocop.yml CHANGED
@@ -1,6 +1,12 @@
1
+ require:
2
+ - rubocop-rspec
3
+
1
4
  AllCops:
2
5
  NewCops: enable
3
6
 
7
+ Naming/BlockForwarding:
8
+ EnforcedStyle: explicit
9
+
4
10
  Style/StringLiterals:
5
11
  Enabled: true
6
12
  EnforcedStyle: double_quotes
@@ -20,3 +26,21 @@ Metrics/MethodLength:
20
26
 
21
27
  Style/Documentation:
22
28
  Enabled: false
29
+
30
+ Style/HashSyntax:
31
+ EnforcedShorthandSyntax: never
32
+
33
+ RSpec/ContextWording:
34
+ Enabled: false
35
+ RSpec/ExampleLength:
36
+ Enabled: false
37
+ RSpec/MessageSpies:
38
+ Enabled: false
39
+ RSpec/MultipleExpectations:
40
+ Enabled: false
41
+ RSpec/NamedSubject:
42
+ Enabled: false
43
+ RSpec/NestedGroups:
44
+ Enabled: false
45
+ RSpec/SubjectStub:
46
+ Enabled: false
data/Gemfile CHANGED
@@ -5,8 +5,11 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in slither.gemspec
6
6
  gemspec
7
7
 
8
+ gem "bundler"
9
+ gem "pry"
8
10
  gem "rake", "~> 13.0"
9
-
10
11
  gem "rspec", "~> 3.0"
11
-
12
- gem "rubocop", "~> 1.21"
12
+ gem "rubocop", "~> 1.76.1"
13
+ gem "rubocop-rspec", "~> 3.6.0", require: false
14
+ # Documentation tool
15
+ gem "yard"
data/Gemfile.lock CHANGED
@@ -1,26 +1,30 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slither (0.99.5)
4
+ slither (0.99.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- ast (2.4.2)
9
+ ast (2.4.3)
10
10
  coderay (1.1.3)
11
11
  diff-lcs (1.5.0)
12
- json (2.6.3)
12
+ json (2.12.2)
13
+ language_server-protocol (3.17.0.5)
14
+ lint_roller (1.1.0)
13
15
  method_source (1.0.0)
14
- parallel (1.22.1)
15
- parser (3.2.0.0)
16
+ parallel (1.27.0)
17
+ parser (3.3.8.0)
16
18
  ast (~> 2.4.1)
17
- pry (0.14.1)
19
+ racc
20
+ prism (1.4.0)
21
+ pry (0.14.2)
18
22
  coderay (~> 1.1)
19
23
  method_source (~> 1.0)
24
+ racc (1.8.1)
20
25
  rainbow (3.1.1)
21
26
  rake (13.0.6)
22
- regexp_parser (2.7.0)
23
- rexml (3.2.5)
27
+ regexp_parser (2.10.0)
24
28
  rspec (3.12.0)
25
29
  rspec-core (~> 3.12.0)
26
30
  rspec-expectations (~> 3.12.0)
@@ -34,30 +38,41 @@ GEM
34
38
  diff-lcs (>= 1.2.0, < 2.0)
35
39
  rspec-support (~> 3.12.0)
36
40
  rspec-support (3.12.0)
37
- rubocop (1.45.1)
41
+ rubocop (1.76.1)
38
42
  json (~> 2.3)
43
+ language_server-protocol (~> 3.17.0.2)
44
+ lint_roller (~> 1.1.0)
39
45
  parallel (~> 1.10)
40
- parser (>= 3.2.0.0)
46
+ parser (>= 3.3.0.2)
41
47
  rainbow (>= 2.2.2, < 4.0)
42
- regexp_parser (>= 1.8, < 3.0)
43
- rexml (>= 3.2.5, < 4.0)
44
- rubocop-ast (>= 1.24.1, < 2.0)
48
+ regexp_parser (>= 2.9.3, < 3.0)
49
+ rubocop-ast (>= 1.45.0, < 2.0)
45
50
  ruby-progressbar (~> 1.7)
46
- unicode-display_width (>= 2.4.0, < 3.0)
47
- rubocop-ast (1.24.1)
48
- parser (>= 3.1.1.0)
49
- ruby-progressbar (1.11.0)
50
- unicode-display_width (2.4.2)
51
+ unicode-display_width (>= 2.4.0, < 4.0)
52
+ rubocop-ast (1.45.1)
53
+ parser (>= 3.3.7.2)
54
+ prism (~> 1.4)
55
+ rubocop-rspec (3.6.0)
56
+ lint_roller (~> 1.1)
57
+ rubocop (~> 1.72, >= 1.72.1)
58
+ ruby-progressbar (1.13.0)
59
+ unicode-display_width (3.1.4)
60
+ unicode-emoji (~> 4.0, >= 4.0.4)
61
+ unicode-emoji (4.0.4)
62
+ yard (0.9.34)
51
63
 
52
64
  PLATFORMS
53
65
  ruby
54
66
 
55
67
  DEPENDENCIES
68
+ bundler
56
69
  pry
57
70
  rake (~> 13.0)
58
71
  rspec (~> 3.0)
59
- rubocop (~> 1.21)
72
+ rubocop (~> 1.76.1)
73
+ rubocop-rspec (~> 3.6.0)
60
74
  slither!
75
+ yard
61
76
 
62
77
  BUNDLED WITH
63
78
  2.3.25
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Slither
2
2
  by Ryan Wood http://ryanwood.com
3
3
 
4
+ Documentation: https://www.rubydoc.info/gems/slither
5
+
4
6
  # Description:
5
7
 
6
8
  A simple, clean DSL for describing, writing, and parsing fixed-width text files.
data/Rakefile CHANGED
@@ -9,4 +9,4 @@ require "rubocop/rake_task"
9
9
 
10
10
  RuboCop::RakeTask.new
11
11
 
12
- task default: %i[spec rubocop]
12
+ task default: %i[spec] # rubocop still working on it
@@ -1,4 +1,4 @@
1
- require 'date'
1
+ require "date"
2
2
 
3
3
  module Slither
4
4
  class ParserError < RuntimeError; end
@@ -1,48 +1,96 @@
1
- module Slither
2
- class Definition
3
- attr_reader :sections, :templates, :options
4
-
5
- def initialize(options = {})
6
- @sections = []
7
- @templates = {}
8
- @options = { :align => :right, :by_bytes => true }.merge(options)
9
- end
10
-
11
- def section(name, options = {}, &block)
12
- if section_using_reserved_name?(name) || section_already_defined?(name)
13
- raise( ArgumentError, "Reserved or duplicate section name: '#{name}'")
14
- end
15
-
16
- section = Slither::Section.new(name, @options.merge(options))
17
- section.definition = self
18
-
19
- yield(section)
20
-
21
- sections << section
22
- section
23
- end
24
-
25
- def template(name, options = {}, &block)
26
- section = Slither::Section.new(name, @options.merge(options))
27
- yield(section)
28
- @templates[name] = section
29
- end
30
-
31
- def method_missing(method, *args, &block)
32
- section(method, *args, &block)
33
- end
34
-
35
- private
36
-
37
- def section_using_reserved_name?(name)
38
- Section::RESERVED_NAMES.include?(name)
39
- end
40
-
41
- def section_already_defined?(name)
42
- return false if sections.empty?
43
-
44
- section_names = sections.map(&:name)
45
- section_names.include?(name)
46
- end
47
- end
48
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Slither
4
+ # A Definition is the parent object that contains the information about how a fixed-width file is
5
+ # formatted. It contains a collection of sections, each of which contains a collection of fields.
6
+ class Definition
7
+ attr_reader :sections, :templates, :options
8
+
9
+ # Initializes a new Definition object.
10
+ #
11
+ # @param options [Hash] An optional hash of configuration options.
12
+ # @option options [Symbol] :align ( :right ) The alignment for fields, can be :left, :right, or :center.
13
+ # @option options [Boolean] :by_bytes ( true ) Whether to align fields by bytes or characters.
14
+ #
15
+ def initialize(options = {})
16
+ @sections = []
17
+ @templates = {}
18
+ @options = { align: :right, by_bytes: true }.merge(options)
19
+ end
20
+
21
+ # Defines a new Section within the Definition.
22
+ #
23
+ # @param name [String] The name of the section.
24
+ # @param options [Hash] An optional hash of section-specific configuration options.
25
+ # @yield [Section] A block for defining fields within the section.
26
+ # @yieldparam section [Section] The section object to be configured.
27
+ # @return [Section] The newly created section.
28
+ #
29
+ # @raise [ArgumentError] if the section name is reserved or already defined.
30
+ #
31
+ # @example Define a section for the "header" part of the fixed-width file.
32
+ # definition.section(:header, align: :left) do |section|
33
+ # # The trap tells Slither which lines should fall into this section
34
+ # section.trap { |line| line[0,4] == 'HEAD' }
35
+ # # Use the boundary template for the columns
36
+ # section.template(:boundary)
37
+ # end
38
+ #
39
+ def section(name, options = {}, &block)
40
+ if section_using_reserved_name?(name) || section_already_defined?(name)
41
+ raise ArgumentError, "Reserved or duplicate section name: '#{name}'"
42
+ end
43
+
44
+ section = Slither::Section.new(name, @options.merge(options))
45
+ section.definition = self
46
+
47
+ yield(section) if block
48
+
49
+ sections << section
50
+ section
51
+ end
52
+
53
+ # Defines a template, which can be reused to create multiple sections with the same configuration.
54
+ #
55
+ # @param name [String] The name of the template.
56
+ # @param options [Hash] An optional hash of template-specific configuration options.
57
+ # @yield [section] A block for configuring the template.
58
+ # @yieldparam section [Section] The template object to be configured.
59
+ #
60
+ # @example Define a template for the "boundary" part of the fixed-width file.
61
+ # definition.template(:boundary) do |section|
62
+ # section.column(:record_type, 4)
63
+ # section.column(::company_id, 12)
64
+ #
65
+ def template(name, options = {}, &block)
66
+ section = Slither::Section.new(name, @options.merge(options))
67
+ yield(section) if block
68
+ @templates[name] = section
69
+ end
70
+
71
+ # Provides a way to define sections using method calls. For example,
72
+ # you can call `my_section` instead of `section('my_section')`.
73
+ #
74
+ # @param method [Symbol] The name of the section.
75
+ # @param args [Array] Additional arguments.
76
+ # @param block [Block] A block for defining fields within the section.
77
+ # @return [Section] The newly created section.
78
+ #
79
+ def method_missing(method, *args, &block) # rubocop:disable Style/MissingRespondToMissing
80
+ section(method, *args, &block)
81
+ end
82
+
83
+ private
84
+
85
+ def section_using_reserved_name?(name)
86
+ Section::RESERVED_NAMES.include?(name)
87
+ end
88
+
89
+ def section_already_defined?(name)
90
+ return false if sections.empty?
91
+
92
+ section_names = sections.map(&:name)
93
+ section_names.include?(name)
94
+ end
95
+ end
96
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Slither
4
- VERSION = "0.99.5"
4
+ VERSION = "0.99.7"
5
5
  end
data/lib/slither.rb CHANGED
@@ -1,16 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'slither/column'
4
- require_relative 'slither/definition'
5
- require_relative 'slither/generator'
6
- require_relative 'slither/parser'
7
- require_relative 'slither/section'
3
+ require_relative "slither/column"
4
+ require_relative "slither/definition"
5
+ require_relative "slither/generator"
6
+ require_relative "slither/parser"
7
+ require_relative "slither/section"
8
8
  require_relative "slither/version"
9
9
 
10
10
  module Slither
11
11
  class Error < StandardError; end
12
- # Your code goes here...
13
-
14
12
  class DuplicateColumnNameError < StandardError; end
15
13
  class RequiredSectionNotFoundError < StandardError; end
16
14
  class RequiredSectionEmptyError < StandardError; end
@@ -19,8 +17,26 @@ module Slither
19
17
  class LineWrongSizeError < StandardError; end
20
18
  class SectionsNotSameLengthError < StandardError; end
21
19
 
20
+ class << self
21
+ private
22
+
23
+ def definitions
24
+ @@definitions ||= {} # rubocop:disable Style/ClassVars
25
+ end
22
26
 
23
- def self.define(name, options = {}, &block)
27
+ def definition(name)
28
+ definitions[name]
29
+ end
30
+ end
31
+
32
+ # Define a Slither's definition to parse a file.
33
+ #
34
+ # name - String name of the definition, this should be unique.
35
+ # options - Hash of options to pass to the definition.
36
+ # Ex: by_bytes: true, to parse by bytes
37
+ # Ex: align: :left, to align the columns to the left
38
+ # block - Block to define the sections of the definition. See README.md for more info.
39
+ def self.define(name, options = {}, &block) # rubocop:disable Lint/UnusedMethodArgument
24
40
  definition = Definition.new(options)
25
41
  yield(definition)
26
42
  definitions[name] = definition
@@ -31,38 +47,28 @@ module Slither
31
47
  def self.generate(definition_name, data)
32
48
  definition = definition(definition_name)
33
49
  raise ArgumentError, "Definition name '#{name}' was not found." unless definition
50
+
34
51
  generator = Generator.new(definition)
35
52
  generator.generate(data)
36
53
  end
37
54
 
38
55
  # Writes the File
39
56
  def self.write(filename, definition_name, data)
40
- File.open(filename, 'w') do |f|
41
- f.write generate(definition_name, data)
42
- end
57
+ File.write(filename, generate(definition_name, data))
43
58
  end
44
59
 
45
60
  def self.parse(filename, definition_name)
46
- raise ArgumentError, "File #{filename} does not exist." unless File.exists?(filename)
61
+ raise ArgumentError, "File #{filename} does not exist." unless File.exist?(filename)
47
62
 
48
- file_io = File.open(filename, 'r')
63
+ file_io = File.open(filename, "r")
49
64
  parseIo(file_io, definition_name)
50
65
  end
51
66
 
52
- def self.parseIo(io, definition_name)
67
+ def self.parseIo(io, definition_name) # rubocop:disable Naming/MethodName
53
68
  definition = definition(definition_name)
54
69
  raise ArgumentError, "Definition name '#{definition_name}' was not found." unless definition
70
+
55
71
  parser = Parser.new(definition, io)
56
72
  definition.options[:by_bytes] ? parser.parse_by_bytes : parser.parse
57
73
  end
58
-
59
- private
60
-
61
- def self.definitions
62
- @@definitions ||= {}
63
- end
64
-
65
- def self.definition(name)
66
- definitions[name]
67
- end
68
74
  end
metadata CHANGED
@@ -1,57 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slither
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.99.5
4
+ version: 0.99.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Wood
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-16 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: pry
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '3.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '3.0'
41
- - !ruby/object:Gem::Dependency
42
- name: rubocop
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '='
46
- - !ruby/object:Gem::Version
47
- version: '2.6'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '='
53
- - !ruby/object:Gem::Version
54
- version: '2.6'
11
+ date: 2025-06-18 00:00:00.000000000 Z
12
+ dependencies: []
55
13
  description:
56
14
  email:
57
15
  executables: []
@@ -76,10 +34,11 @@ files:
76
34
  - lib/slither/section.rb
77
35
  - lib/slither/version.rb
78
36
  - sig/slither.rbs
79
- homepage: https://github.com/JorgeGarciaxyz/slither
37
+ homepage: https://github.com/ryanwood/slither
80
38
  licenses:
81
39
  - MIT
82
- metadata: {}
40
+ metadata:
41
+ rubygems_mfa_required: 'true'
83
42
  post_install_message:
84
43
  rdoc_options: []
85
44
  require_paths:
@@ -88,14 +47,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
47
  requirements:
89
48
  - - ">="
90
49
  - !ruby/object:Gem::Version
91
- version: 3.0.0
50
+ version: 3.2.0
92
51
  required_rubygems_version: !ruby/object:Gem::Requirement
93
52
  requirements:
94
53
  - - ">="
95
54
  - !ruby/object:Gem::Version
96
55
  version: '0'
97
56
  requirements: []
98
- rubygems_version: 3.3.7
57
+ rubygems_version: 3.4.10
99
58
  signing_key:
100
59
  specification_version: 4
101
60
  summary: A simple, clean DSL for describing, writing, and parsing fixed-width text