ettin 1.2.1 → 1.3.0

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: a255e66e3119d91b603833ea3a5b75e3aa1c5dbdd2c20bd8095b816c32ffaa57
4
- data.tar.gz: ee132d426757a520adbf9cb89fd74397ac8df28459310ee46783e61bd8052243
3
+ metadata.gz: 41fed733a48804c578d61f4a59536f3ba63a25bd3cb5595395189333309aba22
4
+ data.tar.gz: 6fce18aa306ba1415d5d8a723472f30c84e45f9a98ff0ad071545163ae3df76b
5
5
  SHA512:
6
- metadata.gz: d4af0bf580c3ba169d40c29eeeef5198f4129df173adf8858b3fdc9eb2db101493d2a44860df889473ea56221f161e7c7bd75c35ed9b50532e819c713c27c813
7
- data.tar.gz: 4333261bbf858c48859b1eb855c8655ff8842569898495977d2390b1a02ab9d0dcb59414566cce58b002102677df5250f6906b1e82693c8049b8258706069734
6
+ metadata.gz: 21b8171268a52679f6a6b3e21597b78368c09f7897c505bac79f7430ca6198ba366c6a8bf295c11a38bacb695f23df9ace31012358a74cfdc28529436ac4f951
7
+ data.tar.gz: 197dc51c977d51908e420b89a47007240df6de55d9b249ad2df6290afb88c8598a4d70d0501decab2299d950eda3db9120df15092da13163b91c939e6f1d659a
@@ -1,21 +1,38 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
1
4
  inherit_from: .rubocop_todo.yml
2
5
 
3
6
  AllCops:
4
7
  DisplayCopNames: true
5
8
  TargetRubyVersion: 2.3
6
9
  Exclude:
10
+ - 'lib/ettin/deep_transform.rb'
11
+ - '.bundle/**/*'
12
+ - 'vendor/bundle/**/*'
7
13
  - '*.gemspec'
14
+ - 'spec/fixtures/**/*'
8
15
 
9
16
  Naming/FileName:
10
17
  ExpectMatchingDefinition: true
11
18
  Exclude:
19
+ - 'bin/**/*'
20
+ - 'lib/core_extensions/**/*'
12
21
  - 'spec/**/*'
13
22
  - 'lib/*/version.rb'
14
23
 
24
+ RSpec/FilePath:
25
+ Exclude:
26
+ - 'spec/**/*.rb' # rubocop error
27
+
15
28
  Style/Documentation:
16
29
  Exclude:
17
30
  - 'spec/**/*'
18
31
 
32
+ # Enabling this cop can break rescue statements in ruby <= 2.4
33
+ Style/RedundantBegin:
34
+ Enabled: false
35
+
19
36
  # We disable this cop because we want to use Pathname#/
20
37
  # and this cop is not configurable at all.
21
38
  Layout/SpaceAroundOperators:
@@ -29,7 +46,7 @@ Style/Alias:
29
46
  EnforcedStyle: prefer_alias_method
30
47
 
31
48
  Metrics/LineLength:
32
- Max: 100
49
+ Max: 90
33
50
  AllowHeredoc: true
34
51
  AllowURI: true
35
52
  URISchemes:
@@ -38,15 +55,16 @@ Metrics/LineLength:
38
55
 
39
56
  Metrics/BlockLength:
40
57
  Exclude:
58
+ - 'spec/support/**/*.rb'
41
59
  - 'spec/**/*_spec.rb'
42
60
 
43
61
  Layout/ElseAlignment:
44
62
  Enabled: false
45
63
 
46
- Layout/FirstParameterIndentation:
64
+ Layout/IndentFirstArgument:
47
65
  EnforcedStyle: consistent
48
66
 
49
- Layout/AlignParameters:
67
+ Layout/AlignArguments:
50
68
  EnforcedStyle: with_fixed_indentation
51
69
 
52
70
  Layout/CaseIndentation:
@@ -58,6 +76,10 @@ Layout/ClosingParenthesisIndentation:
58
76
  Style/ClassAndModuleChildren:
59
77
  EnforcedStyle: nested
60
78
 
79
+ Metrics/ModuleLength:
80
+ Exclude:
81
+ - 'spec/**/*_spec.rb'
82
+
61
83
  Style/CommentAnnotation:
62
84
  Enabled: false
63
85
 
@@ -83,10 +105,10 @@ Style/GuardClause:
83
105
  Style/IfUnlessModifier:
84
106
  Enabled: false
85
107
 
86
- Layout/IndentArray:
108
+ Layout/IndentFirstArrayElement:
87
109
  EnforcedStyle: consistent
88
110
 
89
- Layout/IndentHash:
111
+ Layout/IndentFirstHashElement:
90
112
  EnforcedStyle: consistent
91
113
 
92
114
  Layout/AlignHash:
@@ -125,14 +147,13 @@ Layout/SpaceInsideBlockBraces:
125
147
  Style/SymbolArray:
126
148
  EnforcedStyle: brackets
127
149
 
128
- Lint/BlockAlignment:
150
+ Layout/BlockAlignment:
129
151
  EnforcedStyleAlignWith: start_of_block
130
- #EnforcedStyleAlignWith: start_of_line
131
152
 
132
- Lint/EndAlignment:
153
+ Layout/EndAlignment:
133
154
  EnforcedStyleAlignWith: start_of_line
134
155
 
135
- Lint/DefEndAlignment:
156
+ Layout/DefEndAlignment:
136
157
  EnforcedStyleAlignWith: def
137
158
 
138
159
  Performance/RedundantMerge:
@@ -141,3 +162,63 @@ Performance/RedundantMerge:
141
162
  Style/WordArray:
142
163
  EnforcedStyle: brackets
143
164
 
165
+ Style/RescueModifier:
166
+ Exclude:
167
+ - 'spec/**/*_spec.rb'
168
+
169
+ # This cop just adds extra work when you want to write an integration test,
170
+ # or test something like a jbuilder view.
171
+ RSpec/DescribeClass:
172
+ Enabled: false
173
+
174
+ # Using let! is fine, and can be easier to manage than a before block.
175
+ RSpec/LetSetup:
176
+ Enabled: false
177
+
178
+ RSpec/BeEql:
179
+ Enabled: false
180
+
181
+ RSpec/ExampleWithoutDescription:
182
+ EnforcedStyle: single_line_only
183
+
184
+ RSpec/HookArgument:
185
+ EnforcedStyle: each
186
+
187
+ RSpec/ImplicitSubject:
188
+ EnforcedStyle: disallow
189
+
190
+ RSpec/LeadingSubject:
191
+ Enabled: false
192
+
193
+ RSpec/MultipleExpectations:
194
+ Enabled: true
195
+ Max: 3
196
+
197
+ # Change this as needed.
198
+ RSpec/NestedGroups:
199
+ Max: 3
200
+
201
+ RSpec/VerifiedDoubles:
202
+ Enabled: false
203
+
204
+ RSpec/ExampleLength:
205
+ Max: 10
206
+
207
+ RSpec/MessageSpies:
208
+ EnforcedStyle: receive
209
+
210
+ RSpec/EmptyExampleGroup:
211
+ CustomIncludeMethods:
212
+ - it_allows
213
+ - it_disallows
214
+
215
+ RSpec/ContextWording:
216
+ Prefixes:
217
+ - as
218
+ - when
219
+ - with
220
+ - without
221
+
222
+ Lint/AmbiguousBlockAssociation:
223
+ Exclude:
224
+ - 'spec/**/*.rb'
@@ -11,20 +11,12 @@ branches:
11
11
  - master
12
12
  - develop
13
13
 
14
- env:
15
- global:
16
- - CC_TEST_REPORTER_ID=dfb947d165289cdfab764c2f143dc0b5097878f4100b5580cca3b06932e04840
17
-
18
14
  before_install: gem install bundler
19
15
 
20
- before_script:
21
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
22
- - chmod +x ./cc-test-reporter
23
- - ./cc-test-reporter before-build
24
-
25
16
  script:
26
17
  - bundle exec rspec --order=random
27
18
 
28
- after_script:
29
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT || true
30
-
19
+ matrix:
20
+ include:
21
+ - rvm: ruby-head
22
+ script: bundle exec rubocop
data/Gemfile CHANGED
@@ -7,3 +7,4 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
7
7
  # Specify your gem's dependencies in ettin.gemspec
8
8
  gemspec
9
9
 
10
+ gem "pry"
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Ettin
2
2
 
3
3
  [![Build Status](https://travis-ci.org/mlibrary/ettin.svg?branch=master)](https://travis-ci.org/mlibrary/ettin)
4
- [![Maintainability](https://api.codeclimate.com/v1/badges/efd34b151bad7dacb994/maintainability)](https://codeclimate.com/github/mlibrary/ettin/maintainability)
5
- [![Test Coverage](https://api.codeclimate.com/v1/badges/efd34b151bad7dacb994/test_coverage)](https://codeclimate.com/github/mlibrary/ettin/test_coverage)
4
+ [![Coverage Status](https://coveralls.io/repos/github/mlibrary/ettin/badge.svg?branch=master)](https://coveralls.io/github/mlibrary/ettin?branch=master)
5
+ [![API Docs](https://img.shields.io/badge/API_docs-rubydoc.info-blue.svg)](https://www.rubydoc.info/github/mlibrary/ettin)
6
6
 
7
7
  ## Summary
8
8
 
data/bin/ettin CHANGED
@@ -8,21 +8,23 @@ require "optparse"
8
8
 
9
9
  options = {}
10
10
  parser = OptionParser.new do |opts|
11
- opts.banner = "Creates the standard, empty config files starting from the given path.\n" \
12
- "Usage: ettin STARTPATH"
11
+ opts.banner = "Creates the standard, empty config files starting from the given " \
12
+ "path.\nUsage: ettin STARTPATH"
13
13
 
14
- opts.on("-p", "--path STARTPATH", "The root under which the files will be created.") do |p|
15
- options[:start_path] = p
16
- end
14
+ opts.on("-p", "--path STARTPATH",
15
+ "The root under which the files will be created.") do |p|
16
+ options[:start_path] = p
17
+ end
17
18
 
18
19
  opts.on("-v", "--[no-]verbose", "Print paths created") do |v|
19
20
  options[:verbose] = v
20
21
  end
21
22
 
22
23
  options[:compat] = false
23
- opts.on("-c", "--[no-]compat", "Create extra config files for compatibility with railsconfig gem.") do |c|
24
- options[:compat] = c
25
- end
24
+ opts.on("-c", "--[no-]compat",
25
+ "Create extra config files for compatibility with railsconfig gem.") do |c|
26
+ options[:compat] = c
27
+ end
26
28
 
27
29
  opts.on("-h", "--help", "Prints this help") do
28
30
  puts opts
@@ -45,7 +47,7 @@ files = ["development", "production", "test"]
45
47
  .uniq
46
48
 
47
49
  unless options[:compat]
48
- files.reject!{|path| path.dirname.basename.to_s == "environments" }
50
+ files.reject! {|path| path.dirname.basename.to_s == "environments" }
49
51
  end
50
52
 
51
53
  files.each do |path|
@@ -57,7 +59,7 @@ end
57
59
  puts "\nAdding .local.yml files to .gitignore" if options[:verbose]
58
60
  `echo "\n# Ignore local configuration files" >> .gitignore`
59
61
  files
60
- .select{|path| path.basename.to_s.include?("local")}
61
- .each{|path| `echo "#{path}" >> .gitignore`}
62
+ .select {|path| path.basename.to_s.include?("local") }
63
+ .each {|path| `echo "#{path}" >> .gitignore` }
62
64
 
63
65
  puts "" if options[:verbose]
@@ -24,8 +24,10 @@ Gem::Specification.new do |spec|
24
24
  spec.add_runtime_dependency "deep_merge"
25
25
 
26
26
  spec.add_development_dependency "bundler"
27
+ spec.add_development_dependency "coveralls"
27
28
  spec.add_development_dependency "rake"
28
29
  spec.add_development_dependency "rspec"
29
30
  spec.add_development_dependency "rubocop"
30
- spec.add_development_dependency "simplecov"
31
+ spec.add_development_dependency "rubocop-performance"
32
+ spec.add_development_dependency "rubocop-rspec"
31
33
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ettin
4
+
5
+ # A class for analyzing and manipulating a method's name
6
+ class MethodName
7
+ ASSIGN_CHAR = "="
8
+ BANG_CHAR = "!"
9
+
10
+ def initialize(method)
11
+ @method = method.to_s
12
+ end
13
+
14
+ def to_sym
15
+ method.to_sym
16
+ end
17
+
18
+ def to_s
19
+ method
20
+ end
21
+
22
+ def clean
23
+ @clean ||= if bang? || assignment?
24
+ method.chop
25
+ else
26
+ method
27
+ end.to_sym
28
+ end
29
+
30
+ def bang?
31
+ method[-1] == BANG_CHAR
32
+ end
33
+
34
+ def assignment?
35
+ method[-1] == ASSIGN_CHAR
36
+ end
37
+
38
+ private
39
+
40
+ attr_reader :method
41
+ end
42
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "deep_merge/rails_compat"
4
4
  require "forwardable"
5
+ require "ettin/method_name"
5
6
 
6
7
  module Ettin
7
8
 
@@ -18,37 +19,16 @@ module Ettin
18
19
  @hash.default = nil
19
20
  end
20
21
 
21
- def method_missing(method, *args, &block)
22
- if handles?(method)
23
- if !key?(debang(method))
24
- if bang?(method)
25
- raise KeyError, "key #{debang(method)} not found"
26
- else
27
- self[debang(method)]
28
- end
29
- else
30
- self[debang(method)]
31
- end
32
- else
33
- super(method, *args, &block)
34
- end
22
+ def method_missing(method, *args, &block) # rubocop:disable Style/MethodMissingSuper
23
+ return super(method, *args, &block) unless handles?(method)
35
24
 
36
- if handles?(method)
37
- if bang?(method)
38
- handle_bang_method(method)
39
- else
40
- self[debang(method)]
41
- end
42
- else
43
- super(method, *args, &block)
44
- end
45
- end
46
-
47
- def handle_bang_method(method)
48
- if key?(debang(method))
49
- self[debang(method)]
25
+ method = MethodName.new(method)
26
+ if method.bang?
27
+ handle_bang_method(method)
28
+ elsif method.assignment?
29
+ handle_assignment_method(method, *args)
50
30
  else
51
- raise KeyError, "key #{debang(method)} not found"
31
+ self[method.clean]
52
32
  end
53
33
  end
54
34
 
@@ -66,7 +46,9 @@ module Ettin
66
46
  alias_method :has_key?, :key?
67
47
 
68
48
  def merge(other)
69
- new_hash = {}.deeper_merge(hash).deeper_merge!(other.to_h, overwrite_arrays: true)
49
+ new_hash = {}
50
+ .deeper_merge(hash)
51
+ .deeper_merge!(other.to_h, overwrite_arrays: true)
70
52
  self.class.new(new_hash)
71
53
  end
72
54
 
@@ -101,20 +83,20 @@ module Ettin
101
83
 
102
84
  attr_reader :hash
103
85
 
104
- def handles?(method)
105
- /^[a-zA-Z_0-9]*\!?$/.match(method.to_s)
86
+ def handle_bang_method(method)
87
+ if key?(method.clean)
88
+ self[method.clean]
89
+ else
90
+ raise KeyError, "key #{method.clean} not found"
91
+ end
106
92
  end
107
93
 
108
- def bang?(method)
109
- method.to_s[-1] == "!"
94
+ def handle_assignment_method(method, *args)
95
+ self[method.clean] = args.first
110
96
  end
111
97
 
112
- def debang(method)
113
- if bang?(method)
114
- method.to_s.chop.to_sym
115
- else
116
- method
117
- end
98
+ def handles?(method)
99
+ /^[a-zA-Z_0-9]*(\!|=)?$/.match(method.to_s)
118
100
  end
119
101
 
120
102
  def convert_key(key)
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ettin
4
+
5
+ # Generic interface for data sources containing configuration information.
4
6
  class Source
5
7
  def self.for(target)
6
8
  registry.find {|candidate| candidate.handles?(target) }
@@ -8,7 +10,7 @@ module Ettin
8
10
  end
9
11
 
10
12
  def self.registry
11
- @@registry ||= []
13
+ @@registry ||= [] # rubocop:disable Style/ClassVars
12
14
  end
13
15
 
14
16
  def self.register(candidate)
@@ -21,6 +21,7 @@ module Ettin
21
21
 
22
22
  def load
23
23
  return {} unless File.exist?(path)
24
+
24
25
  begin
25
26
  YAML.safe_load(ERB.new(File.read(path)).result) || {}
26
27
  rescue Psych::SyntaxError => e
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ettin
4
- VERSION = "1.2.1"
4
+ VERSION = "1.3.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ettin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Hockey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-23 00:00:00.000000000 Z
11
+ date: 2019-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deep_merge
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: coveralls
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -81,7 +95,21 @@ dependencies:
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
- name: simplecov
98
+ name: rubocop-performance
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rspec
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
115
  - - ">="
@@ -119,6 +147,7 @@ files:
119
147
  - lib/ettin/config_files.rb
120
148
  - lib/ettin/deep_transform.rb
121
149
  - lib/ettin/hash_factory.rb
150
+ - lib/ettin/method_name.rb
122
151
  - lib/ettin/options.rb
123
152
  - lib/ettin/source.rb
124
153
  - lib/ettin/sources/hash_source.rb
@@ -144,7 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
173
  - !ruby/object:Gem::Version
145
174
  version: '0'
146
175
  requirements: []
147
- rubygems_version: 3.0.2
176
+ rubyforge_project:
177
+ rubygems_version: 2.7.6
148
178
  signing_key:
149
179
  specification_version: 4
150
180
  summary: The best way to add settings in any ruby project.