conifer 1.0.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 242c45c7c55f650e17a190ab1451c4c44600d737881d8a2e37c10291c46f9e48
4
- data.tar.gz: 160ef67508c13a2e05e3efc9aa4dce2dd07bfd41c16979da8c77dc6b96bac2a4
3
+ metadata.gz: 0a170b07790bedd693faf1f86de8cea5bc2b6a8b1adcaa10360816a05a00de72
4
+ data.tar.gz: 6d3913dae889d4543fcda4c3686d88614c5bb95bfb8704fa41e55b4bb14731e6
5
5
  SHA512:
6
- metadata.gz: 4ddc85687be772047571e4c7f56a60e4b2b44f867828de6abc5e38c308467faba238b51c4a6b2d1f880dbb53d9df8938ec1714b96044026b4843d356b0be61b9
7
- data.tar.gz: 2567e3a020b165acdb8479ffe2b54163c69fe231814fa89a39eddb0df08751b2d305eccd663b44df07d0220d4caa22db78a122cb4c49ef2fef53b2beb780b346
6
+ metadata.gz: bfef2f2a00f2a7bbebd5c805876ee51276216c37169fc5e782f78ee218013de0f76afcc68abdea9b0844989dea9d9c7c7405e22ff75749c915068f734ef9880d
7
+ data.tar.gz: c13bc23806654f72898a68044485f294d4116fd127abd4cddbe0c45b11c6d46c59dd6c59eb9d1d5c89575b524b262325b3e5723a05c0c20fa7c6c175f1d78459
data/.codeclimate.yml ADDED
@@ -0,0 +1,15 @@
1
+ version: '2'
2
+
3
+ plugins:
4
+ bundler-audit:
5
+ enabled: true
6
+ duplication:
7
+ enabled: true
8
+ config:
9
+ languages:
10
+ - ruby
11
+ fixme:
12
+ enabled: true
13
+ rubocop:
14
+ enabled: true
15
+ channel: rubocop-0-80
@@ -13,8 +13,14 @@ jobs:
13
13
  uses: actions/setup-ruby@v1
14
14
  with:
15
15
  ruby-version: 2.6.x
16
- - name: Build and test with RSpec
16
+ - name: Configure Bundler
17
17
  run: |
18
18
  gem install bundler -v 1.17.3 --no-document
19
19
  bundle install --jobs 4 --retry 3
20
- bundle exec rspec
20
+ - name: Run tests with RSpec
21
+ uses: paambaati/codeclimate-action@v2.5.3
22
+ env:
23
+ CC_TEST_REPORTER_ID: 0e4e712966b3d2fdf63128dc4d0c863fd4c61888b557ffb1673111b4c8b3bdc9
24
+ with:
25
+ coverageCommand: bundle exec rspec
26
+ debug: false
data/.rubocop.yml CHANGED
@@ -1,3 +1,9 @@
1
+ require:
2
+ - rubocop-rspec
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.6
6
+
1
7
  Layout/LineLength:
2
8
  Max: 120
3
9
 
data/Gemfile.lock CHANGED
@@ -1,13 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- conifer (1.0.0)
4
+ conifer (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ ast (2.4.0)
10
+ climate_control (0.2.0)
9
11
  diff-lcs (1.3)
12
+ docile (1.3.2)
13
+ jaro_winkler (1.5.4)
14
+ json (2.3.0)
15
+ parallel (1.19.1)
16
+ parser (2.7.0.3)
17
+ ast (~> 2.4.0)
18
+ rainbow (3.0.0)
10
19
  rake (10.5.0)
20
+ rexml (3.2.4)
11
21
  rspec (3.8.0)
12
22
  rspec-core (~> 3.8.0)
13
23
  rspec-expectations (~> 3.8.0)
@@ -21,15 +31,36 @@ GEM
21
31
  diff-lcs (>= 1.2.0, < 2.0)
22
32
  rspec-support (~> 3.8.0)
23
33
  rspec-support (3.8.2)
34
+ rubocop (0.80.0)
35
+ jaro_winkler (~> 1.5.1)
36
+ parallel (~> 1.10)
37
+ parser (>= 2.7.0.1)
38
+ rainbow (>= 2.2.2, < 4.0)
39
+ rexml
40
+ ruby-progressbar (~> 1.7)
41
+ unicode-display_width (>= 1.4.0, < 1.7)
42
+ rubocop-rspec (1.38.1)
43
+ rubocop (>= 0.68.1)
44
+ ruby-progressbar (1.10.1)
45
+ simplecov (0.16.1)
46
+ docile (~> 1.1)
47
+ json (>= 1.8, < 3)
48
+ simplecov-html (~> 0.10.0)
49
+ simplecov-html (0.10.2)
50
+ unicode-display_width (1.6.1)
24
51
 
25
52
  PLATFORMS
26
53
  ruby
27
54
 
28
55
  DEPENDENCIES
29
56
  bundler (~> 1.17)
57
+ climate_control (~> 0.2)
30
58
  conifer!
31
59
  rake (~> 10.0)
32
60
  rspec (~> 3.0)
61
+ rubocop (~> 0.80)
62
+ rubocop-rspec (~> 1.38)
63
+ simplecov (= 0.16.1)
33
64
 
34
65
  BUNDLED WITH
35
66
  1.17.3
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
- # Conifer
1
+ ![](https://github.com/hasghari/conifer/workflows/Ruby/badge.svg)
2
+ [![Maintainability](https://api.codeclimate.com/v1/badges/f02c1de9e9d7dbfa5800/maintainability)](https://codeclimate.com/github/hasghari/conifer/maintainability)
3
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/f02c1de9e9d7dbfa5800/test_coverage)](https://codeclimate.com/github/hasghari/conifer/test_coverage)
2
4
 
3
- 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/conifer`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ # Conifer
4
6
 
5
- TODO: Delete this and the text above, and describe your gem
7
+ Conifer allows you to easily manage YAML configuration files and import them into your Ruby objects.
6
8
 
7
9
  ## Installation
8
10
 
@@ -22,7 +24,91 @@ Or install it yourself as:
22
24
 
23
25
  ## Usage
24
26
 
25
- TODO: Write usage instructions here
27
+ You can include the `Conifer` module in any class or module and specify the YAML file you want to import by calling the
28
+ `conifer` method:
29
+
30
+ ```ruby
31
+ class Config
32
+ include Conifer
33
+
34
+ conifer :config
35
+ end
36
+ ```
37
+
38
+ By default, this will look for a file called `config.yml` in the same directory where the `Config` class is defined.
39
+ If no such file is found, it will look for that file in the parent directory. It will continue to traverse the ancestry
40
+ tree until it finds that file. If the file is not found, it will raise a `Conifer::File::NotFoundError` error.
41
+
42
+ With the following `config.yml` file defined in the same directory as the source file for `Config`:
43
+
44
+ ```yaml
45
+ aws:
46
+ access_key_id: <%= ENV.fetch('AWS_ACCESS_KEY_ID', 'my-access-key-id') %>
47
+ bucket: atlantis
48
+ ```
49
+
50
+ You may access the values using a method that defaults to the same name as your YAML file:
51
+
52
+ ```ruby
53
+ object = Config.new
54
+ object.config['aws.access_key_id'] #=> my-access-key-id
55
+ object.config['aws.bucket'] #=> atlantis
56
+ ```
57
+
58
+ The `conifer` method accepts several optional keyword arguments:
59
+
60
+ - `dir`: This option overrides the default location where the YAML file is expected to reside.
61
+ - `method`: This option overrides the default method name that is defined on the class or module. The method name defaults to the name of the YAML file.
62
+ ```ruby
63
+ class Config
64
+ include Conifer
65
+
66
+ conifer :config, method: :foobar
67
+ end
68
+ ```
69
+
70
+ ```ruby
71
+ Config.new.foobar['aws.bucket'] #=> atlantis
72
+ ```
73
+ - `prefix`: This is a string that will be prepended to the lookup key. This is especially useful in Rails where you would like to have different values per environment.
74
+ ```ruby
75
+ class Config
76
+ include Conifer
77
+
78
+ conifer :config, prefix: Rails.env
79
+ end
80
+ ```
81
+
82
+ With the following `config.yml` file:
83
+
84
+ ```yaml
85
+ development:
86
+ aws:
87
+ bucket: atlantis-development
88
+
89
+ production:
90
+ aws:
91
+ bucket: atlantis-production
92
+ ```
93
+
94
+ You can lookup the values the same as before:
95
+
96
+ ```ruby
97
+ Rails.env #=> development
98
+ Config.new.config['aws.bucket'] #=> atlantis-development
99
+ ```
100
+ - `singleton`: This is `false` by default. When set to `true`, the method will be defined at the class scope instead of the instance scope.
101
+ ```ruby
102
+ class Config
103
+ include Conifer
104
+
105
+ conifer :config, singleton: true
106
+ end
107
+ ```
108
+
109
+ ```ruby
110
+ Config.config['aws.bucket'] #=> atlantis
111
+ ```
26
112
 
27
113
  ## Development
28
114
 
@@ -32,7 +118,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
118
 
33
119
  ## Contributing
34
120
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/conifer. 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.
121
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hasghari/conifer. 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.
36
122
 
37
123
  ## License
38
124
 
data/conifer.gemspec CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
10
10
  spec.authors = ['Hamed Asghari']
11
11
  spec.email = ['hasghari@gmail.com']
12
12
 
13
- spec.summary = 'This is a gem to manage multiple, optionally environment-based YAML configurations'
14
- spec.description = 'This is a gem to manage multiple, optionally environment-based YAML configurations'
13
+ spec.summary = 'Conifer allows you to easily manage YAML configuration files and import them into your objects.'
14
+ spec.description = 'Conifer allows you to easily manage YAML configuration files and import them into your objects.'
15
15
  spec.homepage = 'https://github.com/hasghari/conifer'
16
16
  spec.license = 'MIT'
17
17
 
@@ -25,6 +25,10 @@ Gem::Specification.new do |spec|
25
25
  spec.require_paths = ['lib']
26
26
 
27
27
  spec.add_development_dependency 'bundler', '~> 1.17'
28
+ spec.add_development_dependency 'climate_control', '~> 0.2'
28
29
  spec.add_development_dependency 'rake', '~> 10.0'
29
30
  spec.add_development_dependency 'rspec', '~> 3.0'
31
+ spec.add_development_dependency 'rubocop', '~> 0.80'
32
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.38'
33
+ spec.add_development_dependency 'simplecov', '0.16.1'
30
34
  end
data/lib/conifer.rb CHANGED
@@ -8,21 +8,22 @@ module Conifer
8
8
  base.extend ClassMethods
9
9
  end
10
10
 
11
+ # rubocop:disable Metrics/ParameterLists
11
12
  module ClassMethods
12
- def conifer(name, prefix: nil, dir: nil, method: ::File.basename(name.to_s, '.yml'), singleton: false)
13
+ def conifer(name, prefix: nil, dir: nil, method: ::File.basename(name.to_s, '.yml'), singleton: false,
14
+ allowed_classes: [])
13
15
  dir ||= ::File.expand_path(::File.dirname(caller_locations.first.path))
14
16
 
15
17
  body = proc do
16
18
  return instance_variable_get("@conifer_#{method}") if instance_variable_defined?("@conifer_#{method}")
17
19
 
18
- instance_variable_set "@conifer_#{method}", Conifer::File.new(name, prefix: prefix, dir: dir).tap(&:validate!)
20
+ instance_variable_set "@conifer_#{method}",
21
+ Conifer::File.new(name, prefix: prefix, dir: dir, allowed_classes: allowed_classes)
22
+ .tap(&:validate!)
19
23
  end
20
24
 
21
- if singleton
22
- define_singleton_method method, &body
23
- else
24
- define_method method, &body
25
- end
25
+ singleton ? define_singleton_method(method, &body) : define_method(method, &body)
26
26
  end
27
+ # rubocop:enable Metrics/ParameterLists
27
28
  end
28
29
  end
data/lib/conifer/file.rb CHANGED
@@ -7,12 +7,13 @@ module Conifer
7
7
  class File
8
8
  NotFoundError = Class.new(StandardError)
9
9
 
10
- attr_reader :name, :prefix, :dir
10
+ attr_reader :name, :prefix, :dir, :allowed_classes
11
11
 
12
- def initialize(name, dir:, prefix: nil)
12
+ def initialize(name, dir:, prefix: nil, allowed_classes: [])
13
13
  @name = name
14
14
  @prefix = prefix
15
15
  @dir = dir
16
+ @allowed_classes = allowed_classes
16
17
  end
17
18
 
18
19
  def [](key)
@@ -21,7 +22,7 @@ module Conifer
21
22
  end
22
23
 
23
24
  def parsed
24
- @parsed ||= YAML.safe_load(ERB.new(::File.read(path)).result)
25
+ @parsed ||= YAML.safe_load(ERB.new(::File.read(path)).result, allowed_classes)
25
26
  end
26
27
 
27
28
  def path
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Conifer
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conifer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hamed Asghari
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-26 00:00:00.000000000 Z
11
+ date: 2020-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: climate_control
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.2'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,13 +66,57 @@ dependencies:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '3.0'
55
- description: This is a gem to manage multiple, optionally environment-based YAML configurations
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.80'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.80'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.38'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.38'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.16.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.16.1
111
+ description: Conifer allows you to easily manage YAML configuration files and import
112
+ them into your objects.
56
113
  email:
57
114
  - hasghari@gmail.com
58
115
  executables: []
59
116
  extensions: []
60
117
  extra_rdoc_files: []
61
118
  files:
119
+ - ".codeclimate.yml"
62
120
  - ".github/workflows/ruby.yml"
63
121
  - ".gitignore"
64
122
  - ".rspec"
@@ -99,5 +157,6 @@ requirements: []
99
157
  rubygems_version: 3.0.6
100
158
  signing_key:
101
159
  specification_version: 4
102
- summary: This is a gem to manage multiple, optionally environment-based YAML configurations
160
+ summary: Conifer allows you to easily manage YAML configuration files and import them
161
+ into your objects.
103
162
  test_files: []