rails_env_helper 0.1.1 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d08e46e7ff671016310ecf1006f5d056715dba5fbac185ba55ded1ed5473c69e
4
- data.tar.gz: acdbc48300384909f2c0c601b7996c1ffec0f97a52d55de7136c01b4f255b329
3
+ metadata.gz: 54d8382b9bb6e274a82f123248e5bf7a41a34664ca0891635d890548034fbd7b
4
+ data.tar.gz: b3079e18be966eac9fbd0fce492056fec8dae0a42a7f62847b07f619f739db2b
5
5
  SHA512:
6
- metadata.gz: e8a649ead005b992815e655b3d2699d2aaaaaf78a110c4ff0b3226c2a13db6d5c8676b18bed4f69cf3c2d5b93aeef9e534b818cfa07f9e2c0c9f6c7808a64b78
7
- data.tar.gz: d939cf030e3eeccea5f3075d5cb61b902a21d30a6765e0caa2f311ec1a54ecbbcdd4b1ef6b6f7411feede460677a195be4092bad3ee8bb529be6412d563e9c35
6
+ metadata.gz: 8fd299f3e1db5751d1a629e17f36d69a380077121aa778d8403e05c311ba87a8dd727dec86a58ad60bc0e11748282474f88cf3637e85e9cceed69a57746ce926
7
+ data.tar.gz: 512c19f4d6f4894883e9fb1ce479f9812debbeeaac9cd4e24c6b4529118f8be1eb39cca8986ac922bdf65d47a1e7120be0f8d65f088c57fd30c49c14954ee863
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.3"
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
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = "Simplify working with environment variables in a Ruby on Rails application."
13
13
  spec.license = "MIT"
14
14
  spec.required_ruby_version = ">= 2.6.0"
15
- spec.add_dependency "rails", "~> 6.0"
15
+ # spec.add_dependency "rails", "~> 6.0"
16
16
 
17
17
  spec.metadata = {
18
18
  "allowed_push_host" => 'https://rubygems.org',
metadata CHANGED
@@ -1,29 +1,15 @@
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.3
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
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rails
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '6.0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '6.0'
11
+ date: 2024-02-09 00:00:00.000000000 Z
12
+ dependencies: []
27
13
  description: Simplify working with environment variables in a Ruby on Rails application.
28
14
  email:
29
15
  - bhuvanesh@mallow-tech.com
@@ -31,6 +17,11 @@ executables: []
31
17
  extensions: []
32
18
  extra_rdoc_files: []
33
19
  files:
20
+ - ".idea/.gitignore"
21
+ - ".idea/misc.xml"
22
+ - ".idea/modules.xml"
23
+ - ".idea/rails_env_helper.iml"
24
+ - ".idea/vcs.xml"
34
25
  - ".rspec"
35
26
  - CHANGELOG.md
36
27
  - CODE_OF_CONDUCT.md
@@ -40,9 +31,10 @@ files:
40
31
  - lib/rails_env_helper.rb
41
32
  - lib/rails_env_helper/version.rb
42
33
  - rails_env_helper-0.1.0.gem
34
+ - rails_env_helper-0.1.1.gem
43
35
  - rails_env_helper.gemspec
44
36
  - sig/rails_env_helper.rbs
45
- homepage:
37
+ homepage:
46
38
  licenses:
47
39
  - MIT
48
40
  metadata:
@@ -50,7 +42,7 @@ metadata:
50
42
  homepage_uri: https://github.com/Bhuvanesh-ROR/rails_env_helper
51
43
  source_code_uri: https://github.com/Bhuvanesh-ROR/rails_env_helper
52
44
  changelog_uri: https://github.com/Bhuvanesh-ROR/rails_env_helper/blob/main/CHANGELOG.md
53
- post_install_message:
45
+ post_install_message:
54
46
  rdoc_options: []
55
47
  require_paths:
56
48
  - lib
@@ -65,8 +57,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
57
  - !ruby/object:Gem::Version
66
58
  version: '0'
67
59
  requirements: []
68
- rubygems_version: 3.2.15
69
- signing_key:
60
+ rubygems_version: 3.0.3.1
61
+ signing_key:
70
62
  specification_version: 4
71
63
  summary: A helper gem for managing Rails environment variables
72
64
  test_files: []