rails_env_helper 0.1.0 → 0.1.2

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: 4de8d4c3420376833d169cb1c8f2d0c1abaf065a5705479f1539104a4ec367ee
4
- data.tar.gz: b06b086ae21b480fcc7a17e5be376a13cecefe20fc2467efb60f31a1eb4d5969
3
+ metadata.gz: f54357078a478eef71a95691ce0ab40aa4d48d44a0218447250baf806ecbd8d3
4
+ data.tar.gz: 5666a69771f6cd3c0eb15922e14c9f4365dd34eb5b55cd7f7c142412645bf544
5
5
  SHA512:
6
- metadata.gz: 03a30b8ff56f3fdfc026efb84a348450cdecd162928fb764f4fc221693d18a37f709cc9b5c82838ad8a94e7c7f1cc833f63158a87d7e0f7a13f737fb463b753e
7
- data.tar.gz: d0c624625fcaaeaf9c113225386dd17ff12f204891d06824ef1cf11c89b1f5ea84e9b1494c1e4d4bcb5152c084f2ad6e68c9cad308a611b4176d310c8cb35f48
6
+ metadata.gz: 63f8c27b39795f05b0273e120d4f104d77793b564d1e15e550f3f6f1cd0b942f8c3b857cfbca7b73948879fda38098775ea1c1c2b1f1fd0de6a32aa5dfb64b54
7
+ data.tar.gz: f98c7c26da4e41cd9c8f1a6c2cb4162a9ba4861a46300f5df2daca2a5b8ff285d5124a4662d9b5264570c01df4df441eedc4476a2192f6cdecedaaeb9f5c0fe4
data/.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Editor-based HTTP Client requests
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
data/.idea/misc.xml ADDED
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="ruby-2.6.8-p205" project-jdk-type="RUBY_SDK" />
4
+ </project>
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
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
data/CHANGELOG.md CHANGED
@@ -3,3 +3,7 @@
3
3
  ## [0.1.0] - 2024-01-10
4
4
 
5
5
  - Initial release
6
+
7
+ ## [0.1.1] - 2024-01-10
8
+
9
+ - Initial gem setup
data/README.md CHANGED
@@ -1,39 +1,13 @@
1
- # RailsEnvHelper
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
- TODO: Delete this and the text below, and describe your gem
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rails_env_helper`. To experiment with that code, run `bin/console` for an interactive prompt.
7
+ The specific issue it aims to solve is twofold:
6
8
 
7
- ## Installation
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
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
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
- Install the gem and add to the application's Gemfile by executing:
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.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsEnvHelper
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
@@ -3,7 +3,42 @@
3
3
  require_relative "rails_env_helper/version"
4
4
 
5
5
  module RailsEnvHelper
6
- def self.get_env(variable_name)
7
- Rails.env.production? ? ENV[variable_name] : Rails.application.credentials[variable_name]
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
@@ -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/schedule_master',
20
- "source_code_uri" => 'https://github.com/Bhuvanesh-ROR/schedule_master',
21
- "changelog_uri" => 'https://github.com/Bhuvanesh-ROR/schedule_master/blob/main/CHANGELOG.md',
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.0
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-01-10 00:00:00.000000000 Z
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/schedule_master
50
- source_code_uri: https://github.com/Bhuvanesh-ROR/schedule_master
51
- changelog_uri: https://github.com/Bhuvanesh-ROR/schedule_master/blob/main/CHANGELOG.md
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.2.15
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: []