slither 0.99.5 → 0.99.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67bb6ad8dd4ac38f63231d77f9e366543cf9b11589e89760da6c85da9912995b
4
- data.tar.gz: 9b7be1bf9747a39d72ee06097226676c2d7c7a634f56fcbb290bf5d665b23fbb
3
+ metadata.gz: 768c19e4aa4f4c50f7dc74b68c303e65f86fce7bdc5adc6c19a4f241a21efbd7
4
+ data.tar.gz: 990745fa073fb8422a527334849dff46dd6d263de739feefd4355c2ca7aea3b5
5
5
  SHA512:
6
- metadata.gz: 72590afbfbceec05c54e67fa4f534c16207579a6fc3412ff19739e7ecc805864e044f6625b468827cb6dae7d627960a7b24895b25cced9b57ea5884bb217a82e
7
- data.tar.gz: e695c7f0871aae93d0fb2ae8c8e7cd10e36737304f5f9b244009728f44153bd9028c6f3085c0c433eb6e703cb4ba558c11e27479e80c416d460448b5eeed8a38
6
+ metadata.gz: 27fbfe19454cfb409d21666261d3fc913a75e4cb4a4fc7f7c8e6500f66257f4cb364087a7554f97d225d869a3788c841e7f6940df0fe32e09875aae8e63e162b
7
+ data.tar.gz: 4a163683f0cea49ba1747a875b472feb825fe79fbc1d7c59f1ce0ff526a9d31ec0a49d8519b895ccea9cb3b9945875f6989e8cd6ec5bf9ad7bcce67f560a3f6e
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
12
  gem "rubocop", "~> 1.21"
13
+ gem "rubocop-rspec", "~> 2.22.0", require: false
14
+ # Documentation tool
15
+ gem "yard"
data/Gemfile.lock CHANGED
@@ -14,7 +14,7 @@ GEM
14
14
  parallel (1.22.1)
15
15
  parser (3.2.0.0)
16
16
  ast (~> 2.4.1)
17
- pry (0.14.1)
17
+ pry (0.14.2)
18
18
  coderay (~> 1.1)
19
19
  method_source (~> 1.0)
20
20
  rainbow (3.1.1)
@@ -46,18 +46,30 @@ GEM
46
46
  unicode-display_width (>= 2.4.0, < 3.0)
47
47
  rubocop-ast (1.24.1)
48
48
  parser (>= 3.1.1.0)
49
+ rubocop-capybara (2.18.0)
50
+ rubocop (~> 1.41)
51
+ rubocop-factory_bot (2.23.1)
52
+ rubocop (~> 1.33)
53
+ rubocop-rspec (2.22.0)
54
+ rubocop (~> 1.33)
55
+ rubocop-capybara (~> 2.17)
56
+ rubocop-factory_bot (~> 2.22)
49
57
  ruby-progressbar (1.11.0)
50
58
  unicode-display_width (2.4.2)
59
+ yard (0.9.34)
51
60
 
52
61
  PLATFORMS
53
62
  ruby
54
63
 
55
64
  DEPENDENCIES
65
+ bundler
56
66
  pry
57
67
  rake (~> 13.0)
58
68
  rspec (~> 3.0)
59
69
  rubocop (~> 1.21)
70
+ rubocop-rspec (~> 2.22.0)
60
71
  slither!
72
+ yard
61
73
 
62
74
  BUNDLED WITH
63
75
  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.
@@ -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.6"
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,7 +17,13 @@ module Slither
19
17
  class LineWrongSizeError < StandardError; end
20
18
  class SectionsNotSameLengthError < StandardError; end
21
19
 
22
-
20
+ # Define a Slither's definition to parse a file.
21
+ #
22
+ # name - String name of the definition, this should be unique.
23
+ # options - Hash of options to pass to the definition.
24
+ # Ex: by_bytes: true, to parse by bytes
25
+ # Ex: align: :left, to align the columns to the left
26
+ # block - Block to define the sections of the definition. See README.md for more info.
23
27
  def self.define(name, options = {}, &block)
24
28
  definition = Definition.new(options)
25
29
  yield(definition)
@@ -31,19 +35,20 @@ module Slither
31
35
  def self.generate(definition_name, data)
32
36
  definition = definition(definition_name)
33
37
  raise ArgumentError, "Definition name '#{name}' was not found." unless definition
38
+
34
39
  generator = Generator.new(definition)
35
40
  generator.generate(data)
36
41
  end
37
42
 
38
43
  # Writes the File
39
44
  def self.write(filename, definition_name, data)
40
- File.open(filename, 'w') do |f|
45
+ File.open(filename, "w") do |f|
41
46
  f.write generate(definition_name, data)
42
47
  end
43
48
  end
44
49
 
45
50
  def self.parse(filename, definition_name)
46
- raise ArgumentError, "File #{filename} does not exist." unless File.exists?(filename)
51
+ raise ArgumentError, "File #{filename} does not exist." unless File.exist?(filename)
47
52
 
48
53
  file_io = File.open(filename, 'r')
49
54
  parseIo(file_io, definition_name)
@@ -52,6 +57,7 @@ module Slither
52
57
  def self.parseIo(io, definition_name)
53
58
  definition = definition(definition_name)
54
59
  raise ArgumentError, "Definition name '#{definition_name}' was not found." unless definition
60
+
55
61
  parser = Parser.new(definition, io)
56
62
  definition.options[:by_bytes] ? parser.parse_by_bytes : parser.parse
57
63
  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.6
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: 2024-01-22 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: