config_rbs_generator 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b6deabab848b4d6d5d8a557cdb51fdea4c8cf6162a7450cea3a8435153d591af
4
+ data.tar.gz: ca955203b2d4cfd196d7a0da8f2125a8e6265daf5eb3511f8b0334c98d4327e4
5
+ SHA512:
6
+ metadata.gz: 66c56ee05c827aaefc32fa749c5f3f484efff5134d1c0b0425973aed2eaca7f221e73beb0f186ab82c3f9ee31a932aeed3126de0fcd5910be052eca20f78fc10
7
+ data.tar.gz: 5471f09b794746be9ecb8db0c2802bdf297fc02575203f0ed2ec25a9e5e930c5be9cd21be103849ebad42feeb8f8ba4dfa4bdcf7190e053c2a0d7c2a7de75a1a
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ TargetRubyVersion: 3.0
4
+ SuggestExtensions: false
5
+
6
+ Metrics/BlockLength:
7
+ Enabled: false
8
+
9
+ Metrics/MethodLength:
10
+ Enabled: false
11
+
12
+ Style/BlockDelimiters:
13
+ Enabled: false
14
+
15
+ Style/Documentation:
16
+ Enabled: false
17
+
18
+ Style/StringLiterals:
19
+ Enabled: true
20
+
21
+ Style/StringLiteralsInInterpolation:
22
+ Enabled: true
23
+
24
+ Layout/LineLength:
25
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-08-10
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in config_rbs_generator.gemspec
6
+ gemspec
7
+
8
+ gem 'config'
9
+ gem 'minitest'
10
+ gem 'rake', '~> 13.0'
11
+ gem 'rubocop', '~> 1.21'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 fugakkbn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ [![test - Ruby 3.1](https://github.com/fugakkbn/config_rbs_generator/actions/workflows/test_ruby_3.1.yml/badge.svg)](https://github.com/fugakkbn/config_rbs_generator/actions/workflows/test_ruby_3.1.yml)
2
+ [![RuboCop - Ruby 3.1](https://github.com/fugakkbn/config_rbs_generator/actions/workflows/rubocop_ruby_3.1.yml/badge.svg)](https://github.com/fugakkbn/config_rbs_generator/actions/workflows/rubocop_ruby_3.1.yml)
3
+ [![test - Ruby 3.0](https://github.com/fugakkbn/config_rbs_generator/actions/workflows/test_ruby_3.0.yml/badge.svg)](https://github.com/fugakkbn/config_rbs_generator/actions/workflows/test_ruby_3.0.yml)
4
+ [![RuboCop - Ruby 3.0](https://github.com/fugakkbn/config_rbs_generator/actions/workflows/rubocop_ruby_3.0.yml/badge.svg)](https://github.com/fugakkbn/config_rbs_generator/actions/workflows/rubocop_ruby_3.0.yml)
5
+
6
+ # config_rbs_generator
7
+
8
+ The `config_rbs_generator` generates an RBS for the `Settings` object that can be handled by the `config` gem.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'config_rbs_generator', require: false
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle install
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install config_rbs_generator
25
+
26
+ ## Usage
27
+
28
+ Simply run the following command in the root directory of your Rails project.
29
+
30
+ $ bundle exec config_rbs_generate
31
+
32
+ The RBS will then appear in the console. Place rbs file in the location of your choice and copy & paste.
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/test_*.rb']
10
+ end
11
+
12
+ require 'rubocop/rake_task'
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'config_rbs_generator'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'config'
4
+
5
+ Config.setup do |config|
6
+ config.const_name = 'Settings'
7
+ config.load_and_set_settings('config/settings.yml')
8
+ end
@@ -0,0 +1,25 @@
1
+ size: 2
2
+ text: How are you?
3
+ array:
4
+ - 10
5
+ - Nice to meet you!
6
+ - Goodbye.
7
+ section:
8
+ size: 3
9
+ text: Hello World!
10
+ yeah:
11
+ mettya:
12
+ holiday: Sunday
13
+ paragraph:
14
+ - paragraph1
15
+ - paragraph2
16
+ uho:
17
+ - name: name1
18
+ title: title1
19
+ body: body1
20
+ - name: name2
21
+ title: title2
22
+ body: body2
23
+ - name: name3
24
+ title: title3
25
+ body: body3
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/config_rbs_generator/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'config_rbs_generator'
7
+ spec.version = ConfigRbsGenerator::VERSION
8
+ spec.authors = ['fugakkbn']
9
+ spec.email = ['aax.chiri@gmail.com']
10
+
11
+ spec.summary = 'This gem generates RBS files for `Settings` objects created by the config gem.'
12
+ spec.homepage = 'https://github.com/fugakkbn/config_rbs_generator'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = '>= 3.0.0'
15
+
16
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
17
+
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = spec.homepage
20
+ spec.metadata['changelog_uri'] = 'https://github.com/fugakkbn/config_rbs_generator/blob/main/CHANGELOG.md'
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
27
+ end
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ # Uncomment to register a new dependency of your gem
34
+ # spec.add_dependency "example-gem", "~> 1.0"
35
+
36
+ # For more information and examples about making a new gem, check out our
37
+ # guide at: https://bundler.io/guides/creating_gem.html
38
+ spec.metadata['rubygems_mfa_required'] = 'true'
39
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/config_rbs_generator'
5
+
6
+ puts '== generate started... =='
7
+ puts ConfigRbsGenerator.run
8
+ puts 'Settings RBS generated!'
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConfigRbsGenerator
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'config_rbs_generator/version'
4
+ require_relative '../config/initializers/config'
5
+
6
+ module ConfigRbsGenerator
7
+ def self.run
8
+ outputs = Outputs.new
9
+
10
+ Settings.each do |setting|
11
+ outputs.add_method_definition(setting)
12
+ end
13
+
14
+ outputs.finalize
15
+ outputs.text
16
+ end
17
+
18
+ class Outputs
19
+ attr_reader :text
20
+
21
+ def initialize
22
+ @text = "module #{Config.const_name}\n"
23
+ end
24
+
25
+ def add_method_definition(setting)
26
+ @text += " def self.#{setting[0]}: () -> "
27
+
28
+ if setting[1].instance_of?(Config::Options)
29
+ @text += "self\n"
30
+ setting[1].each { |s| add_method_definition(s) }
31
+ @text
32
+ elsif setting[1].instance_of?(Array)
33
+ convert_array_types(setting[1])
34
+ else
35
+ @text += "#{setting[1].class}\n"
36
+ end
37
+ end
38
+
39
+ def finalize
40
+ @text += "end\n"
41
+ end
42
+
43
+ private
44
+
45
+ def convert_array_types(array)
46
+ if array.map { |s| s.instance_of?(Config::Options) }.include?(true)
47
+ @text += "Array[untyped]\n"
48
+ else
49
+ klasses = array.map(&:class).uniq
50
+ @text += "Array[#{klasses.join(' | ')}]\n"
51
+ end
52
+ end
53
+ end
54
+
55
+ class Error < StandardError; end
56
+ end
@@ -0,0 +1,18 @@
1
+ module ConfigRbsGenerator
2
+ VERSION: String
3
+
4
+ def self.run: () -> String
5
+
6
+ class Outputs
7
+ @text: String
8
+
9
+ attr_reader text: ::String
10
+
11
+ def initialize: () -> void
12
+ def add_method_definition: ([::Symbol, ::String]
13
+ | [::Symbol, ::Integer]
14
+ | [::Symbol, ::Array[::String | ::Integer]]
15
+ | [::Symbol, Config::Options] setting) -> ::String
16
+ def finalize: -> ::String
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: config_rbs_generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - fugakkbn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-08-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - aax.chiri@gmail.com
16
+ executables:
17
+ - config_rbs_generate
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rubocop.yml"
22
+ - CHANGELOG.md
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - bin/console
28
+ - bin/setup
29
+ - config/initializers/config.rb
30
+ - config/settings.yml
31
+ - config_rbs_generator.gemspec
32
+ - exe/config_rbs_generate
33
+ - lib/config_rbs_generator.rb
34
+ - lib/config_rbs_generator/version.rb
35
+ - sig/config_rbs_generator.rbs
36
+ homepage: https://github.com/fugakkbn/config_rbs_generator
37
+ licenses:
38
+ - MIT
39
+ metadata:
40
+ allowed_push_host: https://rubygems.org
41
+ homepage_uri: https://github.com/fugakkbn/config_rbs_generator
42
+ source_code_uri: https://github.com/fugakkbn/config_rbs_generator
43
+ changelog_uri: https://github.com/fugakkbn/config_rbs_generator/blob/main/CHANGELOG.md
44
+ rubygems_mfa_required: 'true'
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 3.0.0
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 3.3.7
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: This gem generates RBS files for `Settings` objects created by the config
64
+ gem.
65
+ test_files: []