evt-settings 2.1.0.1 → 2.1.1.5

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: 73261dc36a7d4a3e69fe4e51ed24a47c45e10c4cc39dfca3b452f98d68ebd3f8
4
- data.tar.gz: 6b7c4b23a627f0b680c8dc21d527bd061f463c49678d86d3b7f5ac9dd9ac131d
3
+ metadata.gz: '0861705e053ad84b0a2d9116a3e0d5b6e539bd7aa835922b5376050ef259b200'
4
+ data.tar.gz: 1e7fff33cbcef9d3c4715d9eac4902bb3f0ba4befc6db049d7924b4434e7fafd
5
5
  SHA512:
6
- metadata.gz: 8ac46c3087b20da7d861d10d6c9965631bfa0685c11050f43593d94e1717690792694e1b9a80781bb7d74e98dce7c9581763927090beccb1db9b73ce5ad2e30c
7
- data.tar.gz: 13e21915f9c651e87d991f6a03f5814a3452a1368b12b1d2081993b7bdfa4b140153088e73b081a7a6ec9678926a54536584e800a079fcd2c38fb9ec87f58ec5
6
+ metadata.gz: 2cd618935b2efa01fd828e0884a061c83880c67eea7ee8ae7553a1e2878d3df830afc7a7a16150c4b532bb4f6167ace0b3d37a48c4e9688d29d0382a2889d493
7
+ data.tar.gz: 105fc355cd83b9e5e5b7717e9d571cac1bc62f354ef995780831f9433df544885890cac4299e62b8950a4e732ab0d5108f5f392a3ef6375d292e163dd6733a3d
@@ -1,13 +1,12 @@
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'
9
+ require 'settings/data_source/env'
11
10
  require 'settings/data_source/file'
12
11
  require 'settings/data_source/build'
13
12
  require 'settings/registry'
@@ -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)
@@ -10,6 +10,7 @@ class Settings
10
10
  def self.type(input=nil)
11
11
  return Settings::DataSource::Hash if input.is_a?(::Hash)
12
12
  return Settings::DataSource::File if input.is_a?(String) || input.nil?
13
+ return Settings::DataSource::Env if input.instance_of?(Object)
13
14
 
14
15
  raise Settings::Error, "Input is not supported: #{input}"
15
16
  end
@@ -0,0 +1,11 @@
1
+ class Settings
2
+ class DataSource
3
+ class Env < DataSource
4
+ def get_data
5
+ source.map do |k, v|
6
+ [k.downcase, v]
7
+ end.to_h
8
+ end
9
+ end
10
+ end
11
+ end
@@ -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.0.1
4
+ version: 2.1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-10 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
  - - ">="
@@ -66,9 +66,9 @@ files:
66
66
  - lib/settings/controls/subject.rb
67
67
  - lib/settings/data_source.rb
68
68
  - lib/settings/data_source/build.rb
69
+ - lib/settings/data_source/env.rb
69
70
  - lib/settings/data_source/file.rb
70
71
  - lib/settings/data_source/hash.rb
71
- - lib/settings/log.rb
72
72
  - lib/settings/registry.rb
73
73
  - lib/settings/setting.rb
74
74
  - lib/settings/setting/assignment.rb
@@ -78,7 +78,7 @@ homepage: https://github.com/eventide-project/settings
78
78
  licenses:
79
79
  - MIT
80
80
  metadata: {}
81
- post_install_message:
81
+ post_install_message:
82
82
  rdoc_options: []
83
83
  require_paths:
84
84
  - lib
@@ -93,8 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  requirements: []
96
- rubygems_version: 3.0.1
97
- signing_key:
96
+ rubygems_version: 3.1.2
97
+ signing_key:
98
98
  specification_version: 4
99
99
  summary: Settings data access and assignment
100
100
  test_files: []
@@ -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