usable 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +3 -3
- data/bin/console +9 -1
- data/lib/usable/config.rb +34 -28
- data/lib/usable/config_multi.rb +6 -6
- data/lib/usable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6635f1e16cd089ac2239170c5904b965b148f0f
|
4
|
+
data.tar.gz: a25bed9af17e5dbacefe34eb1005d38b7be5669e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7465c315a1f2f3baca1c9210f8b9880157d5bc74a68f0b8f29aa86dffdbf0c5d16d08951bd68bdb309a9dd1bad5653a7dcaff265c47746c56d3989ab28e5de2
|
7
|
+
data.tar.gz: d4ac3cc2a46e42434d5b606471b8349600c68e50a28eec1b0c503eeab1155fed1df46e5ac897d8960ee887eaf3ff150ac9b81df214994f652582907b7bf748b1
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
3.2 (12/1/2016)
|
2
|
+
===============
|
3
|
+
|
4
|
+
* Improve performance of reads by defining usable attributes as methods
|
5
|
+
* `usables._spec` is now `usables.spec`
|
6
|
+
|
7
|
+
3.1 (11/30/2016)
|
8
|
+
================
|
9
|
+
|
10
|
+
* Convert +usables+ to a hash with +to_h+
|
11
|
+
|
1
12
|
3.0 (11/4/2016)
|
2
13
|
===============
|
3
14
|
|
data/README.md
CHANGED
data/bin/console
CHANGED
@@ -22,7 +22,15 @@ end
|
|
22
22
|
|
23
23
|
module Mixin
|
24
24
|
extend Usable
|
25
|
-
|
25
|
+
config.language = :en
|
26
|
+
config do
|
27
|
+
country 'US'
|
28
|
+
state 'Hawaii'
|
29
|
+
census({
|
30
|
+
population: 1_400_00,
|
31
|
+
daily_visitors: 218_150
|
32
|
+
})
|
33
|
+
end
|
26
34
|
|
27
35
|
def name
|
28
36
|
"defined by Mixin"
|
data/lib/usable/config.rb
CHANGED
@@ -13,56 +13,62 @@ module Usable
|
|
13
13
|
@lazy_loads = Set.new
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
@spec.to_h.each(&block)
|
18
|
-
end
|
19
|
-
|
20
|
-
def spec(key, value = nil)
|
21
|
-
if value
|
22
|
-
@spec[key.to_s.tr('=', '')] = value
|
23
|
-
else
|
24
|
-
# Handle the case where the value may be defined with a block, in which case it's a method
|
25
|
-
@spec[key] ||= call_lazy_method(key)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def _spec
|
16
|
+
def spec
|
30
17
|
@spec
|
31
18
|
end
|
32
19
|
|
33
20
|
def [](key)
|
34
|
-
spec
|
21
|
+
@spec[key]
|
35
22
|
end
|
36
23
|
|
37
24
|
def []=(key, val)
|
38
|
-
spec
|
25
|
+
@spec[key] = val
|
26
|
+
end
|
27
|
+
|
28
|
+
def each(&block)
|
29
|
+
@spec.to_h.each(&block)
|
39
30
|
end
|
40
31
|
|
41
32
|
def to_h
|
42
|
-
@lazy_loads.each { |key| spec(key) }
|
43
|
-
|
33
|
+
@lazy_loads.each { |key| @spec[key] = call_spec_method(key) }
|
34
|
+
@spec.to_h
|
44
35
|
end
|
45
36
|
|
46
37
|
alias to_hash to_h
|
47
38
|
|
48
|
-
def
|
49
|
-
@lazy_loads.delete key
|
50
|
-
@spec.public_send key.to_s.tr('=', '')
|
51
|
-
end
|
52
|
-
|
53
|
-
def method_missing(method_name, *args, &block)
|
39
|
+
def method_missing(key, *args, &block)
|
54
40
|
if block
|
55
|
-
|
56
|
-
@
|
41
|
+
@lazy_loads << key
|
42
|
+
@spec.define_singleton_method(key) { yield }
|
57
43
|
else
|
58
|
-
|
44
|
+
key = key.to_s.tr('=', '')
|
45
|
+
if args.empty?
|
46
|
+
value = @spec[key] ||= call_spec_method(key)
|
47
|
+
define_singleton_method(key) { @spec[key] }
|
48
|
+
value
|
49
|
+
else
|
50
|
+
@spec[key] = args.first
|
51
|
+
end
|
59
52
|
end
|
60
53
|
rescue NoMethodError
|
61
54
|
super
|
62
55
|
end
|
63
56
|
|
64
57
|
def respond_to_missing?(method_name, _private = false)
|
65
|
-
method_name.to_s.end_with?('=') ||
|
58
|
+
method_name.to_s.end_with?('=') || @spec.respond_to?(method_name)
|
59
|
+
end
|
60
|
+
|
61
|
+
def freeze
|
62
|
+
to_h.each { |key, value| define_singleton_method(key) { value } }
|
63
|
+
super
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
# @note Handles the case where the value may be defined with a block, in which case it's a method
|
69
|
+
def call_spec_method(key)
|
70
|
+
@lazy_loads.delete key
|
71
|
+
@spec.public_send key
|
66
72
|
end
|
67
73
|
end
|
68
74
|
end
|
data/lib/usable/config_multi.rb
CHANGED
@@ -4,13 +4,13 @@ module Usable
|
|
4
4
|
# Set block specs to nil values so it will fallback to calling the underlying singleton method defined by Config#method_missing
|
5
5
|
def +(other)
|
6
6
|
config = clone
|
7
|
-
specs = other.
|
8
|
-
specs.each { |key, val| config
|
9
|
-
methods = other.
|
7
|
+
specs = other.spec.to_h
|
8
|
+
specs.each { |key, val| config[key] = val }
|
9
|
+
methods = other.spec.singleton_methods - specs.keys
|
10
10
|
methods.each do |name|
|
11
|
-
config.
|
12
|
-
config.
|
13
|
-
other.
|
11
|
+
config.spec[name] = nil
|
12
|
+
config.spec.define_singleton_method(name) do
|
13
|
+
other.spec.public_method(name).call
|
14
14
|
end
|
15
15
|
end
|
16
16
|
config
|
data/lib/usable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Buckley
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|