figleaf 0.2.9 → 0.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
- SHA1:
3
- metadata.gz: ec9ac4b9f179b8da23d4fe6fd4f89573ad041f40
4
- data.tar.gz: 6d35c13f543461265cc76ca339335f392fcdf03f
2
+ SHA256:
3
+ metadata.gz: d9587314be7114b5e08704a3f1e2364f41cf90f926c890554b8dd31582dbd7c2
4
+ data.tar.gz: 7f1731a8135590e9992ff1a2e40382fd36f11f9bb3739d6006546a40069ee948
5
5
  SHA512:
6
- metadata.gz: 80c139d2c4a5b3cb77999e9101940248ecb2b82ec9dc83420d89f7fc7462fe7875de2c61c9b7ba868be611500a5fa6b27dc53e707c3d730784741f740a551e4f
7
- data.tar.gz: 4bb3aefcc80e712dcb231a413f3b3e867004248ca4a36491d8c56e2f9b29889a98a7dc8d6fb304043d914ab7919a486c87478b9b02ed783d8dfc932bfb4f6d6c
6
+ metadata.gz: '03471397a014e702344505aee3ebe6289b110278d662ed121fcc634c8a63a20f9207e90b1ca08ec7d6d693246f61b1dede83cec44af33694dae4621b4e892b56'
7
+ data.tar.gz: 76a9bdcec7177c4485273a93748c454b886f3adb22b12e4dfe485ea7359d9f7d418a15509f7ce7747b0b5225ff0fc896598f877c29354ea67d8090a4a03ee238
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.3.0 (2024/04/05)
4
+ - Use YAML.safe_load to support versions of Psych >4
5
+ - Target modern rubies
6
+ - Take advantage of Ruby 3's single line methods
7
+ - Use standardrb to auto format all files
8
+
3
9
  ## 0.2.7, 0.2.8 and 0.2.9 (2017/09/28)
4
10
  Bugfixes
5
11
 
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
@@ -13,13 +13,15 @@ group :development do
13
13
  gem "rb-fsevent", require: false
14
14
  gem "rb-inotify", require: false
15
15
 
16
- gem 'guard-bundler', :require => false
17
- gem 'guard-livereload', :require => false
18
- gem 'guard-rspec', :require => false
19
- gem 'libnotify', :require => false # linux notifications
20
- gem 'ruby_gntp', :require => false # os x notifications
21
- gem "terminal-notifier-guard", :require => false
16
+ gem "guard-bundler", require: false
17
+ gem "guard-livereload", require: false
18
+ gem "guard-rspec", require: false
19
+ gem "libnotify", require: false # linux notifications
20
+ gem "ruby_gntp", require: false # os x notifications
21
+ gem "terminal-notifier-guard", require: false
22
22
 
23
- gem "pry"
24
- gem "pry-debugger", platforms: :ruby_19
23
+ gem "pry", require: false
24
+ gem "pry-byebug", require: false
25
+
26
+ gem "standard", require: false
25
27
  end
data/Guardfile CHANGED
@@ -1,19 +1,19 @@
1
1
  platform = RUBY_PLATFORM.match(/(linux|darwin)/)[0].to_sym
2
2
  notification case platform
3
- when :darwin
4
- :gntp
5
- when :linux
6
- require 'libnotify'
7
- :libnotify
8
- end
3
+ when :darwin
4
+ :gntp
5
+ when :linux
6
+ require "libnotify"
7
+ :libnotify
8
+ end
9
9
 
10
10
  guard :bundler do
11
- require 'guard/bundler'
12
- require 'guard/bundler/verify'
11
+ require "guard/bundler"
12
+ require "guard/bundler/verify"
13
13
  helper = Guard::Bundler::Verify.new
14
14
 
15
- files = ['Gemfile']
16
- files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }
15
+ files = ["Gemfile"]
16
+ files += Dir["*.gemspec"] if files.any? { |f| helper.uses_gemspec?(f) }
17
17
 
18
18
  # Assume files are symlinked from somewhere
19
19
  files.each { |file| watch(helper.real_path(file)) }
data/Rakefile CHANGED
@@ -18,4 +18,4 @@ task :clean do
18
18
  end
19
19
 
20
20
  desc "Run rspec by default"
21
- task :default => :spec
21
+ task default: :spec
data/figleaf.gemspec CHANGED
@@ -1,19 +1,17 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/figleaf/version', __FILE__)
1
+ require File.expand_path("../lib/figleaf/version", __FILE__)
3
2
 
4
3
  Gem::Specification.new do |gem|
5
- gem.authors = ["Juan C. Müller"]
6
- gem.email = ["jcmuller@gmail.com"]
7
- gem.description = %q{YAML based DRY settings manager.}
8
- gem.summary = %q{YAML based DRY settings manager.}
9
- gem.homepage = "http://github.com/jcmuller/figleaf"
4
+ gem.authors = ["Juan C. Müller"]
5
+ gem.email = ["jcmuller@gmail.com"]
6
+ gem.description = "YAML based DRY settings manager."
7
+ gem.summary = "YAML based DRY settings manager."
8
+ gem.homepage = "http://github.com/jcmuller/figleaf"
10
9
 
11
- gem.files = `git ls-files`.split($\)
12
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
- gem.name = "figleaf"
10
+ gem.files = `git ls-files`.split($\)
11
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
12
+ gem.name = "figleaf"
15
13
  gem.require_paths = ["lib"]
16
- gem.version = Figleaf::VERSION
14
+ gem.version = Figleaf::VERSION
17
15
 
18
16
  gem.add_dependency "activesupport", ">= 3"
19
17
  gem.add_dependency "hashie", ">= 2"
@@ -1,47 +1,37 @@
1
1
  module Figleaf
2
2
  # Convert a ruby block to nested hash
3
3
  class Config
4
- def initialize
5
- @property = LazyBlockHash.new
6
- end
4
+ def initialize = @property = LazyBlockHash.new
7
5
 
8
- def call(&block)
9
- instance_eval(&block)
6
+ def call(&)
7
+ instance_eval(&)
10
8
 
11
9
  property
12
- rescue Exception => e
10
+ rescue => e
13
11
  raise Settings::InvalidRb, "Configuration has invalid Ruby\n" + e.message
14
12
  end
15
13
 
16
- def method_missing(method_name, *args, &block)
17
- process_method(method_name, *args, &block)
18
- end
14
+ def method_missing(method_name, *, &) = process_method(method_name, *, &)
19
15
 
20
- def test(&block)
21
- process_method(:test, [], &block)
22
- end
16
+ def test(&) = process_method(:test, [], &)
23
17
 
24
18
  def process_method(method_name, *args, &block)
25
19
  @property[method_name.to_s] =
26
- if block_given?
20
+ if block
27
21
  obj = self.class.new
28
- Proc.new { obj.call(&block) }
22
+ proc { obj.call(&block) }
23
+ elsif args.count == 1
24
+ args[0]
29
25
  else
30
- if args.count == 1
31
- args[0]
32
- else
33
- args
34
- end
26
+ args
35
27
  end
36
28
  end
37
29
 
38
- def respond_to_missing?(method_name, *args)
39
- true
40
- end
30
+ def respond_to_missing?(method_name, *args) = true
41
31
 
42
32
  private
43
33
 
44
- attr_reader :property
34
+ attr_reader :property
45
35
  end
46
36
 
47
37
  class LazyBlockHash < Hash
@@ -10,7 +10,7 @@ module Figleaf
10
10
  # Public - configure pre-defined attributes
11
11
  #
12
12
  def configure
13
- self.auto_define.tap do |cached_auto_define|
13
+ auto_define.tap do |cached_auto_define|
14
14
  self.auto_define = false
15
15
  yield self
16
16
  self.auto_define = cached_auto_define
@@ -20,13 +20,13 @@ module Figleaf
20
20
  # Public - configure auto defined settings attributes
21
21
  # and load yaml settings from confing/settings directory
22
22
  #
23
- def configure!(&block)
23
+ def configure!(&)
24
24
  load_settings
25
- configure_with_auto_define(&block)
25
+ configure_with_auto_define(&)
26
26
  end
27
27
 
28
28
  def configure_with_auto_define
29
- self.auto_define.tap do |cached_auto_define|
29
+ auto_define.tap do |cached_auto_define|
30
30
  self.auto_define = true
31
31
  yield self
32
32
  self.auto_define = cached_auto_define
@@ -46,23 +46,23 @@ module Figleaf
46
46
 
47
47
  next if property.nil?
48
48
 
49
- if self.respond_to?(property_name) &&
50
- self.send(property_name).respond_to?(:merge) &&
49
+ if respond_to?(property_name) &&
50
+ send(property_name).respond_to?(:merge) &&
51
51
  property.respond_to?(:merge)
52
- property = self.send(property_name).merge(property)
52
+ property = send(property_name).merge(property)
53
53
  end
54
54
 
55
- self.send("#{property_name}=", property)
55
+ send(:"#{property_name}=", property)
56
56
  end
57
57
  end
58
58
  end
59
59
 
60
60
  def load_file(file, env_to_load = env)
61
- if file.end_with?('.rb')
62
- property_name = File.basename(file, '.rb')
61
+ if file.end_with?(".rb")
62
+ property_name = File.basename(file, ".rb")
63
63
  config = load_rb_file(file) or return nil
64
64
  else
65
- property_name = File.basename(file, '.yml')
65
+ property_name = File.basename(file, ".yml")
66
66
  config = load_yaml_file(file) or return nil
67
67
  end
68
68
 
@@ -84,23 +84,23 @@ module Figleaf
84
84
  end
85
85
 
86
86
  def load_yaml_file(file_path)
87
- YAML.load(ERB.new(IO.read(file_path)).result)
87
+ YAML.safe_load(ERB.new(IO.read(file_path)).result, aliases: true)
88
88
  rescue Psych::SyntaxError => e
89
89
  raise InvalidYAML, "#{file_path} has invalid YAML\n" + e.message
90
90
  end
91
91
 
92
92
  def root
93
93
  return Rails.root if defined?(Rails)
94
- Pathname.new('.')
94
+ Pathname.new(".")
95
95
  end
96
96
 
97
97
  def default_file_pattern
98
- [root.join('config/settings/*.yml'), root.join('config/settings/*.rb')]
98
+ [root.join("config/settings/*.yml"), root.join("config/settings/*.rb")]
99
99
  end
100
100
 
101
101
  def env
102
102
  return Rails.env if defined?(Rails)
103
- ENV['ENVIRONMENT']
103
+ ENV["ENVIRONMENT"]
104
104
  end
105
105
 
106
106
  def use_hashie_if_hash(property)
@@ -109,20 +109,20 @@ module Figleaf
109
109
  end
110
110
 
111
111
  def override_with_local!(local_file)
112
- #this file (i.e. test.local.rb) is an optional place to put settings
112
+ # this file (i.e. test.local.rb) is an optional place to put settings
113
113
  local_file.tap do |local_settings_path|
114
- eval(IO.read(local_settings_path), binding) if File.exists?(local_settings_path)
114
+ eval(IO.read(local_settings_path), binding) if File.exist?(local_settings_path)
115
115
  end
116
116
  end
117
117
 
118
118
  def method_missing(method_name, *args)
119
119
  getter_name, modifier = extract_getter_name_and_modifier(method_name)
120
120
 
121
- if self.auto_define && modifier == '=' && args.length == 1
122
- self.define_cattr_methods(getter_name)
123
- self.send(method_name, args.shift)
124
- elsif modifier == '?' && args.empty?
125
- self.send(getter_name).present?
121
+ if auto_define && modifier == "=" && args.length == 1
122
+ define_cattr_methods(getter_name)
123
+ send(method_name, args.shift)
124
+ elsif modifier == "?" && args.empty?
125
+ send(getter_name).present?
126
126
  else
127
127
  super
128
128
  end
@@ -136,11 +136,10 @@ module Figleaf
136
136
  def define_cattr_methods(getter_name)
137
137
  cattr_writer getter_name
138
138
  define_singleton_method(getter_name) do
139
- result = class_variable_get "@@#{getter_name}"
139
+ result = class_variable_get :"@@#{getter_name}"
140
140
  result.respond_to?(:call) ? result.call : result
141
141
  end
142
142
  end
143
-
144
143
  end
145
144
  end
146
145
  end
@@ -1,3 +1,3 @@
1
1
  module Figleaf
2
- VERSION = '0.2.9'
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/figleaf.rb CHANGED
@@ -1,15 +1,15 @@
1
- require 'active_support/concern'
2
- require 'active_support/core_ext/class/attribute'
3
- require 'active_support/core_ext/module/attribute_accessors'
1
+ require "active_support/concern"
2
+ require "active_support/core_ext/class/attribute"
3
+ require "active_support/core_ext/module/attribute_accessors"
4
4
  require "active_support/core_ext/object/blank"
5
- require 'hashie'
6
- require 'pathname'
7
- require 'yaml'
8
- require 'erb'
5
+ require "erb"
6
+ require "hashie"
7
+ require "pathname"
8
+ require "yaml"
9
9
 
10
10
  module Figleaf
11
- autoload :Config, 'figleaf/config'
12
- autoload :Fighash, 'figleaf/fighash'
13
- autoload :Settings, 'figleaf/settings'
14
- autoload :VERSION, 'figleaf/version'
11
+ autoload :Config, "figleaf/config"
12
+ autoload :Fighash, "figleaf/fighash"
13
+ autoload :Settings, "figleaf/settings"
14
+ autoload :VERSION, "figleaf/version"
15
15
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  module Figleaf
4
4
  RSpec.describe Config do
@@ -30,13 +30,13 @@ module Figleaf
30
30
  describe "#call" do
31
31
  subject(:called) { config.call(&code) }
32
32
  it "stores first level keywords as keys" do
33
- expect(called.keys).to contain_exactly(*%w(
33
+ expect(called.keys).to contain_exactly(*%w[
34
34
  default
35
35
  failer
36
36
  production
37
37
  setting_set_on_root
38
38
  test
39
- ))
39
+ ])
40
40
  end
41
41
 
42
42
  it "expands default" do
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Figleaf::Settings do
4
4
  describe "setters and getters" do
@@ -87,7 +87,7 @@ describe Figleaf::Settings do
87
87
 
88
88
  it "return true for lists" do
89
89
  described_class.configure_with_auto_define do |s|
90
- s.not_a_boolean = %w(1 2 3)
90
+ s.not_a_boolean = %w[1 2 3]
91
91
  end
92
92
 
93
93
  described_class.not_a_boolean?.should be true
@@ -116,5 +116,4 @@ describe Figleaf::Settings do
116
116
  }.to raise_error
117
117
  end
118
118
  end
119
-
120
119
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Figleaf::Fighash do
4
4
  describe "#to_hash" do
@@ -8,18 +8,18 @@ describe Figleaf::Fighash do
8
8
 
9
9
  context "should have symbols as keys" do
10
10
  it "for symbol keys" do
11
- subject = described_class.new({ a: :b, c: 1, d: "foo" })
12
- subject.to_hash.should == { a: :b, c: 1, d: "foo" }
11
+ subject = described_class.new({a: :b, c: 1, d: "foo"})
12
+ subject.to_hash.should == {a: :b, c: 1, d: "foo"}
13
13
  end
14
14
 
15
15
  it "for string keys" do
16
- subject = described_class.new({ "a" => :b, "c" => 1, "d" => "foo" })
17
- subject.to_hash.should == { a: :b, c: 1, d: "foo" }
16
+ subject = described_class.new({"a" => :b, "c" => 1, "d" => "foo"})
17
+ subject.to_hash.should == {a: :b, c: 1, d: "foo"}
18
18
  end
19
19
 
20
20
  it "should have symbols as keys inside two levels" do
21
- subject = described_class.new({ a: { b: :d } })
22
- subject.to_hash.should == { a: { b: :d } }
21
+ subject = described_class.new({a: {b: :d}})
22
+ subject.to_hash.should == {a: {b: :d}}
23
23
  end
24
24
  end
25
25
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Figleaf::Settings do
4
4
  describe "self.load_settings" do
@@ -47,12 +47,12 @@ describe Figleaf::Settings do
47
47
  end
48
48
 
49
49
  it "and for erb values" do
50
- expect(described_class.erb.foo).to eq('foo')
50
+ expect(described_class.erb.foo).to eq("foo")
51
51
  expect(described_class.erb.bar).to be_nil
52
52
  end
53
53
 
54
54
  it "raise exception when loading an undefined value" do
55
- YAML.stub(:load_yaml_file).and_return({ "test" => {} })
55
+ YAML.stub(:load_yaml_file).and_return({"test" => {}})
56
56
  described_class.load_settings
57
57
  expect { described_class.service.blah }.to raise_error NoMethodError
58
58
  end
@@ -62,8 +62,8 @@ describe Figleaf::Settings do
62
62
  let(:overload) { File.expand_path("../../fixtures/errors/*.yml", __FILE__) }
63
63
 
64
64
  it "reports the file that has errors" do
65
- expect { described_class.load_settings(overload, "test") }.
66
- to raise_error(described_class::InvalidYAML)
65
+ expect { described_class.load_settings(overload, "test") }
66
+ .to raise_error(described_class::InvalidYAML)
67
67
  end
68
68
  end
69
69
 
@@ -71,8 +71,8 @@ describe Figleaf::Settings do
71
71
  let(:overload) { File.expand_path("../../fixtures/errors/*.rb", __FILE__) }
72
72
 
73
73
  it "reports the file that has errors" do
74
- expect { described_class.load_settings(overload, "test") }.
75
- to raise_error(described_class::InvalidRb)
74
+ expect { described_class.load_settings(overload, "test") }
75
+ .to raise_error(described_class::InvalidRb)
76
76
  end
77
77
  end
78
78
  end
@@ -84,8 +84,8 @@ describe Figleaf::Settings do
84
84
  end
85
85
 
86
86
  it "merge values for matching env" do
87
- expect(described_class.service.foo).to eq 'overridden'
88
- expect(described_class.service.extra).to eq 'extra'
87
+ expect(described_class.service.foo).to eq "overridden"
88
+ expect(described_class.service.extra).to eq "extra"
89
89
  expect(described_class.service.bool_false).to eq(false)
90
90
  expect(described_class.service.bool_true).to eq(true)
91
91
  end
@@ -167,7 +167,7 @@ describe Figleaf::Settings do
167
167
  end
168
168
 
169
169
  it "and for ENV values" do
170
- expect(described_class.code.from_env).to eq('foo')
170
+ expect(described_class.code.from_env).to eq("foo")
171
171
  end
172
172
  end
173
173
  end
@@ -17,5 +17,5 @@ test do
17
17
  bool_false false
18
18
  array 1, 2, 3, 4
19
19
  array_alt [1, 2, 3, 4]
20
- from_env ENV['FIGLEAF_TEST_FOO']
20
+ from_env ENV["FIGLEAF_TEST_FOO"]
21
21
  end
data/spec/spec_helper.rb CHANGED
@@ -19,5 +19,5 @@ RSpec.configure do |config|
19
19
  config.order = "random"
20
20
  end
21
21
 
22
- ENV['FIGLEAF_TEST_FOO'] ||= 'foo'
22
+ ENV["FIGLEAF_TEST_FOO"] ||= "foo"
23
23
  # ENV['FIGLEAF_TEST_BAR'] intentionally left blank
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: figleaf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan C. Müller
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-29 00:00:00.000000000 Z
11
+ date: 2024-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -82,7 +82,7 @@ files:
82
82
  homepage: http://github.com/jcmuller/figleaf
83
83
  licenses: []
84
84
  metadata: {}
85
- post_install_message:
85
+ post_install_message:
86
86
  rdoc_options: []
87
87
  require_paths:
88
88
  - lib
@@ -97,27 +97,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  requirements: []
100
- rubyforge_project:
101
- rubygems_version: 2.6.11
102
- signing_key:
100
+ rubygems_version: 3.4.19
101
+ signing_key:
103
102
  specification_version: 4
104
103
  summary: YAML based DRY settings manager.
105
- test_files:
106
- - spec/figleaf/config_spec.rb
107
- - spec/figleaf/configuration_spec.rb
108
- - spec/figleaf/fighash_spec.rb
109
- - spec/figleaf/settings_spec.rb
110
- - spec/fixtures/array.yml
111
- - spec/fixtures/boolean.yml
112
- - spec/fixtures/erb.yml
113
- - spec/fixtures/errors/bad_file.rb
114
- - spec/fixtures/errors/bad_file.yml
115
- - spec/fixtures/extra/array.yml
116
- - spec/fixtures/extra/boolean.yml
117
- - spec/fixtures/extra/code.rb
118
- - spec/fixtures/extra/default.yml
119
- - spec/fixtures/extra/default_anchor.yml
120
- - spec/fixtures/extra/service.yml
121
- - spec/fixtures/service.yml
122
- - spec/fixtures/string.yml
123
- - spec/spec_helper.rb
104
+ test_files: []