usable 3.7.1 → 3.8.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
2
  SHA1:
3
- metadata.gz: 0a5a38c4e6b7ce12dc8babbb63d9c8ebfca63619
4
- data.tar.gz: 3657c1890f435d920a0e08429956f728fec8b330
3
+ metadata.gz: 8075d1fbe92a5e6264d68e0ef7c7e874def4d8f1
4
+ data.tar.gz: eeec86f688c53eb9a3f19c5a0e938e5f4e3a1d6d
5
5
  SHA512:
6
- metadata.gz: 9581e053956c78d748cb59431395d569d059b52f5682834a2834ac53d136ca1b55561852bebf6626e1bcddc6dfd697c8890209df11d17a5040e4a6766cf8c9ec
7
- data.tar.gz: b8b305ed5e491828febd8f68b0767bbed70425636b5196609700578a04c275103d7945ea0630730d04eb8d5b3cec97ae6a58adcdf705ae47f9868f53248ff6cd
6
+ metadata.gz: 45639fe02b2890ede739f810f805a796b60e67b5a79c14d719ae9f17a9d427644df81c9cc3a4cdfb867665ce1627bccc72bbdadf84b743502641a65442d9f865
7
+ data.tar.gz: 50a8adb07f611ab908ecf6cb2b6d81c17aad65b1036a0557ec56fdda66856e837e5ea41da35d9761900de84d072d3dde279bf19e7dd0219345f5b3b478468b04
data/lib/usable/config.rb CHANGED
@@ -43,6 +43,14 @@ module Usable
43
43
  to_h.merge(other)
44
44
  end
45
45
 
46
+ # @param other [Hash] to update ourselves with
47
+ def merge!(other)
48
+ other.each do |key, val|
49
+ @spec[key] = val
50
+ end
51
+ self
52
+ end
53
+
46
54
  def method_missing(key, *args, &block)
47
55
  if block
48
56
  @lazy_loads << key
data/lib/usable/struct.rb CHANGED
@@ -2,10 +2,9 @@ module Usable
2
2
  def self.Struct(attributes = {})
3
3
  Class.new do
4
4
  extend Usable
5
-
6
5
  self.usables = Usable::Config.new(attributes)
7
-
8
- attributes.keys.each do |key|
6
+ define_usable_accessors
7
+ attributes.keys.map(&:to_sym).each do |key|
9
8
  define_method(key) { @attrs[key] }
10
9
  define_method("#{key}=") { |new_val| @attrs[key] = new_val }
11
10
  end
@@ -15,6 +14,18 @@ module Usable
15
14
  def initialize(attrs = {})
16
15
  @attrs = usables.merge(attrs)
17
16
  end
17
+
18
+ def [](key)
19
+ @attrs[key]
20
+ end
21
+
22
+ def []=(key, val)
23
+ @attrs[key] = val
24
+ end
25
+
26
+ def each(&block)
27
+ @attrs.each(&block)
28
+ end
18
29
  end
19
30
  end
20
31
  end
@@ -1,3 +1,3 @@
1
1
  module Usable
2
- VERSION = "3.7.1".freeze
2
+ VERSION = "3.8.0".freeze
3
3
  end
data/lib/usable.rb CHANGED
@@ -88,6 +88,13 @@ module Usable
88
88
  super
89
89
  end
90
90
 
91
+ def define_usable_accessors
92
+ usables.to_h.keys.each do |key|
93
+ define_singleton_method(key) { usables[key] }
94
+ define_singleton_method("#{key}=") { |new_val| usables[key] = new_val }
95
+ end
96
+ end
97
+
91
98
  def usables
92
99
  @usables ||= Config.new
93
100
  end
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.7.1
4
+ version: 3.8.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: 2017-04-03 00:00:00.000000000 Z
11
+ date: 2017-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler