asetus 0.3.0 → 0.4.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
- SHA1:
3
- metadata.gz: 8e7928dfc17c80661fdd04fa77a9834a15576489
4
- data.tar.gz: 0db9acdb4df502a99316e2fbe6328dbb72f83690
2
+ SHA256:
3
+ metadata.gz: c534c1419ce9dc4ca9f70bd8cee2cf95dbd7ffaf08a91592b3fd577fa5e3f6d3
4
+ data.tar.gz: c6b31d2019b287a1b752dbc5174d82193e63cd4e20f266a3b6b71a78dbbe9771
5
5
  SHA512:
6
- metadata.gz: be5a0b16846d9620ac652cfa3cda3761ca9d5d8b5cadbc5fb42922d6d17278f98d8fd609d00e7ce4abfe17ea5c38ad4a098c6691c151618dbafb44898eb1a721
7
- data.tar.gz: e5ee6a222d6c8ca4c1ff317de0018adddd1efda6a38492e0581b45bb76f40f9f835314b9eb8c9a92ad42cc257cfc35afa7961f8a9df995d91658ce4f333c2eb4
6
+ metadata.gz: 21dcef691c3ba393e6550748ca272fd495b826c0638173f342064130076fd7e1366d014cf5e98807a1b671ee44ee4a50a8676feb5e141f67710414aacb715dab
7
+ data.tar.gz: 6c7e6f90529654c1e2e768b2d887dd428f51e0000c521f3ebc6b7e135bffc9ff28343d05022ca2bb85e30d5130057398f7a4d85a61d85bf1c41d78c8b340ed7f
@@ -0,0 +1,23 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "github-actions"
9
+ target-branch: "master"
10
+ directory: "/"
11
+ schedule:
12
+ interval: "daily"
13
+ open-pull-requests-limit: 10
14
+ labels:
15
+ - dependencies
16
+ - package-ecosystem: "bundler"
17
+ target-branch: "master"
18
+ directory: "/"
19
+ schedule:
20
+ interval: "daily"
21
+ open-pull-requests-limit: 10
22
+ labels:
23
+ - dependencies
@@ -0,0 +1,42 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: CI
9
+
10
+ on: [ push, pull_request ]
11
+ # push:
12
+ # branches: [ master ]
13
+ # pull_request:
14
+ # branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ ruby-version: ['2.7', '3.0', '3.1', '3.2']
23
+
24
+ steps:
25
+ - uses: actions/checkout@v3
26
+ - name: Set up Ruby
27
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
+ uses: ruby/setup-ruby@v1
30
+ with:
31
+ ruby-version: ${{ matrix.ruby-version }}
32
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
33
+ - name: rubocop
34
+ uses: reviewdog/action-rubocop@v2
35
+ with:
36
+ rubocop_version: gemfile
37
+ rubocop_extensions: rubocop-minitest:gemfile rubocop-rake:gemfile
38
+ reporter: github-pr-review
39
+ - name: Run tests
40
+ run: bundle exec rake
41
+ - uses: codecov/codecov-action@v3
42
+ if: ${{ always() }}
@@ -0,0 +1,16 @@
1
+ name: "Stale Issue/PR cleanup"
2
+ on:
3
+ schedule:
4
+ - cron: "30 1 * * *"
5
+
6
+ permissions:
7
+ issues: write
8
+ pull-requests: write
9
+
10
+ jobs:
11
+ stale:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/stale@v8
15
+ with:
16
+ operations-per-run: 500
data/.gitignore CHANGED
@@ -1,2 +1,2 @@
1
1
  Gemfile.lock
2
- gems
2
+ pkg
data/.rubocop.yml ADDED
@@ -0,0 +1,93 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ # Do not attempt to police vendored code
4
+ AllCops:
5
+ NewCops: enable
6
+ TargetRubyVersion: 2.7
7
+ Exclude:
8
+ - 'vendor/**/*'
9
+
10
+ Style/StringLiterals:
11
+ Enabled: false
12
+
13
+ Style/FrozenStringLiteralComment:
14
+ Enabled: false
15
+
16
+ Layout/LineLength:
17
+ Enabled: false
18
+
19
+ Lint/AmbiguousRegexpLiteral:
20
+ Enabled: false
21
+
22
+ Lint/RaiseException:
23
+ Enabled: true
24
+
25
+ Lint/StructNewOverride:
26
+ Enabled: true
27
+
28
+ # Stick to verbose until https://bugs.ruby-lang.org/issues/10177 is closed.
29
+ Style/PreferredHashMethods:
30
+ EnforcedStyle: verbose
31
+
32
+ Layout/HashAlignment:
33
+ EnforcedHashRocketStyle: table
34
+ EnforcedColonStyle: table
35
+
36
+ Style/Not:
37
+ Enabled: false
38
+
39
+ # comply with @ytti's exacting specifications
40
+ Style/CommandLiteral:
41
+ EnforcedStyle: percent_x
42
+
43
+ Style/FormatString:
44
+ EnforcedStyle: percent
45
+
46
+ Style/FormatStringToken:
47
+ EnforcedStyle: unannotated
48
+
49
+ Style/HashEachMethods:
50
+ Enabled: true
51
+
52
+ Style/HashTransformKeys:
53
+ Enabled: true
54
+
55
+ Style/HashTransformValues:
56
+ Enabled: true
57
+
58
+ Style/RescueModifier:
59
+ Enabled: false
60
+
61
+ Style/SymbolProc:
62
+ Enabled: false
63
+
64
+ Style/Documentation:
65
+ Enabled: false
66
+
67
+ Style/ParallelAssignment:
68
+ Enabled: false
69
+
70
+ Metrics/MethodLength:
71
+ Max: 45
72
+
73
+ ## Metrics/AbcSize:
74
+ ## Max: 28
75
+
76
+ Metrics/ClassLength:
77
+ Max: 200
78
+
79
+ ## Metrics/CyclomaticComplexity:
80
+ ## Max: 7
81
+
82
+ Metrics/BlockLength:
83
+ Max: 150
84
+
85
+ Metrics/ParameterLists:
86
+ Max: 6
87
+
88
+ Lint/EmptyBlock:
89
+ Enabled: false
90
+
91
+ require:
92
+ - rubocop-rake
93
+ - rubocop-minitest
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,71 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2023-04-24 11:45:31 UTC using RuboCop version 1.48.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
11
+ Metrics/AbcSize:
12
+ Max: 25
13
+
14
+ # Offense count: 1
15
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
16
+ Metrics/CyclomaticComplexity:
17
+ Max: 9
18
+
19
+ # Offense count: 1
20
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
21
+ Metrics/PerceivedComplexity:
22
+ Max: 9
23
+
24
+ # Offense count: 1
25
+ # Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
26
+ # NamePrefix: is_, has_, have_
27
+ # ForbiddenPrefixes: is_, has_, have_
28
+ # AllowedMethods: is_a?
29
+ # MethodDefinitionMacros: define_method, define_singleton_method
30
+ Naming/PredicateName:
31
+ Exclude:
32
+ - 'spec/**/*'
33
+ - 'lib/asetus/configstruct.rb'
34
+
35
+ # Offense count: 1
36
+ Security/Eval:
37
+ Exclude:
38
+ - 'Rakefile'
39
+
40
+ # Offense count: 1
41
+ # This cop supports unsafe autocorrection (--autocorrect-all).
42
+ Security/JSONLoad:
43
+ Exclude:
44
+ - 'lib/asetus/adapter/json.rb'
45
+
46
+ # Offense count: 1
47
+ Style/MissingRespondToMissing:
48
+ Exclude:
49
+ - 'lib/asetus/configstruct.rb'
50
+
51
+ # Offense count: 1
52
+ # This cop supports unsafe autocorrection (--autocorrect-all).
53
+ # Configuration parameters: EnforcedStyle.
54
+ # SupportedStyles: literals, strict
55
+ Style/MutableConstant:
56
+ Exclude:
57
+ - 'lib/asetus.rb'
58
+
59
+ # Offense count: 2
60
+ # This cop supports unsafe autocorrection (--autocorrect-all).
61
+ Style/SlicingWithRange:
62
+ Exclude:
63
+ - 'lib/asetus/configstruct.rb'
64
+
65
+ # Offense count: 5
66
+ # This cop supports unsafe autocorrection (--autocorrect-all).
67
+ # Configuration parameters: Mode.
68
+ Style/StringConcatenation:
69
+ Exclude:
70
+ - 'Rakefile'
71
+ - 'lib/asetus.rb'
data/README.md CHANGED
@@ -31,7 +31,7 @@ asetus = Asetus.new name: 'mykewlapp',
31
31
  sysdir: '/System/config/',
32
32
  load: false
33
33
  asetus.default.poop2 = [1, 2, 3, 4]
34
- asetus.default.starship.poopoers = 42
34
+ asetus.default.starship.poopers = 42
35
35
  asetus.load :user
36
36
  if asetus.user.empty?
37
37
  asetus.user = asetus.default
@@ -59,7 +59,7 @@ asetus.user # user only
59
59
 
60
60
  ## License and Copyright
61
61
 
62
- Copyright 2014-2015 Saku Ytti <saku@ytti.fi>
62
+ Copyright 2014-2016 Saku Ytti <saku@ytti.fi>
63
63
 
64
64
  Licensed under the Apache License, Version 2.0 (the "License");
65
65
  you may not use this file except in compliance with the License.
data/Rakefile CHANGED
@@ -1,14 +1,9 @@
1
- begin
2
- require 'rake/testtask'
3
- require 'bundler'
4
- #Bundler.setup
5
- rescue LoadError
6
- warn 'bunler missing'
7
- exit 42
8
- end
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'bundler'
9
4
 
10
5
  gemspec = eval(File.read(Dir['*.gemspec'].first))
11
- file = [gemspec.name, gemspec.version].join('-') + '.gem'
6
+ gemfile = [gemspec.name, gemspec.version].join('-') + '.gem'
12
7
 
13
8
  desc 'Validate gemspec'
14
9
  task :gemspec do
@@ -18,30 +13,29 @@ end
18
13
  desc 'Run minitest'
19
14
  task :test do
20
15
  Rake::TestTask.new do |t|
21
- t.libs.push "lib"
22
- t.test_files = FileList['spec/*_spec.rb']
16
+ t.libs << 'spec'
17
+ t.test_files = FileList['spec/**/*_spec.rb']
18
+ t.warning = true
23
19
  t.verbose = true
24
20
  end
25
21
  end
26
22
 
27
23
  desc 'Build gem'
28
- task :build do
29
- system "gem build #{gemspec.name}.gemspec"
30
- FileUtils.mkdir_p 'gems'
31
- FileUtils.mv file, 'gems'
32
- end
24
+ task :build
33
25
 
34
26
  desc 'Install gem'
35
- task :install => :build do
36
- system "sudo -E sh -c \'umask 022; gem install gems/#{file}\'"
27
+ task install: :build do
28
+ system "sudo -E sh -c 'umask 022; gem install gems/#{gemfile}'"
37
29
  end
38
30
 
39
31
  desc 'Remove gems'
40
32
  task :clean do
41
- FileUtils.rm_rf 'gems'
33
+ FileUtils.rm_rf 'pkg'
42
34
  end
43
35
 
44
36
  desc 'Push to rubygems'
45
37
  task :push do
46
- system "gem push gems/#{file}"
38
+ system "gem push pkg/#{gemfile}"
47
39
  end
40
+
41
+ task default: :test
data/asetus.gemspec CHANGED
@@ -1,15 +1,27 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'asetus'
3
- s.version = '0.3.0'
3
+ s.version = '0.4.0'
4
4
  s.licenses = ['Apache-2.0']
5
5
  s.platform = Gem::Platform::RUBY
6
- s.authors = [ 'Saku Ytti' ]
7
- s.email = %w( saku@ytti.fi )
6
+ s.authors = ['Saku Ytti']
7
+ s.email = %w[saku@ytti.fi]
8
8
  s.homepage = 'http://github.com/ytti/asetus'
9
9
  s.summary = 'configuration library'
10
10
  s.description = 'configuration library with object access to YAML/JSON/TOML backends'
11
- s.rubyforge_project = s.name
12
- s.files = `git ls-files`.split("\n")
13
- s.executables = %w( )
11
+ s.files = %x(git ls-files -z).split("\x0")
12
+ s.executables = %w[]
14
13
  s.require_path = 'lib'
14
+
15
+ s.metadata['rubygems_mfa_required'] = 'true'
16
+
17
+ s.required_ruby_version = '>= 2.7'
18
+
19
+ s.add_development_dependency 'bundler', '~> 2.2'
20
+ s.add_development_dependency 'rake', '~> 13.0'
21
+ s.add_development_dependency 'rubocop', '~> 1.48.0'
22
+ s.add_development_dependency 'rubocop-minitest', '~> 0.29.0'
23
+ s.add_development_dependency 'rubocop-rake', '~> 0.6.0'
24
+ s.add_development_dependency 'simplecov', '~> 0.22.0'
25
+ s.add_development_dependency 'simplecov-cobertura', '~> 2.1.0'
26
+ s.add_development_dependency 'simplecov-html', '~> 0.12.3'
15
27
  end
@@ -1,27 +1,25 @@
1
1
  class Asetus
2
-
3
- def to_json config
2
+ def to_json(config)
4
3
  Adapter::JSON.to config._asetus_to_hash
5
4
  end
6
5
 
7
- def from_json json
6
+ def from_json(json)
8
7
  Adapter::JSON.from json
9
8
  end
10
9
 
11
10
  class Adapter
12
11
  class JSON
13
12
  class << self
14
- def to hash
13
+ def to(hash)
15
14
  require 'json'
16
15
  ::JSON.pretty_generate hash
17
16
  end
18
17
 
19
- def from json
18
+ def from(json)
20
19
  require 'json'
21
20
  ::JSON.load json
22
21
  end
23
22
  end
24
23
  end
25
24
  end
26
-
27
25
  end
@@ -1,27 +1,25 @@
1
1
  class Asetus
2
-
3
- def to_toml config
2
+ def to_toml(config)
4
3
  Adapter::TOML.to config._asetus_to_hash
5
4
  end
6
5
 
7
- def from_toml toml
6
+ def from_toml(toml)
8
7
  Adapter::TOML.from toml
9
8
  end
10
9
 
11
10
  class Adapter
12
11
  class TOML
13
12
  class << self
14
- def to hash
13
+ def to(hash)
15
14
  require 'toml'
16
15
  ::TOML::Generator.new(hash).body
17
16
  end
18
17
 
19
- def from toml
18
+ def from(toml)
20
19
  require 'toml'
21
20
  ::TOML.load toml
22
21
  end
23
22
  end
24
23
  end
25
24
  end
26
-
27
25
  end
@@ -1,27 +1,25 @@
1
1
  class Asetus
2
-
3
- def to_yaml config
2
+ def to_yaml(config)
4
3
  Adapter::YAML.to config._asetus_to_hash
5
4
  end
6
5
 
7
- def from_yaml yaml
6
+ def from_yaml(yaml)
8
7
  Adapter::YAML.from yaml
9
8
  end
10
9
 
11
10
  class Adapter
12
11
  class YAML
13
12
  class << self
14
- def to hash
13
+ def to(hash)
15
14
  require 'yaml'
16
15
  ::YAML.dump hash
17
16
  end
18
17
 
19
- def from yaml
18
+ def from(yaml)
20
19
  require 'yaml'
21
- ::YAML.load yaml
20
+ ::YAML.unsafe_load yaml
22
21
  end
23
22
  end
24
23
  end
25
24
  end
26
-
27
25
  end
@@ -1,12 +1,9 @@
1
1
  class Asetus
2
2
  class ConfigStruct
3
-
4
3
  def _asetus_to_hash
5
4
  hash = {}
6
5
  @cfg.each do |key, value|
7
- if value.class == ConfigStruct
8
- value = value._asetus_to_hash
9
- end
6
+ value = value._asetus_to_hash if value.instance_of?(ConfigStruct)
10
7
  key = key.to_s if @key_to_s
11
8
  hash[key] = value
12
9
  end
@@ -17,7 +14,7 @@ class Asetus
17
14
  @cfg.empty?
18
15
  end
19
16
 
20
- def each &block
17
+ def each(&block)
21
18
  @cfg.each(&block)
22
19
  end
23
20
 
@@ -25,27 +22,23 @@ class Asetus
25
22
  @cfg.keys
26
23
  end
27
24
 
28
- def has_key? key
25
+ def has_key?(key)
29
26
  @cfg.has_key? key
30
27
  end
31
28
 
32
29
  private
33
30
 
34
- def initialize hash=nil, opts={}
31
+ def initialize(hash = nil, opts = {})
35
32
  @key_to_s = opts.delete :key_to_s
36
33
  @cfg = hash ? _asetus_from_hash(hash) : {}
37
34
  end
38
35
 
39
- def method_missing name, *args, &block
36
+ def method_missing name, *args
40
37
  name = name.to_s
41
38
  name = args.shift if name[0..1] == '[]' # asetus.cfg['foo']
42
39
  arg = args.first
43
40
  if name[-1..-1] == '?' # asetus.cfg.foo.bar?
44
- if @cfg.has_key? name[0..-2]
45
- @cfg[name[0..-2]]
46
- else
47
- nil
48
- end
41
+ @cfg[name[0..-2]] if @cfg.has_key? name[0..-2]
49
42
  elsif name[-1..-1] == '=' # asetus.cfg.foo.bar = 'quux'
50
43
  _asetus_set name[0..-2], arg
51
44
  else
@@ -53,11 +46,11 @@ class Asetus
53
46
  end
54
47
  end
55
48
 
56
- def _asetus_set key, value
49
+ def _asetus_set(key, value)
57
50
  @cfg[key] = value
58
51
  end
59
52
 
60
- def _asetus_get key, value
53
+ def _asetus_get(key, _value)
61
54
  if @cfg.has_key? key
62
55
  @cfg[key]
63
56
  else
@@ -65,16 +58,13 @@ class Asetus
65
58
  end
66
59
  end
67
60
 
68
- def _asetus_from_hash hash
61
+ def _asetus_from_hash(hash)
69
62
  cfg = {}
70
63
  hash.each do |key, value|
71
- if value.class == Hash
72
- value = ConfigStruct.new value, :key_to_s=>@key_to_s
73
- end
64
+ value = ConfigStruct.new value, key_to_s: @key_to_s if value.instance_of?(Hash)
74
65
  cfg[key] = value
75
66
  end
76
67
  cfg
77
68
  end
78
-
79
69
  end
80
70
  end
data/lib/asetus.rb CHANGED
@@ -34,28 +34,26 @@ class Asetus
34
34
  end
35
35
 
36
36
  # When this is called, by default :system and :user are loaded from
37
- # filesystem and merged with defefault, so that user overrides system which
37
+ # filesystem and merged with default, so that user overrides system which
38
38
  # overrides default
39
39
  #
40
- # @param [Symbol] level which configuration level to load, by defaukt :all
40
+ # @param [Symbol] level which configuration level to load, by default :all
41
41
  # @return [void]
42
- def load level=:all
43
- if level == :default or level == :all
44
- @cfg = merge @cfg, @default
45
- end
46
- if level == :system or level == :all
42
+ def load(level = :all)
43
+ @cfg = merge @cfg, @default if %i[default all].include?(level)
44
+ if %i[system all].include?(level)
47
45
  @system = load_cfg @sysdir
48
46
  @cfg = merge @cfg, @system
49
47
  end
50
- if level == :user or level == :all
51
- @user = load_cfg @usrdir
52
- @cfg = merge @cfg, @user
53
- end
48
+ return unless %i[user all].include?(level)
49
+
50
+ @user = load_cfg @usrdir
51
+ @cfg = merge @cfg, @user
54
52
  end
55
53
 
56
54
  # @param [Symbol] level which configuration level to save, by default :user
57
55
  # @return [void]
58
- def save level=:user
56
+ def save(level = :user)
59
57
  if level == :user
60
58
  save_cfg @usrdir, @user
61
59
  elsif level == :system
@@ -66,20 +64,20 @@ class Asetus
66
64
  # @example create user config from default config and raise error, if no config was found
67
65
  # raise StandardError, 'edit ~/.config/name/config' if asetus.create
68
66
  # @param [Hash] opts options for Asetus
69
- # @option opts [Symbol] :source source to use for settings to save, by defaylt :default
70
- # @option opts [Symbol] :destination destinatino to use for settings to save, by default :user
67
+ # @option opts [Symbol] :source source to use for settings to save, by default :default
68
+ # @option opts [Symbol] :destination destination to use for settings to save, by default :user
71
69
  # @option opts [boolean] :load load config once saved, by default false
72
70
  # @return [boolean] true if config didn't exist and was created, false if config already exists
73
- def create opts={}
71
+ def create(opts = {})
74
72
  src = opts.delete :source
75
73
  src ||= :default
76
74
  dst = opts.delete :destination
77
75
  dst ||= :user
78
76
  no_config = false
79
- no_config = true if @system.empty? and @user.empty?
77
+ no_config = true if @system.empty? && @user.empty?
80
78
  if no_config
81
79
  src = instance_variable_get '@' + src.to_s
82
- instance_variable_set('@'+dst.to_s, src.dup)
80
+ instance_variable_set('@' + dst.to_s, src.dup)
83
81
  save dst
84
82
  load if opts.delete :load
85
83
  end
@@ -93,11 +91,11 @@ class Asetus
93
91
  # @option opts [String] :adapter adapter to use 'yaml', 'json' or 'toml' for now
94
92
  # @option opts [String] :usrdir directory for storing user config ~/.config/name/ by default
95
93
  # @option opts [String] :sysdir directory for storing system config /etc/name/ by default
96
- # @option opts [String] :cfgfile configuration filename by default CONFIG_FILE
94
+ # @option opts [String] :cfgfile configuration filename, by default CONFIG_FILE
97
95
  # @option opts [Hash] :default default settings to use
98
96
  # @option opts [boolean] :load automatically load+merge system+user config with defaults in #cfg
99
97
  # @option opts [boolean] :key_to_s convert keys to string by calling #to_s for keys
100
- def initialize opts={}
98
+ def initialize(opts = {})
101
99
  @name = (opts.delete(:name) or metaname)
102
100
  @adapter = (opts.delete(:adapter) or 'yaml')
103
101
  @usrdir = (opts.delete(:usrdir) or File.join(Dir.home, '.config', @name))
@@ -111,18 +109,19 @@ class Asetus
111
109
  @load = opts.delete(:load) if opts.has_key?(:load)
112
110
  @key_to_s = opts.delete(:key_to_s)
113
111
  raise UnknownOption, "option '#{opts}' not recognized" unless opts.empty?
112
+
114
113
  load :all if @load
115
114
  end
116
115
 
117
- def load_cfg dir
116
+ def load_cfg(dir)
118
117
  @file = File.join dir, @cfgfile
119
118
  file = File.read @file
120
- ConfigStruct.new(from(@adapter, file), :key_to_s=>@key_to_s)
119
+ ConfigStruct.new(from(@adapter, file), key_to_s: @key_to_s)
121
120
  rescue Errno::ENOENT
122
121
  ConfigStruct.new
123
122
  end
124
123
 
125
- def save_cfg dir, config
124
+ def save_cfg(dir, config)
126
125
  config = to(@adapter, config)
127
126
  file = File.join dir, @cfgfile
128
127
  FileUtils.mkdir_p dir
@@ -137,12 +136,12 @@ class Asetus
137
136
  ConfigStruct.new hash
138
137
  end
139
138
 
140
- def from adapter, string
139
+ def from(adapter, string)
141
140
  name = 'from_' + adapter
142
141
  send name, string
143
142
  end
144
143
 
145
- def to adapter, config
144
+ def to(adapter, config)
146
145
  name = 'to_' + adapter
147
146
  send name, config
148
147
  end
@@ -150,15 +149,15 @@ class Asetus
150
149
  def metaname
151
150
  path = caller_locations[-1].path
152
151
  File.basename path, File.extname(path)
153
- rescue
152
+ rescue StandardError
154
153
  raise NoName, "can't figure out name, specify explicitly"
155
154
  end
156
155
  end
157
156
 
158
157
  class Hash
159
- def _asetus_deep_merge newhash
160
- merger = proc do |key, oldval, newval|
161
- Hash === oldval && Hash === newval ? oldval.merge(newval, &merger) : newval
158
+ def _asetus_deep_merge(newhash)
159
+ merger = proc do |_key, oldval, newval|
160
+ oldval.is_a?(Hash) && newval.is_a?(Hash) ? oldval.merge(newval, &merger) : newval
162
161
  end
163
162
  merge newhash, &merger
164
163
  end
metadata CHANGED
@@ -1,15 +1,127 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asetus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saku Ytti
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-08 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2023-04-24 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: '2.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.48.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.48.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.29.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.29.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.6.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.6.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.22.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.22.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov-cobertura
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 2.1.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 2.1.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov-html
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.12.3
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.12.3
13
125
  description: configuration library with object access to YAML/JSON/TOML backends
14
126
  email:
15
127
  - saku@ytti.fi
@@ -17,7 +129,12 @@ executables: []
17
129
  extensions: []
18
130
  extra_rdoc_files: []
19
131
  files:
132
+ - ".github/dependabot.yml"
133
+ - ".github/workflows/ruby.yml"
134
+ - ".github/workflows/stale.yml"
20
135
  - ".gitignore"
136
+ - ".rubocop.yml"
137
+ - ".rubocop_todo.yml"
21
138
  - Gemfile
22
139
  - README.md
23
140
  - Rakefile
@@ -30,8 +147,9 @@ files:
30
147
  homepage: http://github.com/ytti/asetus
31
148
  licenses:
32
149
  - Apache-2.0
33
- metadata: {}
34
- post_install_message:
150
+ metadata:
151
+ rubygems_mfa_required: 'true'
152
+ post_install_message:
35
153
  rdoc_options: []
36
154
  require_paths:
37
155
  - lib
@@ -39,16 +157,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
39
157
  requirements:
40
158
  - - ">="
41
159
  - !ruby/object:Gem::Version
42
- version: '0'
160
+ version: '2.7'
43
161
  required_rubygems_version: !ruby/object:Gem::Requirement
44
162
  requirements:
45
163
  - - ">="
46
164
  - !ruby/object:Gem::Version
47
165
  version: '0'
48
166
  requirements: []
49
- rubyforge_project: asetus
50
- rubygems_version: 2.2.2
51
- signing_key:
167
+ rubygems_version: 3.4.10
168
+ signing_key:
52
169
  specification_version: 4
53
170
  summary: configuration library
54
171
  test_files: []