unifig-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ee97e3ee9ea7a7291cf9f7ade08f4094dda73d94f66b754212dd4b50da4809a6
4
+ data.tar.gz: 6836466d1255f6ff9e11a66e8441ce46a4230b1c61bd1dcfdf2a812c896ab40d
5
+ SHA512:
6
+ metadata.gz: 0e7fb023670ab143c7e962afc5d8034b7c1b10f49e15f9a3c58b5958e449d1de7ae561ccf7ee255dc375757b08caf985e85d3061b01e5c3f62bced894061026f
7
+ data.tar.gz: a04837c002905ca81012bca00a85869796bba7d2e78ce37aa119113b4e5bb97cf63ed9a7df39d79c0ba0607c006b3bdd617c7a6250a9c22765565b43ea30151a
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # [0.1.0][] (2022-07-24)
2
+
3
+ Initial release.
4
+
5
+ [0.1.0]: https://github.com/AaronLasseigne/unifig/compare/v0.0.0...v0.1.0
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,19 @@
1
+ # Contributing
2
+
3
+ For features please open a [discussion][] and we can make sure the feature fits with the gem before working on it.
4
+
5
+ ## Steps
6
+
7
+ 1. [Fork][] the repo.
8
+ 2. Add a breaking test for your change.
9
+ 3. Make the tests pass.
10
+ 4. Push your fork.
11
+ 5. Submit a pull request against the `next` branch.
12
+
13
+ ## Code Style
14
+
15
+ Running the tests using `rake` (with no args) will also check for style issues in the code.
16
+ If you have a failure you cannot figure out push the PR and ask for help.
17
+
18
+ [fork]: https://github.com/AaronLasseigne/unifig-rails/fork
19
+ [discussion]: https://github.com/AaronLasseigne/unifig-rails/discussions/categories/ideas
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Aaron Lasseigne
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,48 @@
1
+ # [Unifig::Rails][]
2
+
3
+ Adds [Rails][] support to [Unifig][].
4
+
5
+ [![Version](https://img.shields.io/gem/v/unifig-rails.svg?style=flat-square)](https://rubygems.org/gems/unifig-rails)
6
+ [![Test](https://img.shields.io/github/workflow/status/AaronLasseigne/unifig-rails/Test?label=Test&style=flat-square)](https://github.com/AaronLasseigne/unifig-rails/actions?query=workflow%3ATest)
7
+
8
+ ## Installation
9
+
10
+ Add it to your Gemfile:
11
+
12
+ ``` rb
13
+ gem 'unifig-rails', '~> 0.1.0'
14
+ ```
15
+
16
+ Run the configuration generator:
17
+
18
+ ``` sh
19
+ rails generate unifig:config
20
+ ```
21
+
22
+ This project uses [Semantic Versioning][].
23
+ Check out [GitHub releases][] for a detailed list of changes.
24
+
25
+ ## Usage
26
+
27
+ Once your Rails app has been started you will be able use Unifig with the setup you've created in `config/unifig.yml`.
28
+
29
+ For information on how to use Unifig see the [documentation][] for that gem.
30
+
31
+ ## Contributing
32
+
33
+ If you want to contribute to Unifig::Rails, please read [our contribution guidelines][].
34
+ A [complete list of contributors][] is available on GitHub.
35
+
36
+ ## License
37
+
38
+ Unifig is licensed under [the MIT License][].
39
+
40
+ [Unifig::Rails]: https://github.com/AaronLasseigne/unifig-rails
41
+ [Rails]: https://rubyonrails.org
42
+ [Unifig]: https://github.com/AaronLasseigne/unifig
43
+ [documentation]: https://github.com/AaronLasseigne/unifig#usage
44
+ [Semantic Versioning]: http://semver.org/spec/v2.0.0.html
45
+ [GitHub releases]: https://github.com/AaronLasseigne/unifig-rails/releases
46
+ [our contribution guidelines]: CONTRIBUTING.md
47
+ [complete list of contributors]: https://github.com/AaronLasseigne/unifig-rails/graphs/contributors
48
+ [the MIT License]: LICENSE.txt
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
4
+
5
+ module Unifig
6
+ # @private
7
+ class ConfigGenerator < ::Rails::Generators::Base
8
+ desc 'Create a Unifig configuration file.'
9
+ def config
10
+ abort 'A configuration file already exists.' if File.exist?(Unifig::Rails::CONFIG_PATH)
11
+
12
+ create_file Unifig::Rails::CONFIG_PATH, <<~YML
13
+ config:
14
+ providers: local
15
+
16
+
17
+ YML
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unifig
4
+ module Rails
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/railtie'
4
+ require 'unifig'
5
+
6
+ require_relative 'railtie'
7
+ require_relative 'rails/version'
8
+ require_relative '../generators/unifig/config_generator'
9
+
10
+ module Unifig
11
+ # @private
12
+ module Rails
13
+ # @private
14
+ CONFIG_PATH = File.join('config', 'unifig.yml')
15
+
16
+ def self.run
17
+ file_path = ::Rails.root.join(CONFIG_PATH)
18
+ Unifig::Init.load_file(file_path, env: ::Rails.env.to_sym) if File.exist?(file_path)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/railtie'
4
+
5
+ module Unifig
6
+ # @private
7
+ class Railtie < ::Rails::Railtie
8
+ config.before_configuration do
9
+ Rails.run
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,40 @@
1
+ RSpec.describe Unifig::ConfigGenerator do
2
+ it 'adds a generator to Rails' do
3
+ expect(rails('generate')).to include 'unifig:config'
4
+ end
5
+
6
+ it 'writes the file out' do
7
+ rails('generate unifig:config')
8
+ content = in_rails do
9
+ File.read(Unifig::Rails::CONFIG_PATH)
10
+ end
11
+
12
+ expect(content).to eql <<~YML
13
+ config:
14
+ providers: local
15
+
16
+
17
+ YML
18
+ end
19
+
20
+ context 'with an existing file' do
21
+ before do
22
+ write_config(<<~YML)
23
+ config:
24
+ providers: local
25
+
26
+ ONE:
27
+ value: 1
28
+ YML
29
+ end
30
+
31
+ it 'fails' do
32
+ rails('generate unifig:config')
33
+ content = in_rails do
34
+ File.read(Unifig::Rails::CONFIG_PATH)
35
+ end
36
+
37
+ expect(content).to include 'ONE'
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,87 @@
1
+ require 'fileutils'
2
+ require 'unifig/rails'
3
+
4
+ RSpec.configure do |config|
5
+ config.expect_with :rspec do |expectations|
6
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
7
+ expectations.on_potential_false_positives = :nothing
8
+ end
9
+
10
+ config.mock_with :rspec do |mocks|
11
+ mocks.verify_partial_doubles = true
12
+ end
13
+
14
+ config.shared_context_metadata_behavior = :apply_to_host_groups
15
+
16
+ config.filter_run_when_matching :focus
17
+
18
+ config.example_status_persistence_file_path = 'spec/examples.txt'
19
+
20
+ config.disable_monkey_patching!
21
+
22
+ config.warnings = true
23
+
24
+ config.default_formatter = 'doc' if config.files_to_run.one?
25
+
26
+ config.order = :random
27
+ Kernel.srand config.seed
28
+
29
+ config.before(:suite) do
30
+ Dir.mkdir('tmp') unless Dir.exist?('tmp')
31
+ cleanup
32
+
33
+ Dir.chdir('tmp') do
34
+ `bundle exec rails new example --minimal`
35
+ Dir.chdir('example') do
36
+ append_to_file('Gemfile', 'gem "unifig-rails", path: "../../"')
37
+ Bundler.with_unbundled_env do
38
+ `bundle install`
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ config.after(:suite) do
45
+ cleanup
46
+ end
47
+
48
+ config.after do
49
+ in_rails do
50
+ Dir.chdir('config') do
51
+ File.unlink('unifig.yml') if File.exist?('unifig.yml')
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ def cleanup
58
+ Dir.chdir('tmp') do
59
+ FileUtils.rm_rf('example') if Dir.exist?('example')
60
+ end
61
+ end
62
+
63
+ def append_to_file(file, addition)
64
+ File.write(file, "\n#{addition}", mode: 'a')
65
+ end
66
+
67
+ def in_rails(&block)
68
+ Dir.chdir('tmp') do
69
+ Dir.chdir('example', &block)
70
+ end
71
+ end
72
+
73
+ def write_config(yml)
74
+ in_rails do
75
+ Dir.chdir('config') do
76
+ File.write('unifig.yml', yml)
77
+ end
78
+ end
79
+ end
80
+
81
+ def rails(cmd)
82
+ in_rails do
83
+ Bundler.with_unbundled_env do
84
+ `bundle exec rails #{cmd}`
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Unifig::Railtie do
4
+ context 'before_configure' do
5
+ context 'without a config' do
6
+ it 'does nothing' do
7
+ expect(rails('runner "print Unifig.respond_to?(:foo)"')).to eql 'false'
8
+ end
9
+ end
10
+
11
+ context 'with a config' do
12
+ before do
13
+ write_config(<<~YML)
14
+ config:
15
+ providers: local
16
+
17
+ FOO:
18
+ value: 'foo'
19
+ YML
20
+ end
21
+
22
+ it 'writes to Unifig' do
23
+ expect(rails('runner "print Unifig.foo"')).to eql 'foo'
24
+ end
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unifig-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Lasseigne
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-07-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: unifig
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.0
41
+ description: Unifig support for Rails.
42
+ email:
43
+ - aaron.lasseigne@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - CHANGELOG.md
49
+ - CONTRIBUTING.md
50
+ - LICENSE.txt
51
+ - README.md
52
+ - lib/generators/unifig/config_generator.rb
53
+ - lib/unifig/rails.rb
54
+ - lib/unifig/rails/version.rb
55
+ - lib/unifig/railtie.rb
56
+ - spec/generators/unifig/config_generator_spec.rb
57
+ - spec/spec_helper.rb
58
+ - spec/unifig/railtie_spec.rb
59
+ homepage: https://github.com/AaronLasseigne/unifig-rails
60
+ licenses:
61
+ - MIT
62
+ metadata:
63
+ homepage_uri: https://github.com/AaronLasseigne/unifig-rails
64
+ source_code_uri: https://github.com/AaronLasseigne/unifig-rails
65
+ changelog_uri: https://github.com/AaronLasseigne/unifig-rails/blob/main/CHANGELOG.md
66
+ rubygems_mfa_required: 'true'
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 2.7.0
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.3.7
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Unifig support for Rails.
86
+ test_files:
87
+ - spec/generators/unifig/config_generator_spec.rb
88
+ - spec/spec_helper.rb
89
+ - spec/unifig/railtie_spec.rb