conifer 1.0.0 → 1.3.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: '09ced739ff40c2e3f5b4bc60431dfd578a4a700aed77be41aeb84ea0e62677c1'
4
+ data.tar.gz: 0f8950a612acf6f0b3b2ee1a0bf9f9414c68cf541f4fcb89ee0b144721070f53
5
5
  SHA512:
6
- metadata.gz: 4ddc85687be772047571e4c7f56a60e4b2b44f867828de6abc5e38c308467faba238b51c4a6b2d1f880dbb53d9df8938ec1714b96044026b4843d356b0be61b9
7
- data.tar.gz: 2567e3a020b165acdb8479ffe2b54163c69fe231814fa89a39eddb0df08751b2d305eccd663b44df07d0220d4caa22db78a122cb4c49ef2fef53b2beb780b346
6
+ metadata.gz: a981b2691bffaabc70e2c79d3d58b00c811bafb06ec47f3d7b6560aa057ef883e6231d03555f677c3c17c5995e001194eeab4bb1549be5554d1d8835b0c8a7dc
7
+ data.tar.gz: 7de081b9c44c12a4cbfb8201c39ea77fc3b0d1477c75a4f1518632d569363eedf59c3f24a105f6c0512bbfe17ef3894cb3204581fd9d93c35d51dbd55cdb6c5f
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
@@ -7,14 +7,27 @@ jobs:
7
7
 
8
8
  runs-on: ubuntu-latest
9
9
 
10
+ strategy:
11
+ matrix:
12
+ ruby:
13
+ - '2.6'
14
+ - '2.7'
15
+ - '3.0'
16
+ - '3.1'
17
+
10
18
  steps:
11
19
  - uses: actions/checkout@v2
12
- - name: Set up Ruby 2.6
13
- uses: actions/setup-ruby@v1
20
+
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ bundler-cache: true
26
+
27
+ - name: Run tests with RSpec
28
+ uses: paambaati/codeclimate-action@v2.7.5
29
+ env:
30
+ CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
14
31
  with:
15
- ruby-version: 2.6.x
16
- - name: Build and test with RSpec
17
- run: |
18
- gem install bundler -v 1.17.3 --no-document
19
- bundle install --jobs 4 --retry 3
20
- bundle exec rspec
32
+ coverageCommand: bundle exec rspec
33
+ debug: false
data/.rubocop.yml CHANGED
@@ -1,3 +1,10 @@
1
+ require:
2
+ - rubocop-rspec
3
+
4
+ AllCops:
5
+ NewCops: enable
6
+ TargetRubyVersion: 2.6
7
+
1
8
  Layout/LineLength:
2
9
  Max: 120
3
10
 
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.5
1
+ 3.0.0
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.1.0
data/Gemfile.lock CHANGED
@@ -1,35 +1,71 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- conifer (1.0.0)
4
+ conifer (1.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- diff-lcs (1.3)
10
- rake (10.5.0)
11
- rspec (3.8.0)
12
- rspec-core (~> 3.8.0)
13
- rspec-expectations (~> 3.8.0)
14
- rspec-mocks (~> 3.8.0)
15
- rspec-core (3.8.2)
16
- rspec-support (~> 3.8.0)
17
- rspec-expectations (3.8.4)
9
+ ast (2.4.2)
10
+ climate_control (1.0.0)
11
+ diff-lcs (1.4.4)
12
+ docile (1.3.5)
13
+ parallel (1.21.0)
14
+ parser (3.0.3.2)
15
+ ast (~> 2.4.1)
16
+ rainbow (3.0.0)
17
+ rake (13.0.3)
18
+ regexp_parser (2.2.0)
19
+ rexml (3.2.5)
20
+ rspec (3.10.0)
21
+ rspec-core (~> 3.10.0)
22
+ rspec-expectations (~> 3.10.0)
23
+ rspec-mocks (~> 3.10.0)
24
+ rspec-core (3.10.1)
25
+ rspec-support (~> 3.10.0)
26
+ rspec-expectations (3.10.1)
18
27
  diff-lcs (>= 1.2.0, < 2.0)
19
- rspec-support (~> 3.8.0)
20
- rspec-mocks (3.8.1)
28
+ rspec-support (~> 3.10.0)
29
+ rspec-mocks (3.10.2)
21
30
  diff-lcs (>= 1.2.0, < 2.0)
22
- rspec-support (~> 3.8.0)
23
- rspec-support (3.8.2)
31
+ rspec-support (~> 3.10.0)
32
+ rspec-support (3.10.2)
33
+ rubocop (1.24.0)
34
+ parallel (~> 1.10)
35
+ parser (>= 3.0.0.0)
36
+ rainbow (>= 2.2.2, < 4.0)
37
+ regexp_parser (>= 1.8, < 3.0)
38
+ rexml
39
+ rubocop-ast (>= 1.15.0, < 2.0)
40
+ ruby-progressbar (~> 1.7)
41
+ unicode-display_width (>= 1.4.0, < 3.0)
42
+ rubocop-ast (1.15.0)
43
+ parser (>= 3.0.1.1)
44
+ rubocop-rspec (2.3.0)
45
+ rubocop (~> 1.0)
46
+ rubocop-ast (>= 1.1.0)
47
+ ruby-progressbar (1.11.0)
48
+ simplecov (0.21.2)
49
+ docile (~> 1.1)
50
+ simplecov-html (~> 0.11)
51
+ simplecov_json_formatter (~> 0.1)
52
+ simplecov-html (0.12.3)
53
+ simplecov_json_formatter (0.1.2)
54
+ unicode-display_width (2.1.0)
24
55
 
25
56
  PLATFORMS
26
- ruby
57
+ x86_64-darwin-19
58
+ x86_64-darwin-20
59
+ x86_64-linux
27
60
 
28
61
  DEPENDENCIES
29
- bundler (~> 1.17)
62
+ climate_control
30
63
  conifer!
31
- rake (~> 10.0)
32
- rspec (~> 3.0)
64
+ rake
65
+ rspec
66
+ rubocop
67
+ rubocop-rspec
68
+ simplecov
33
69
 
34
70
  BUNDLED WITH
35
- 1.17.3
71
+ 2.3.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,11 +10,13 @@ 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
 
18
+ spec.required_ruby_version = '>= 2.6'
19
+
18
20
  # Specify which files should be added to the gem when it is released.
19
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
22
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
@@ -24,7 +26,10 @@ Gem::Specification.new do |spec|
24
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
27
  spec.require_paths = ['lib']
26
28
 
27
- spec.add_development_dependency 'bundler', '~> 1.17'
28
- spec.add_development_dependency 'rake', '~> 10.0'
29
- spec.add_development_dependency 'rspec', '~> 3.0'
29
+ spec.add_development_dependency 'climate_control'
30
+ spec.add_development_dependency 'rake'
31
+ spec.add_development_dependency 'rspec'
32
+ spec.add_development_dependency 'rubocop'
33
+ spec.add_development_dependency 'rubocop-rspec'
34
+ spec.add_development_dependency 'simplecov'
30
35
  end
data/lib/conifer/file.rb CHANGED
@@ -6,13 +6,16 @@ require 'erb'
6
6
  module Conifer
7
7
  class File
8
8
  NotFoundError = Class.new(StandardError)
9
+ UnsupportedFormatError = Class.new(StandardError)
9
10
 
10
- attr_reader :name, :prefix, :dir
11
+ attr_reader :name, :dir, :prefix, :format, :allowed_classes
11
12
 
12
- def initialize(name, dir:, prefix: nil)
13
+ def initialize(name, dir:, prefix: nil, format: :yml, allowed_classes: [])
13
14
  @name = name
14
- @prefix = prefix
15
15
  @dir = dir
16
+ @prefix = prefix
17
+ @format = format
18
+ @allowed_classes = allowed_classes
16
19
  end
17
20
 
18
21
  def [](key)
@@ -21,7 +24,14 @@ module Conifer
21
24
  end
22
25
 
23
26
  def parsed
24
- @parsed ||= YAML.safe_load(ERB.new(::File.read(path)).result)
27
+ @parsed ||= case format
28
+ when :yml, :yaml
29
+ YAML.safe_load(ERB.new(::File.read(path)).result, permitted_classes: allowed_classes)
30
+ when :json
31
+ JSON.parse(ERB.new(::File.read(path)).result)
32
+ else
33
+ raise UnsupportedFormatError, "Format '#{format}' is not supported"
34
+ end
25
35
  end
26
36
 
27
37
  def path
@@ -35,7 +45,7 @@ module Conifer
35
45
  end
36
46
 
37
47
  def filename
38
- "#{::File.basename(name.to_s, '.yml')}.yml"
48
+ "#{::File.basename(name.to_s, ".#{format}")}.#{format}"
39
49
  end
40
50
 
41
51
  def validate!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Conifer
4
- VERSION = '1.0.0'
4
+ VERSION = '1.3.0'
5
5
  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, format: :yml, method: ::File.basename(name.to_s, ".#{format}"),
14
+ singleton: false, 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, format: format,
22
+ dir: dir, allowed_classes: allowed_classes).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
metadata CHANGED
@@ -1,70 +1,115 @@
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.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hamed Asghari
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-26 00:00:00.000000000 Z
11
+ date: 2021-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: climate_control
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.17'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.17'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
55
- description: This is a gem to manage multiple, optionally environment-based YAML configurations
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Conifer allows you to easily manage YAML configuration files and import
98
+ them into your objects.
56
99
  email:
57
100
  - hasghari@gmail.com
58
101
  executables: []
59
102
  extensions: []
60
103
  extra_rdoc_files: []
61
104
  files:
105
+ - ".codeclimate.yml"
62
106
  - ".github/workflows/ruby.yml"
63
107
  - ".gitignore"
64
108
  - ".rspec"
65
109
  - ".rubocop.yml"
66
110
  - ".ruby-gemset"
67
111
  - ".ruby-version"
112
+ - ".tool-versions"
68
113
  - CODE_OF_CONDUCT.md
69
114
  - Gemfile
70
115
  - Gemfile.lock
@@ -81,7 +126,7 @@ homepage: https://github.com/hasghari/conifer
81
126
  licenses:
82
127
  - MIT
83
128
  metadata: {}
84
- post_install_message:
129
+ post_install_message:
85
130
  rdoc_options: []
86
131
  require_paths:
87
132
  - lib
@@ -89,15 +134,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
134
  requirements:
90
135
  - - ">="
91
136
  - !ruby/object:Gem::Version
92
- version: '0'
137
+ version: '2.6'
93
138
  required_rubygems_version: !ruby/object:Gem::Requirement
94
139
  requirements:
95
140
  - - ">="
96
141
  - !ruby/object:Gem::Version
97
142
  version: '0'
98
143
  requirements: []
99
- rubygems_version: 3.0.6
100
- signing_key:
144
+ rubygems_version: 3.3.3
145
+ signing_key:
101
146
  specification_version: 4
102
- summary: This is a gem to manage multiple, optionally environment-based YAML configurations
147
+ summary: Conifer allows you to easily manage YAML configuration files and import them
148
+ into your objects.
103
149
  test_files: []