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 +5 -5
- data/CHANGELOG.md +6 -0
- data/Gemfile +11 -9
- data/Guardfile +10 -10
- data/Rakefile +1 -1
- data/figleaf.gemspec +10 -12
- data/lib/figleaf/config.rb +13 -23
- data/lib/figleaf/settings.rb +23 -24
- data/lib/figleaf/version.rb +1 -1
- data/lib/figleaf.rb +11 -11
- data/spec/figleaf/config_spec.rb +3 -3
- data/spec/figleaf/configuration_spec.rb +2 -3
- data/spec/figleaf/fighash_spec.rb +7 -7
- data/spec/figleaf/settings_spec.rb +10 -10
- data/spec/fixtures/extra/code.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +7 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d9587314be7114b5e08704a3f1e2364f41cf90f926c890554b8dd31582dbd7c2
|
4
|
+
data.tar.gz: 7f1731a8135590e9992ff1a2e40382fd36f11f9bb3739d6006546a40069ee948
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
17
|
-
gem
|
18
|
-
gem
|
19
|
-
gem
|
20
|
-
gem
|
21
|
-
gem "terminal-notifier-guard", :
|
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-
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
when :darwin
|
4
|
+
:gntp
|
5
|
+
when :linux
|
6
|
+
require "libnotify"
|
7
|
+
:libnotify
|
8
|
+
end
|
9
9
|
|
10
10
|
guard :bundler do
|
11
|
-
require
|
12
|
-
require
|
11
|
+
require "guard/bundler"
|
12
|
+
require "guard/bundler/verify"
|
13
13
|
helper = Guard::Bundler::Verify.new
|
14
14
|
|
15
|
-
files = [
|
16
|
-
files += Dir[
|
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
data/figleaf.gemspec
CHANGED
@@ -1,19 +1,17 @@
|
|
1
|
-
|
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
|
6
|
-
gem.email
|
7
|
-
gem.description
|
8
|
-
gem.summary
|
9
|
-
gem.homepage
|
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
|
12
|
-
gem.executables
|
13
|
-
gem.
|
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
|
14
|
+
gem.version = Figleaf::VERSION
|
17
15
|
|
18
16
|
gem.add_dependency "activesupport", ">= 3"
|
19
17
|
gem.add_dependency "hashie", ">= 2"
|
data/lib/figleaf/config.rb
CHANGED
@@ -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(&
|
9
|
-
instance_eval(&
|
6
|
+
def call(&)
|
7
|
+
instance_eval(&)
|
10
8
|
|
11
9
|
property
|
12
|
-
rescue
|
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,
|
17
|
-
process_method(method_name, *args, &block)
|
18
|
-
end
|
14
|
+
def method_missing(method_name, *, &) = process_method(method_name, *, &)
|
19
15
|
|
20
|
-
def test(&
|
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
|
20
|
+
if block
|
27
21
|
obj = self.class.new
|
28
|
-
|
22
|
+
proc { obj.call(&block) }
|
23
|
+
elsif args.count == 1
|
24
|
+
args[0]
|
29
25
|
else
|
30
|
-
|
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
|
-
|
34
|
+
attr_reader :property
|
45
35
|
end
|
46
36
|
|
47
37
|
class LazyBlockHash < Hash
|
data/lib/figleaf/settings.rb
CHANGED
@@ -10,7 +10,7 @@ module Figleaf
|
|
10
10
|
# Public - configure pre-defined attributes
|
11
11
|
#
|
12
12
|
def configure
|
13
|
-
|
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!(&
|
23
|
+
def configure!(&)
|
24
24
|
load_settings
|
25
|
-
configure_with_auto_define(&
|
25
|
+
configure_with_auto_define(&)
|
26
26
|
end
|
27
27
|
|
28
28
|
def configure_with_auto_define
|
29
|
-
|
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
|
50
|
-
|
49
|
+
if respond_to?(property_name) &&
|
50
|
+
send(property_name).respond_to?(:merge) &&
|
51
51
|
property.respond_to?(:merge)
|
52
|
-
property =
|
52
|
+
property = send(property_name).merge(property)
|
53
53
|
end
|
54
54
|
|
55
|
-
|
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?(
|
62
|
-
property_name = File.basename(file,
|
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,
|
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.
|
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(
|
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[
|
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.
|
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
|
122
|
-
|
123
|
-
|
124
|
-
elsif modifier ==
|
125
|
-
|
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
|
data/lib/figleaf/version.rb
CHANGED
data/lib/figleaf.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
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
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
5
|
+
require "erb"
|
6
|
+
require "hashie"
|
7
|
+
require "pathname"
|
8
|
+
require "yaml"
|
9
9
|
|
10
10
|
module Figleaf
|
11
|
-
autoload :Config,
|
12
|
-
autoload :Fighash,
|
13
|
-
autoload :Settings,
|
14
|
-
autoload :VERSION,
|
11
|
+
autoload :Config, "figleaf/config"
|
12
|
+
autoload :Fighash, "figleaf/fighash"
|
13
|
+
autoload :Settings, "figleaf/settings"
|
14
|
+
autoload :VERSION, "figleaf/version"
|
15
15
|
end
|
data/spec/figleaf/config_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
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
|
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
|
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
|
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({
|
12
|
-
subject.to_hash.should == {
|
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({
|
17
|
-
subject.to_hash.should == {
|
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({
|
22
|
-
subject.to_hash.should == {
|
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
|
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(
|
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({
|
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
|
88
|
-
expect(described_class.service.extra).to eq
|
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(
|
170
|
+
expect(described_class.code.from_env).to eq("foo")
|
171
171
|
end
|
172
172
|
end
|
173
173
|
end
|
data/spec/fixtures/extra/code.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
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.
|
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:
|
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
|
-
|
101
|
-
|
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: []
|