rails_env_helper 0.1.1 → 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: d08e46e7ff671016310ecf1006f5d056715dba5fbac185ba55ded1ed5473c69e
4
- data.tar.gz: acdbc48300384909f2c0c601b7996c1ffec0f97a52d55de7136c01b4f255b329
3
+ metadata.gz: f54357078a478eef71a95691ce0ab40aa4d48d44a0218447250baf806ecbd8d3
4
+ data.tar.gz: 5666a69771f6cd3c0eb15922e14c9f4365dd34eb5b55cd7f7c142412645bf544
5
5
  SHA512:
6
- metadata.gz: e8a649ead005b992815e655b3d2699d2aaaaaf78a110c4ff0b3226c2a13db6d5c8676b18bed4f69cf3c2d5b93aeef9e534b818cfa07f9e2c0c9f6c7808a64b78
7
- data.tar.gz: d939cf030e3eeccea5f3075d5cb61b902a21d30a6765e0caa2f311ec1a54ecbbcdd4b1ef6b6f7411feede460677a195be4092bad3ee8bb529be6412d563e9c35
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,2 +1,13 @@
1
1
  # rails_env_helper
2
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.
4
+
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.
6
+
7
+ The specific issue it aims to solve is twofold:
8
+
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.
10
+
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.
12
+
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.1"
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
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.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-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
@@ -40,9 +45,10 @@ files:
40
45
  - lib/rails_env_helper.rb
41
46
  - lib/rails_env_helper/version.rb
42
47
  - rails_env_helper-0.1.0.gem
48
+ - rails_env_helper-0.1.1.gem
43
49
  - rails_env_helper.gemspec
44
50
  - sig/rails_env_helper.rbs
45
- homepage:
51
+ homepage:
46
52
  licenses:
47
53
  - MIT
48
54
  metadata:
@@ -50,7 +56,7 @@ metadata:
50
56
  homepage_uri: https://github.com/Bhuvanesh-ROR/rails_env_helper
51
57
  source_code_uri: https://github.com/Bhuvanesh-ROR/rails_env_helper
52
58
  changelog_uri: https://github.com/Bhuvanesh-ROR/rails_env_helper/blob/main/CHANGELOG.md
53
- post_install_message:
59
+ post_install_message:
54
60
  rdoc_options: []
55
61
  require_paths:
56
62
  - lib
@@ -65,8 +71,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
71
  - !ruby/object:Gem::Version
66
72
  version: '0'
67
73
  requirements: []
68
- rubygems_version: 3.2.15
69
- signing_key:
74
+ rubygems_version: 3.0.3.1
75
+ signing_key:
70
76
  specification_version: 4
71
77
  summary: A helper gem for managing Rails environment variables
72
78
  test_files: []