usable 3.2.0 → 3.3.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: d6635f1e16cd089ac2239170c5904b965b148f0f
4
- data.tar.gz: a25bed9af17e5dbacefe34eb1005d38b7be5669e
3
+ metadata.gz: 37d7979f36f818a019b5e938f9271a09021d8740
4
+ data.tar.gz: 52f7607ba637d7e1e50c2423797c0680c390af47
5
5
  SHA512:
6
- metadata.gz: b7465c315a1f2f3baca1c9210f8b9880157d5bc74a68f0b8f29aa86dffdbf0c5d16d08951bd68bdb309a9dd1bad5653a7dcaff265c47746c56d3989ab28e5de2
7
- data.tar.gz: d4ac3cc2a46e42434d5b606471b8349600c68e50a28eec1b0c503eeab1155fed1df46e5ac897d8960ee887eaf3ff150ac9b81df214994f652582907b7bf748b1
6
+ metadata.gz: be661c7880726a1fd3235c88c6ac27218f5ed88dad72088ee72da40493ba54208e71743c8951c424095936249a09c2c8db329f262e781be683088d6a4fa0d7bf
7
+ data.tar.gz: d074eea1d75951eaf494de6680a94d2cea4f721324570ef50a39c147276fedf85adac77ca5c464cc9d46a1e99a6a6a4d6281e992573196b8f2536affcdde4f6d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ 3.3.0 (12/4/2016)
2
+ =================
3
+
4
+ * FIX - `Usable::ModExtender` doesn't require the target to be "usable"
5
+ * NEW - `Usable::Struct(a: :b)` creates value classes with defaults (optional `require 'usable/struct'`)
6
+ * NEW - `usables.merge` converts usables to a hash and merges w/ the other
7
+ * NEW - Usable::Config#initialize takes a hash to set the initial attributes
8
+ * NEW - Usable politely defines `.config(&block)`
9
+ * FIX - `usables.freeze` to also freeze `@spec` so errors are raised when modifying
10
+
1
11
  3.2 (12/1/2016)
2
12
  ===============
3
13
 
data/bin/console CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  require "bundler/setup"
4
4
  require "usable"
5
+ require "usable/struct"
6
+ require "irb"
5
7
 
6
8
  # You can add fixtures and/or initialization code here to make experimenting
7
9
  # with your gem easier. You can also use a different console, if you like.
@@ -76,6 +78,4 @@ end
76
78
 
77
79
  Model.usable PersistenceOverride, method: 'prepend'
78
80
 
79
- require "irb"
80
-
81
81
  IRB.start
data/lib/usable/config.rb CHANGED
@@ -8,9 +8,10 @@ module Usable
8
8
  include ConfigRegister
9
9
  include ConfigMulti
10
10
 
11
- def initialize
12
- @spec = OpenStruct.new
11
+ def initialize(attributes = {})
12
+ @spec = OpenStruct.new(attributes)
13
13
  @lazy_loads = Set.new
14
+ # @attributes = Set.new attributes.keys.map(&:to_s)
14
15
  end
15
16
 
16
17
  def spec
@@ -36,12 +37,18 @@ module Usable
36
37
 
37
38
  alias to_hash to_h
38
39
 
40
+ def merge(other)
41
+ to_h.merge(other)
42
+ end
43
+
39
44
  def method_missing(key, *args, &block)
40
45
  if block
41
46
  @lazy_loads << key
47
+ # @attributes << key.to_s
42
48
  @spec.define_singleton_method(key) { yield }
43
49
  else
44
50
  key = key.to_s.tr('=', '')
51
+ # @attributes << key
45
52
  if args.empty?
46
53
  value = @spec[key] ||= call_spec_method(key)
47
54
  define_singleton_method(key) { @spec[key] }
@@ -60,6 +67,7 @@ module Usable
60
67
 
61
68
  def freeze
62
69
  to_h.each { |key, value| define_singleton_method(key) { value } }
70
+ @spec.freeze
63
71
  super
64
72
  end
65
73
 
@@ -26,7 +26,7 @@ module Usable
26
26
  target.send :remove_const, const_name if target.const_defined? const_name, false
27
27
  target.const_set const_name, copy
28
28
  end
29
- target.usables.add_module copy
29
+ target.usables.add_module copy if target.respond_to?(:usables)
30
30
  target.send options[:method], copy
31
31
  end
32
32
 
@@ -0,0 +1,24 @@
1
+ module Usable
2
+ def self.Struct(attributes = {})
3
+ Class.new do
4
+ extend Usable
5
+
6
+ self.usables = Usable::Config.new(attributes)
7
+
8
+ define_singleton_method(:inherited) do |child|
9
+ child.usables = usables.clone
10
+ end
11
+
12
+ attributes.keys.each do |key|
13
+ define_method(key) { @attrs[key] }
14
+ define_method("#{key}=") { |new_val| @attrs[key] = new_val }
15
+ end
16
+
17
+ attr_accessor :attrs
18
+
19
+ def initialize(attrs = {})
20
+ @attrs = usables.merge(attrs)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Usable
2
- VERSION = "3.2.0".freeze
2
+ VERSION = "3.3.0".freeze
3
3
  end
data/lib/usable.rb CHANGED
@@ -6,22 +6,21 @@ require 'usable/mod_extender'
6
6
  require 'usable/config'
7
7
 
8
8
  module Usable
9
-
10
9
  def self.extended(base)
11
- base.class_eval do
12
- def usable_method(method_name)
13
- self.class.usable_method(self, method_name)
14
- end
15
- end
16
10
  if base.is_a? Class
17
11
  # Define an instance level version of +usables+
18
12
  base.class_eval do
19
13
  def usables
20
14
  self.class.usables
21
15
  end
16
+
17
+ def usable_method(method_name)
18
+ self.class.usable_method(self, method_name)
19
+ end
22
20
  end
23
- else
24
- # Define +config+ when added to a module
21
+ end
22
+
23
+ unless base.respond_to?(:config)
25
24
  base.instance_eval do
26
25
  def config(&block)
27
26
  if block
@@ -29,7 +28,7 @@ module Usable
29
28
  else
30
29
  usables
31
30
  end
32
- end unless defined? config
31
+ end
33
32
  end
34
33
  end
35
34
  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.2.0
4
+ version: 3.3.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-12-02 00:00:00.000000000 Z
11
+ date: 2016-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -82,6 +82,7 @@ files:
82
82
  - lib/usable/config_multi.rb
83
83
  - lib/usable/config_register.rb
84
84
  - lib/usable/mod_extender.rb
85
+ - lib/usable/struct.rb
85
86
  - lib/usable/version.rb
86
87
  - usable.gemspec
87
88
  homepage: https://github.com/ridiculous/usable