brutal 1.2.1 → 1.3.0

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: 958cf59b6aea2f5e323b849c83a86399cd9ad99e2433b899160a2422275a319e
4
- data.tar.gz: bdb36f749b6bfcb87683f12d3db9e74c716bdbfbf41e21c845864bf1e17f7a7e
3
+ metadata.gz: 7f98c650c2e97438b0cedcebdb5b01da84af29f7cbc0c324a4b3416b3da68114
4
+ data.tar.gz: 696e8e96639a62e046f138c10f3d5181a3265c90bb10306481bc0d2b2fd9d3d0
5
5
  SHA512:
6
- metadata.gz: 6f4b098047917136946c7bb88b111b5e6facf2a13ab70677bf0bce480bc2b4f0931f89f0be8ad2dc6db152abaaeffbdece5993d7ac5fba2ca85fde601df0c4c2
7
- data.tar.gz: 7d5d125189afacf46a008a6b12c79ec68ffeb6e15c4324c1a6924a19be9061dac5760224225a564a8a1d9410b18a3da80591beeb30e5abc15995a5094326fab4
6
+ metadata.gz: b6279a503eba6120d29cd8855fab48c725f46671bd8efa7d6fd73158e68d0cf6de9fed01e4f5ae83cf04417b0551ab9598d6c615d25b164fbefec1d3b7ce262f
7
+ data.tar.gz: 8aebd74fd0a2c9bda6b418980dd627645f9b1c85f3e92e753ba2c03bd642d0dd63393dfd8923ef25e470269e3b6645fa3428a54cd7b2128ca53ee2b5c9e5de63
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- The MIT License (MIT)
1
+ # The MIT License
2
2
 
3
3
  Copyright (c) 2020-2022 Cyril Kato
4
4
 
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Brutal 💎🔨
2
2
 
3
- [![Version](https://img.shields.io/github/v/tag/fixrb/brutal?label=Version&logo=github)](https://github.com/fixrb/brutal/releases)
3
+ [![Version](https://img.shields.io/github/v/tag/fixrb/brutal?label=Version&logo=github)](https://github.com/fixrb/brutal/tags)
4
4
  [![Yard documentation](https://img.shields.io/badge/Yard-documentation-blue.svg?logo=github)](https://rubydoc.info/github/fixrb/brutal/main)
5
- [![CI](https://github.com/fixrb/brutal/workflows/CI/badge.svg?branch=main)](https://github.com/fixrb/brutal/actions?query=workflow%3Aci+branch%3Amain)
5
+ [![Ruby](https://github.com/fixrb/brutal/workflows/Ruby/badge.svg?branch=main)](https://github.com/fixrb/brutal/actions?query=workflow%3Aruby+branch%3Amain)
6
6
  [![RuboCop](https://github.com/fixrb/brutal/workflows/RuboCop/badge.svg?branch=main)](https://github.com/fixrb/brutal/actions?query=workflow%3Arubocop+branch%3Amain)
7
7
  [![License](https://img.shields.io/github/license/fixrb/brutal?label=License&logo=github)](https://github.com/fixrb/brutal/raw/main/LICENSE.md)
8
8
 
@@ -59,18 +59,22 @@ Just type `brutal` in a Ruby project's folder and watch the magic happen.
59
59
 
60
60
  ## Usage
61
61
 
62
- The `brutal.yml` file is a manifest you can use to define your __Brutal__ meta-spec.
63
- It has 4 top-level sections:
62
+ __Brutal__ needs a configuration file, it's a kind of manifest, or a meta-spec if you prefer.
63
+ This file is composed of 4 top-level sections:
64
64
 
65
65
  * `header` - Specifies the code to execute before generating the test suite.
66
66
  * `subject` - Specifies the template of the code to be declined across contexts.
67
67
  * `contexts` - Specifies a list of variables to populate the subject's template.
68
68
  * `actuals` - Specifies templates to challenge evaluated subjects & get results.
69
69
 
70
+ By default, this file is called `.brutal.yml`, but it would be possible to call it differently by passing it as an argument to the brutal command.
71
+
72
+ Currently, only the YAML format is supported.
73
+
70
74
  ### Getting started
71
75
 
72
- 1. Create a `brutal.yml` file in your application's root directory.
73
- The following example `brutal.yml` defines the shape of a Hello test suite:
76
+ 1. Create a `.brutal.yml` file in your application's root directory.
77
+ The following example `.brutal.yml` defines the shape of a Hello test suite:
74
78
 
75
79
  ```yaml
76
80
  ---
@@ -145,9 +149,7 @@ The [gem](https://rubygems.org/gems/brutal) is available as open source under th
145
149
 
146
150
  ***
147
151
 
148
- <p>
149
- This project is sponsored by:<br />
150
- <a href="https://sashite.com/"><img
151
- src="https://github.com/fixrb/brutal/raw/main/img/sashite.png"
152
- alt="Sashite" /></a>
153
- </p>
152
+ This project is sponsored by [Sashité](https://github.com/sashite/):
153
+
154
+ ![Sashité logo](https://github.com/fixrb/brutal/raw/main/img/sponsor/dark/en/sashite.png#gh-dark-mode-only "Sashité")
155
+ ![Sashité logo](https://github.com/fixrb/brutal/raw/main/img/sponsor/light/en/sashite.png#gh-light-mode-only "Sashité")
data/bin/brutal CHANGED
@@ -3,4 +3,4 @@
3
3
 
4
4
  require_relative File.join("..", "lib", "brutal")
5
5
 
6
- Brutal.generate!
6
+ Brutal.generate! ARGV.fetch(0, Brutal::File::DEFAULT_CONFIG_FILENAME)
@@ -1,19 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Brutal
4
- # Brutal::File
5
- #
6
- # @since 1.1.0
7
4
  module File
8
5
  # Brutal::File::Read
9
6
  #
10
7
  # @since 1.1.0
11
8
  class Read
12
- NAME = ".brutal.yml"
13
-
14
9
  attr_reader :name
15
10
 
16
- def initialize(name = NAME)
11
+ def initialize(name)
17
12
  @name = name
18
13
  end
19
14
 
@@ -1,19 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Brutal
4
- # Brutal::File
5
- #
6
- # @since 1.1.0
7
4
  module File
8
5
  # Brutal::File::Write
9
6
  #
10
7
  # @since 1.1.0
11
8
  class Write
12
- NAME = "test.rb"
13
-
14
9
  attr_reader :name
15
10
 
16
- def initialize(name = NAME)
11
+ def initialize(name)
17
12
  @name = name
18
13
  end
19
14
 
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ %w[
4
+ read
5
+ write
6
+ ].each { |filename| require_relative(File.join("file", filename)) }
7
+
8
+ module Brutal
9
+ # Brutal::File
10
+ module File
11
+ DEFAULT_CONFIG_FILENAME = ".brutal.yml"
12
+ DEFAULT_GENERATED_FILENAME = "test.rb"
13
+
14
+ def self.generated_filename(filename)
15
+ return DEFAULT_GENERATED_FILENAME if filename == DEFAULT_CONFIG_FILENAME
16
+
17
+ filename.gsub(/.[^.]+\z/, ".rb")
18
+ end
19
+ end
20
+ end
@@ -51,7 +51,7 @@ module Brutal
51
51
 
52
52
  string = <<~CODE
53
53
  actual = begin
54
- #{actual_str.gsub(/^/, " ")}
54
+ #{actual_str.gsub(/^/, ' ')}
55
55
  end
56
56
 
57
57
  CODE
@@ -68,8 +68,8 @@ module Brutal
68
68
  end
69
69
 
70
70
  def blank_line
71
- "\n" \
72
- "# #{"-" * 78}\n" \
71
+ "\n" \
72
+ "# #{'-' * 78}\n" \
73
73
  "\n"
74
74
  end
75
75
 
data/lib/brutal/yaml.rb CHANGED
@@ -7,8 +7,18 @@ module Brutal
7
7
  #
8
8
  # @since 1.1.0
9
9
  module Yaml
10
+ FILENAME_EXTENSIONS = %w[
11
+ yaml
12
+ yml
13
+ ].freeze
14
+
10
15
  def self.parse(yaml)
11
16
  ::YAML.safe_load(yaml, symbolize_names: false)
12
17
  end
18
+
19
+ def self.parse?(filename)
20
+ filename_extension = filename.split(".")[1..][-1]
21
+ FILENAME_EXTENSIONS.include?(filename_extension)
22
+ end
13
23
  end
14
24
  end
data/lib/brutal.rb CHANGED
@@ -2,17 +2,23 @@
2
2
 
3
3
  %w[
4
4
  configuration
5
- file/read
6
- file/write
5
+ file
7
6
  scaffold
8
7
  yaml
9
- ].each { |file_name| require_relative(File.join("brutal", file_name)) }
8
+ ].each { |filename| require_relative(File.join("brutal", filename)) }
10
9
 
11
10
  # The Brutal namespace.
12
11
  module Brutal
13
- def self.generate!
14
- yaml = File::Read.new.call
15
- hash = Yaml.parse(yaml)
12
+ def self.generate!(filename)
13
+ file = File::Read.new(filename).call
14
+
15
+ hash = if Yaml.parse?(filename)
16
+ Yaml.parse(file)
17
+ else
18
+ raise ::ArgumentError, "Unrecognized extension. " \
19
+ "Impossible to parse #{filename.inspect}."
20
+ end
21
+
16
22
  conf = Configuration.load(hash)
17
23
 
18
24
  ruby = Scaffold.new(conf.header,
@@ -20,6 +26,8 @@ module Brutal
20
26
  *conf.actuals,
21
27
  **conf.contexts)
22
28
 
23
- File::Write.new.call(ruby)
29
+ new_filename = File.generated_filename(filename)
30
+
31
+ File::Write.new(new_filename).call(ruby)
24
32
  end
25
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brutal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Kato
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-03 00:00:00.000000000 Z
11
+ date: 2022-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop-gitlab-security
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rubocop-md
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -134,6 +148,7 @@ files:
134
148
  - bin/brutal
135
149
  - lib/brutal.rb
136
150
  - lib/brutal/configuration.rb
151
+ - lib/brutal/file.rb
137
152
  - lib/brutal/file/read.rb
138
153
  - lib/brutal/file/write.rb
139
154
  - lib/brutal/scaffold.rb