r_creds 0.1.0
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 +7 -0
- data/README.md +57 -0
- data/lib/r_creds.rb +8 -0
- data/lib/r_creds/fetcher.rb +43 -0
- data/lib/r_creds/version.rb +3 -0
- data/r_creds.gemspec +40 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 03db4fe4423fb4084b0d989b6335d6b02fcfbe744aa8b0f8ef502db271b98b35
|
4
|
+
data.tar.gz: b6d7c8d82034779ec276f7effa2bd4cd71e9992d0e6777bd5377c805800e610a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4d4af24c475d19b07981ed15edf7ed0309d26ae535ec8868cca3a4f80b905bbcc167091b231b089396da2aec061b3014766e6237bf4e0abdf5fbbc6351fce455
|
7
|
+
data.tar.gz: f084d270504dd7d687330c5366907d5316fcb27d5eb79117d6230b8febf924a38a05ff4b880e10b86de0ea9c9734e555b66a548cf3e9afa893de78e156cf680d
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# RCreds
|
2
|
+
|
3
|
+
Work simple with creds in Rails 5.2 and above!
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'r_creds'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install r_creds
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
RCreds give an ability to read credentials in credentials.yml, ENV or use default value!
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
# returns value from credentials.yml for current environment
|
27
|
+
RCreds.fetch(:payment_system, :secret_key)
|
28
|
+
```
|
29
|
+
```ruby
|
30
|
+
# returns value from credentials.yml for current environment or default
|
31
|
+
RCreds.fetch(:redis, :url, default: 'redis://localhost:6379/0')
|
32
|
+
```
|
33
|
+
```ruby
|
34
|
+
# if value is set in as ENV variable it will be fetched if it's not set in credentials.yml
|
35
|
+
# keys concatenates as in following example
|
36
|
+
ENV['REDIS_URL'] = 'redis://real_redis_url'
|
37
|
+
RCreds.fetch(:redis, :url, default: 'redis://localhost:6379/0') # output: redis://real_redis_url
|
38
|
+
```
|
39
|
+
RCreds search for values in following order: credentials.yml > ENV > default:
|
40
|
+
|
41
|
+
## Development
|
42
|
+
|
43
|
+
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.
|
44
|
+
|
45
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/r_creds. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
54
|
+
|
55
|
+
## Code of Conduct
|
56
|
+
|
57
|
+
Everyone interacting in the RCreds project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/r_creds/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/r_creds.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module RCreds
|
2
|
+
class Fetcher
|
3
|
+
class NoRailsError < StandardError; end
|
4
|
+
|
5
|
+
def initialize(keys, default)
|
6
|
+
@keys = keys
|
7
|
+
@default = default
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :keys, :default
|
11
|
+
|
12
|
+
def call
|
13
|
+
check_rails
|
14
|
+
fetch
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch
|
18
|
+
cred = Rails.application.credentials.dig(Rails.env.to_sym, *keys)
|
19
|
+
|
20
|
+
presence?(cred) || presence?(ENV[keys.join('_').upcase]) || default
|
21
|
+
end
|
22
|
+
|
23
|
+
def presence?(cred)
|
24
|
+
return nil if cred.nil?
|
25
|
+
|
26
|
+
present?(cred) ? cred : false
|
27
|
+
end
|
28
|
+
|
29
|
+
def present?(cred)
|
30
|
+
!blank?(cred)
|
31
|
+
end
|
32
|
+
|
33
|
+
def blank?(cred)
|
34
|
+
cred.respond_to?(:empty?) ? !!cred.empty? : !cred
|
35
|
+
end
|
36
|
+
|
37
|
+
def check_rails
|
38
|
+
return true if defined?(::Rails)
|
39
|
+
|
40
|
+
raise NoRailsError.new 'RCreds works with 5.2 and above'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/r_creds.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "r_creds/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "r_creds"
|
8
|
+
spec.version = RCreds::VERSION
|
9
|
+
spec.authors = ["OrestF"]
|
10
|
+
spec.email = ["falchuko@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = 'RCreds make working with Rails 5.2 credentials easier'
|
13
|
+
spec.description = 'RCreds make working with Rails 5.2 credentials easier'
|
14
|
+
spec.homepage = 'https://github.com/OrestF/r_creds'
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
# "public gem pushes."
|
24
|
+
# end
|
25
|
+
|
26
|
+
# Specify which files should be added to the gem when it is released.
|
27
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
28
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
29
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
30
|
+
end
|
31
|
+
spec.bindir = "exe"
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
spec.files = Dir['README.md', 'lib/**/*', 'lib/*', 'r_creds.gemspec']
|
35
|
+
|
36
|
+
|
37
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
38
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
39
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: r_creds
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- OrestF
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: RCreds make working with Rails 5.2 credentials easier
|
56
|
+
email:
|
57
|
+
- falchuko@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- README.md
|
63
|
+
- lib/r_creds.rb
|
64
|
+
- lib/r_creds/fetcher.rb
|
65
|
+
- lib/r_creds/version.rb
|
66
|
+
- r_creds.gemspec
|
67
|
+
homepage: https://github.com/OrestF/r_creds
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.7.3
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: RCreds make working with Rails 5.2 credentials easier
|
91
|
+
test_files: []
|