evt-settings 2.1.1.0 → 2.1.1.1

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: fb5a4eb960f4d0e780bbcd97bb2e91416baf7b90b1268c7ae92fdf1663ec784d
4
- data.tar.gz: 5ed28384eb54314aa31a421ba84355ed944ae932d5675c0c4c0ae6917e0b57c6
3
+ metadata.gz: 68e0691d8994930cab7259e915ec865bab803c3ff7a025a3eea790c2e769a405
4
+ data.tar.gz: 5acd8233c2624f5a7883846b51b33ada95f40fa9c5ad64155597178a50d715e2
5
5
  SHA512:
6
- metadata.gz: 0ad24968d8d1f02c1922d315868f5ed9a382d6308d856cf33168571e60be98ae70927feb68992e69d957d651ec6b86388ae8b87fdca7f7d95884d063729b6b5d
7
- data.tar.gz: 5053f0ceffe12425ae380be52a484bed75ebd6f292989415bb9c7792b9a274fce768386fe760fad28e63916859b6788255e484deb187ce8d72d78ce972ebd708
6
+ metadata.gz: d3765bde5adcfc8f19023d246fdbccc07073d32aa5acf0ce7a8aa5b52bc37f3586541fe06091a34021ae1d1a737a225163438163f09930526232cb92ee2dcfdc
7
+ data.tar.gz: 259ba6bb657b7beed6fa5dd5dbffd12884819e2b8f5d94543f6ef2ceacdf47ae6001bcc2dbe0bdd23d2b880cb4307c464d0831f52fdfa75d26be8cb0027045fe
@@ -1,11 +1,9 @@
1
1
  require 'pathname'
2
2
  require 'json'
3
3
 
4
- require 'log'
5
4
  require 'casing'
6
5
  require 'attribute'
7
6
 
8
- require 'settings/log'
9
7
  require 'settings/data_source'
10
8
  require 'settings/data_source/hash'
11
9
  require 'settings/data_source/env'
@@ -1,7 +1,5 @@
1
1
  class Settings
2
2
  class DataSource
3
- include Log::Dependency
4
-
5
3
  attr_reader :source
6
4
 
7
5
  def initialize(source)
@@ -1,10 +1,6 @@
1
1
  class Settings
2
2
  class DataSource
3
3
  class Env < DataSource
4
- def self.logger
5
- @logger ||= Log.get(self)
6
- end
7
-
8
4
  def get_data
9
5
  source.map do |k, v|
10
6
  [k.downcase, v]
@@ -2,13 +2,9 @@ class Settings
2
2
  class DataSource
3
3
  class File < DataSource
4
4
  def self.canonize(source)
5
- logger.trace { "Canonizing the file source (Source: #{source})" }
6
-
7
5
  canonized_filepath = canonize_filepath(source)
8
6
  validate(canonized_filepath)
9
7
 
10
- logger.debug { "Canonized the file source (Source: #{source}, Canonized: #{canonized_filepath})" }
11
-
12
8
  canonized_filepath
13
9
  end
14
10
 
@@ -28,8 +24,6 @@ class Settings
28
24
  dirpath ||= Pathname.new(source)
29
25
  filepath ||= Pathname.new(source)
30
26
 
31
- logger.debug { "Canonized the file source (#{source})" }
32
-
33
27
  pathname(filepath, dirpath)
34
28
  end
35
29
 
@@ -57,56 +51,32 @@ class Settings
57
51
  end
58
52
 
59
53
  def self.validate(pathname)
60
- logger.trace { "Validating the pathname (#{pathname})" }
61
-
62
54
  pathname = Pathname.new(pathname)
63
55
 
64
56
  unless pathname.file?
65
- msg = "Settings cannot be read from #{pathname}. The file doesn't exist."
66
- logger.error { msg }
67
- raise Settings::Error, msg
57
+ raise Settings::Error, "Settings cannot be read from #{pathname}. The file doesn't exist."
68
58
  end
69
-
70
- logger.trace { "Validated the pathname (#{pathname})" }
71
- end
72
-
73
- def self.logger
74
- @logger ||= Log.get(self)
75
59
  end
76
60
 
77
61
  def get_data
78
- logger.trace { "Reading file: #{source}" }
79
62
  file = ::File.open(source)
80
- data = JSON.load(file).tap do
81
- logger.debug { "Read file: #{source}" }
82
- end
63
+
64
+ data = JSON.load(file)
83
65
 
84
66
  hash_data_source = Hash.build data
85
67
  hash_data_source.get_data
86
68
  end
87
69
 
88
70
  module Defaults
89
- def self.logger
90
- @logger ||= Log.get(self)
91
- end
92
-
93
71
  def self.filename
94
- default_file = 'settings.json'
95
- logger.debug { "Using the default settings file name (#{default_file})" }
96
- default_file
72
+ 'settings.json'
97
73
  end
98
74
  end
99
75
 
100
76
  module Directory
101
77
  module Defaults
102
- def self.logger
103
- @logger ||= Log.get(self)
104
- end
105
-
106
78
  def self.pathname
107
- default_dir = Dir.pwd
108
- logger.debug { "Using the working directory default settings directory (#{default_dir})" }
109
- default_dir
79
+ Dir.pwd
110
80
  end
111
81
  end
112
82
  end
@@ -1,10 +1,6 @@
1
1
  class Settings
2
2
  class DataSource
3
3
  class Hash < DataSource
4
- def self.logger
5
- @logger ||= Log.get(self)
6
- end
7
-
8
4
  def get_data
9
5
  AssureStringKeys.(source)
10
6
  end
@@ -3,10 +3,6 @@ class Settings
3
3
  module Assignment
4
4
  extend self
5
5
 
6
- def logger
7
- @logger ||= Log.get(self)
8
- end
9
-
10
6
  def assign(receiver, attribute, value, strict=false)
11
7
  settable = assure_settable(receiver, attribute, strict)
12
8
  if settable
@@ -17,11 +13,7 @@ class Settings
17
13
  end
18
14
 
19
15
  def assign_value(receiver, attribute, value)
20
- logger.trace { "Assigning to #{attribute}" }
21
- receiver.public_send("#{attribute}=", value).tap do
22
- logger.debug { "Assigned to #{attribute}" }
23
- logger.debug(tag: :data) { "#{attribute}: #{value}" }
24
- end
16
+ receiver.public_send("#{attribute}=", value)
25
17
  end
26
18
 
27
19
  def setting?(receiver, attribute)
@@ -37,40 +29,22 @@ class Settings
37
29
  :"#{attribute.to_s}=" unless attribute.to_s.end_with? '='
38
30
  end
39
31
 
40
- def digest(receiver, attribute, strict)
41
- content = []
42
- content << "Attribute: #{attribute}" if attribute
43
- content << "Receiver: #{receiver.class.name}"
44
- strict = "<not set>" if strict.nil?
45
- content << "Strict: #{strict}"
46
- content.join ', '
47
- end
48
-
49
32
  module Object
50
33
  extend Assignment
51
34
 
52
- def logger
53
- @logger ||= Log.get(self)
54
- end
55
-
56
35
  def self.assure_settable(receiver, attribute, strict=true)
57
- logger.trace { "Approving attribute (#{digest(receiver, attribute, strict)})" }
58
-
59
36
  if strict
60
37
  setting = setting?(receiver, attribute)
61
38
  unless setting
62
- logger.warn { "Can't set \"#{attribute}\". It isn't a setting of #{receiver.class.name}." }
63
39
  return false
64
40
  end
65
41
  end
66
42
 
67
43
  assignable = assignable? receiver, attribute
68
44
  unless assignable
69
- logger.warn { "Can't set \"#{attribute}\". It isn't assignable to #{receiver.class.name}." }
70
45
  return false
71
46
  end
72
47
 
73
- logger.debug { "\"#{attribute}\" can be set" }
74
48
  true
75
49
  end
76
50
  end
@@ -78,28 +52,19 @@ class Settings
78
52
  module Attribute
79
53
  extend Assignment
80
54
 
81
- def logger
82
- @logger ||= Log.get(self)
83
- end
84
-
85
55
  def self.assure_settable(receiver, attribute, strict=true)
86
56
  if strict
87
57
  setting = setting? receiver, attribute
88
58
  unless setting
89
- msg = "Can't set \"#{attribute}\". It isn't a setting of #{receiver.class.name}."
90
- logger.error { msg }
91
- raise msg
59
+ raise "Can't set \"#{attribute}\". It isn't a setting of #{receiver.class.name}."
92
60
  end
93
61
  end
94
62
 
95
- assignable = assignable? receiver, attribute
63
+ assignable = assignable?(receiver, attribute)
96
64
  unless assignable
97
- msg = "Can't set \"#{attribute}\". It isn't assignable to #{receiver.class.name}."
98
- logger.error { msg }
99
- raise msg
65
+ raise "Can't set \"#{attribute}\". It isn't assignable to #{receiver.class.name}."
100
66
  end
101
67
 
102
- logger.debug { "\"#{attribute}\" can be set" }
103
68
  true
104
69
  end
105
70
  end
@@ -2,13 +2,8 @@ class Settings
2
2
  module Setting
3
3
  module Macro
4
4
  def setting_macro(attribute)
5
- logger = Log.get(self)
6
-
7
- logger.trace { "Defining setting attribute: #{attribute}" }
8
5
  Attribute::Define.(self, attribute, :accessor)
9
- Settings::Registry.register(self, attribute).tap do
10
- logger.debug { "Defined setting attribute: #{attribute}" }
11
- end
6
+ Settings::Registry.register(self, attribute)
12
7
  end
13
8
  alias :setting :setting_macro
14
9
  end
@@ -1,18 +1,12 @@
1
1
  class Settings
2
2
  class Error < RuntimeError; end
3
3
 
4
- include Log::Dependency
5
-
6
4
  attr_reader :data
7
5
 
8
6
  def initialize(data)
9
7
  @data = data
10
8
  end
11
9
 
12
- def self.logger
13
- @logger ||= Log.get(self)
14
- end
15
-
16
10
  def self.build(source=nil)
17
11
  source ||= implementer_source
18
12
 
@@ -28,20 +22,14 @@ class Settings
28
22
  end
29
23
 
30
24
  def self.implementer_source
31
- logger.trace { "Getting data source from the implementer" }
32
-
33
- unless self.respond_to? :data_source
34
- logger.trace { "Implementer doesn't provide a data_source" }
25
+ unless self.respond_to?(:data_source)
35
26
  return nil
36
27
  end
37
28
 
38
- self.data_source.tap do |data_source|
39
- logger.trace { "Got data source from the implementer (#{data_source})" }
40
- end
29
+ self.data_source
41
30
  end
42
31
 
43
32
  def set(receiver, *namespace, attribute: nil, strict: true)
44
- logger.trace { "Setting #{receiver.class.name} (#{digest(namespace, attribute, strict)})" }
45
33
  unless attribute.nil?
46
34
  value = set_attribute(receiver, attribute, namespace, strict)
47
35
  else
@@ -51,8 +39,6 @@ class Settings
51
39
  end
52
40
 
53
41
  def set_attribute(receiver, attribute, namespace, strict)
54
- logger.trace { "Setting #{receiver.class.name} attribute (#{digest(namespace, attribute, strict)})" }
55
-
56
42
  attribute = attribute.to_s if attribute.is_a?(Symbol)
57
43
 
58
44
  attribute_namespace = namespace.dup
@@ -61,35 +47,25 @@ class Settings
61
47
  value = get(attribute_namespace)
62
48
 
63
49
  if value.nil?
64
- msg = "#{attribute_namespace} not found in the data"
65
- logger.error { msg }
66
- raise Settings::Error, msg
50
+ raise Settings::Error, "#{attribute_namespace} not found in the data"
67
51
  end
68
52
 
69
53
  Settings::Setting::Assignment::Attribute.assign(receiver, attribute.to_sym, value, strict)
70
54
 
71
- logger.debug { "Set #{receiver.class.name} #{attribute} to #{value.inspect}" }
72
-
73
55
  value
74
56
  end
75
57
 
76
58
  def set_object(receiver, namespace, strict)
77
- logger.trace { "Setting #{receiver.class.name} object (#{digest(namespace, nil, strict)})" }
78
-
79
59
  data = get(namespace)
80
60
 
81
61
  if data.nil?
82
- msg = "#{namespace} not found in the data"
83
- logger.error { msg }
84
- raise Settings::Error, msg
62
+ raise Settings::Error, "#{namespace} not found in the data"
85
63
  end
86
64
 
87
65
  data.each do |attribute, value|
88
66
  Settings::Setting::Assignment::Object.assign(receiver, attribute.to_sym, value, strict)
89
67
  end
90
68
 
91
- logger.debug { "Set #{receiver.class.name} object (#{digest(namespace, nil, strict)})" }
92
-
93
69
  receiver
94
70
  end
95
71
 
@@ -99,7 +75,6 @@ class Settings
99
75
 
100
76
  def get(*namespace)
101
77
  namespace.flatten!
102
- logger.trace { "Getting #{namespace}" }
103
78
 
104
79
  keys = namespace.map { |n| n.is_a?(Symbol) ? n.to_s : n }
105
80
 
@@ -110,18 +85,6 @@ class Settings
110
85
  value = data.dig(*keys)
111
86
  end
112
87
 
113
- logger.debug { "Got #{namespace}" }
114
- logger.debug(tag: :data) { "#{namespace}: #{value.inspect}" }
115
-
116
88
  value
117
89
  end
118
-
119
- def digest(namespace, attribute, strict)
120
- content = []
121
- content << "Namespace: #{namespace.join ', '}" unless namespace.empty?
122
- content << "Attribute: #{attribute}" if attribute
123
- strict = "<not set>" if strict.nil?
124
- content << "Strict: #{strict}"
125
- content.join ', '
126
- end
127
90
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1.0
4
+ version: 2.1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-02 00:00:00.000000000 Z
11
+ date: 2020-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: evt-log
14
+ name: evt-attribute
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -69,7 +69,6 @@ files:
69
69
  - lib/settings/data_source/env.rb
70
70
  - lib/settings/data_source/file.rb
71
71
  - lib/settings/data_source/hash.rb
72
- - lib/settings/log.rb
73
72
  - lib/settings/registry.rb
74
73
  - lib/settings/setting.rb
75
74
  - lib/settings/setting/assignment.rb
@@ -1,9 +0,0 @@
1
- class Settings
2
- class Log < ::Log
3
- def tag!(tags)
4
- tags << :settings
5
- tags << :library
6
- tags << :verbose
7
- end
8
- end
9
- end