rails_env_helper 0.1.0 → 0.1.2
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 +4 -4
- data/.idea/.gitignore +8 -0
- data/.idea/misc.xml +4 -0
- data/.idea/modules.xml +8 -0
- data/.idea/rails_env_helper.iml +20 -0
- data/.idea/vcs.xml +6 -0
- data/CHANGELOG.md +4 -0
- data/README.md +8 -34
- data/lib/rails_env_helper/version.rb +1 -1
- data/lib/rails_env_helper.rb +37 -2
- data/rails_env_helper-0.1.0.gem +0 -0
- data/rails_env_helper-0.1.1.gem +0 -0
- data/rails_env_helper.gemspec +3 -3
- metadata +17 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f54357078a478eef71a95691ce0ab40aa4d48d44a0218447250baf806ecbd8d3
|
4
|
+
data.tar.gz: 5666a69771f6cd3c0eb15922e14c9f4365dd34eb5b55cd7f7c142412645bf544
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63f8c27b39795f05b0273e120d4f104d77793b564d1e15e550f3f6f1cd0b942f8c3b857cfbca7b73948879fda38098775ea1c1c2b1f1fd0de6a32aa5dfb64b54
|
7
|
+
data.tar.gz: f98c7c26da4e41cd9c8f1a6c2cb4162a9ba4861a46300f5df2daca2a5b8ff285d5124a4662d9b5264570c01df4df441eedc4476a2192f6cdecedaaeb9f5c0fe4
|
data/.idea/.gitignore
ADDED
data/.idea/misc.xml
ADDED
data/.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/rails_env_helper.iml" filepath="$PROJECT_DIR$/.idea/rails_env_helper.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="ModuleRunConfigurationManager">
|
4
|
+
<shared />
|
5
|
+
</component>
|
6
|
+
<component name="NewModuleRootManager">
|
7
|
+
<content url="file://$MODULE_DIR$">
|
8
|
+
<sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
|
9
|
+
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
10
|
+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
11
|
+
</content>
|
12
|
+
<orderEntry type="inheritedJdk" />
|
13
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
14
|
+
</component>
|
15
|
+
<component name="RakeTasksCache">
|
16
|
+
<option name="myRootTask">
|
17
|
+
<RakeTaskImpl id="rake" />
|
18
|
+
</option>
|
19
|
+
</component>
|
20
|
+
</module>
|
data/.idea/vcs.xml
ADDED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,39 +1,13 @@
|
|
1
|
-
#
|
1
|
+
# rails_env_helper
|
2
|
+
Simplify working with environment variables in a Ruby on Rails application.
|
3
|
+
rails_env_helper, is designed to simplify the handling of environment variables in a Ruby on Rails application, particularly in different environments like development, test, and production. It attempts to address a common challenge faced by Rails developers, which involves managing and accessing environment variables in a consistent and convenient way.
|
2
4
|
|
3
|
-
|
5
|
+
In a typical Rails application, developers often need to differentiate how environment variables are accessed based on the application's runtime environment (e.g., development, production). The example gem provides a helper method, RailsEnvHelper.get_env, that abstracts away the complexity of accessing environment variables, making the code cleaner and more Rails-centric.
|
4
6
|
|
5
|
-
|
7
|
+
The specific issue it aims to solve is twofold:
|
6
8
|
|
7
|
-
|
9
|
+
-> Consistent Handling of Environment Variables: The gem provides a unified method, RailsEnvHelper.get_env, to fetch environment variables. In production, it retrieves the variable directly from ENV, while in non-production environments (e.g., development), it leverages Rails credentials for a more secure and organized approach.
|
8
10
|
|
9
|
-
|
11
|
+
-> Simplified Code for Environment Variable Access: Developers can use a single method call (RailsEnvHelper.get_env) to access environment variables, regardless of the runtime environment. This reduces the need for conditional checks and allows for more straightforward and readable code.
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
14
|
-
|
15
|
-
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
-
|
17
|
-
$ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
|
-
## Development
|
24
|
-
|
25
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
-
|
27
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
-
|
29
|
-
## Contributing
|
30
|
-
|
31
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rails_env_helper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/rails_env_helper/blob/main/CODE_OF_CONDUCT.md).
|
32
|
-
|
33
|
-
## License
|
34
|
-
|
35
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
36
|
-
|
37
|
-
## Code of Conduct
|
38
|
-
|
39
|
-
Everyone interacting in the RailsEnvHelper project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rails_env_helper/blob/main/CODE_OF_CONDUCT.md).
|
13
|
+
By addressing these issues, the gem aims to enhance the developer experience when working with environment variables in a Ruby on Rails application, promoting consistency and simplicity in code implementation.
|
data/lib/rails_env_helper.rb
CHANGED
@@ -3,7 +3,42 @@
|
|
3
3
|
require_relative "rails_env_helper/version"
|
4
4
|
|
5
5
|
module RailsEnvHelper
|
6
|
-
|
7
|
-
|
6
|
+
class << self
|
7
|
+
def initialize_env_variables(config_file_path)
|
8
|
+
begin
|
9
|
+
env_vars = load_env_variables(config_file_path)
|
10
|
+
set_env_variables(env_vars)
|
11
|
+
return "Environment variables initialized successfully."
|
12
|
+
rescue Errno::ENOENT
|
13
|
+
return "Error: Configuration file not found at #{config_file_path}."
|
14
|
+
rescue Psych::SyntaxError
|
15
|
+
return "Error: Invalid YAML syntax in the configuration file."
|
16
|
+
rescue StandardError => e
|
17
|
+
return "Error: #{e.message}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_env(variable_name)
|
22
|
+
if Rails.env.production?
|
23
|
+
ENV[variable_name]
|
24
|
+
else
|
25
|
+
Rails.application.credentials[variable_name]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def load_env_variables(config_file_path)
|
32
|
+
env_vars_file = Rails.root.join(config_file_path)
|
33
|
+
YAML.load_file(env_vars_file)
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_env_variables(env_vars)
|
37
|
+
Rails.application.configure do
|
38
|
+
env_vars[Rails.env].each do |key, value|
|
39
|
+
ENV[key] ||= value.to_s
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
8
43
|
end
|
9
44
|
end
|
Binary file
|
Binary file
|
data/rails_env_helper.gemspec
CHANGED
@@ -16,9 +16,9 @@ Gem::Specification.new do |spec|
|
|
16
16
|
|
17
17
|
spec.metadata = {
|
18
18
|
"allowed_push_host" => 'https://rubygems.org',
|
19
|
-
"homepage_uri" => 'https://github.com/Bhuvanesh-ROR/
|
20
|
-
"source_code_uri" => 'https://github.com/Bhuvanesh-ROR/
|
21
|
-
"changelog_uri" => 'https://github.com/Bhuvanesh-ROR/
|
19
|
+
"homepage_uri" => 'https://github.com/Bhuvanesh-ROR/rails_env_helper',
|
20
|
+
"source_code_uri" => 'https://github.com/Bhuvanesh-ROR/rails_env_helper',
|
21
|
+
"changelog_uri" => 'https://github.com/Bhuvanesh-ROR/rails_env_helper/blob/main/CHANGELOG.md',
|
22
22
|
}
|
23
23
|
|
24
24
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_env_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bhuvanesh Ganesan
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -31,6 +31,11 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
+
- ".idea/.gitignore"
|
35
|
+
- ".idea/misc.xml"
|
36
|
+
- ".idea/modules.xml"
|
37
|
+
- ".idea/rails_env_helper.iml"
|
38
|
+
- ".idea/vcs.xml"
|
34
39
|
- ".rspec"
|
35
40
|
- CHANGELOG.md
|
36
41
|
- CODE_OF_CONDUCT.md
|
@@ -39,17 +44,19 @@ files:
|
|
39
44
|
- Rakefile
|
40
45
|
- lib/rails_env_helper.rb
|
41
46
|
- lib/rails_env_helper/version.rb
|
47
|
+
- rails_env_helper-0.1.0.gem
|
48
|
+
- rails_env_helper-0.1.1.gem
|
42
49
|
- rails_env_helper.gemspec
|
43
50
|
- sig/rails_env_helper.rbs
|
44
|
-
homepage:
|
51
|
+
homepage:
|
45
52
|
licenses:
|
46
53
|
- MIT
|
47
54
|
metadata:
|
48
55
|
allowed_push_host: https://rubygems.org
|
49
|
-
homepage_uri: https://github.com/Bhuvanesh-ROR/
|
50
|
-
source_code_uri: https://github.com/Bhuvanesh-ROR/
|
51
|
-
changelog_uri: https://github.com/Bhuvanesh-ROR/
|
52
|
-
post_install_message:
|
56
|
+
homepage_uri: https://github.com/Bhuvanesh-ROR/rails_env_helper
|
57
|
+
source_code_uri: https://github.com/Bhuvanesh-ROR/rails_env_helper
|
58
|
+
changelog_uri: https://github.com/Bhuvanesh-ROR/rails_env_helper/blob/main/CHANGELOG.md
|
59
|
+
post_install_message:
|
53
60
|
rdoc_options: []
|
54
61
|
require_paths:
|
55
62
|
- lib
|
@@ -64,8 +71,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
71
|
- !ruby/object:Gem::Version
|
65
72
|
version: '0'
|
66
73
|
requirements: []
|
67
|
-
rubygems_version: 3.
|
68
|
-
signing_key:
|
74
|
+
rubygems_version: 3.0.3.1
|
75
|
+
signing_key:
|
69
76
|
specification_version: 4
|
70
77
|
summary: A helper gem for managing Rails environment variables
|
71
78
|
test_files: []
|