tainbox 0.1.0 → 0.2.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: 5481509dcffafe5133286d95ed7bf4248db07c0e
4
- data.tar.gz: 420840720a69c64f377a6e3b2f0dc68a7e4cdba9
3
+ metadata.gz: c180884b0471d64ec257abcb626c43cd59a79fe8
4
+ data.tar.gz: fcfd7c4fd5e0ab7f3f0ada8b04409363e55032a9
5
5
  SHA512:
6
- metadata.gz: 73a294309162a0ca5babca933f90388ebb0f24fd5f15728534f71af907fc091961352a054fb13a2794cc2bfee74f2d3657183099743b53f5a5a5dc1250ff9425
7
- data.tar.gz: 48b7b7c3cfb610b9d62bacbe923856453f39bb6b16fcb25cbbe0c575730778110a39dcc7e536b0718fe9ba177476b8c2becd162b0c2ff08b383cfc52c67f8857
6
+ metadata.gz: a0f2941c17de11c3e083d3303ae87602d6f542b7ebfb7d586058278789c4e6c3e45f192b0193d6ecdbb23f24556e37052dab07e6d665bdb33b6a88602731b7bc
7
+ data.tar.gz: 77c030002c12e6f0e3aa7e1abe0b3135bded6d9d39cdf0d4a808e56decb99cc40180dfa44cddbff9b686f169c2ca52ef7826742d1b4560c5615c5946291ef023
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .ruby-version
@@ -2,6 +2,7 @@ require 'active_support/core_ext/object/deep_dup'
2
2
 
3
3
  require_relative 'type_converter'
4
4
  require_relative 'extensions'
5
+ require_relative 'deferred_value'
5
6
 
6
7
  class Tainbox::AttributeDefiner
7
8
 
@@ -18,7 +19,8 @@ class Tainbox::AttributeDefiner
18
19
 
19
20
  klass.tainbox_layer.instance_eval do
20
21
  define_method(attribute) do
21
- instance_variable_get(:"@#{attribute}")
22
+ value = instance_variable_get(:"@#{attribute}")
23
+ value.is_a?(Tainbox::DeferredValue) ? instance_exec(&value.proc) : value
22
24
  end
23
25
  end
24
26
  end
@@ -41,7 +43,9 @@ class Tainbox::AttributeDefiner
41
43
  define_method("tainbox_set_default_#{attribute}") do
42
44
  if args.has_key?(:default)
43
45
  tainbox_register_attribute_provided(attribute)
44
- instance_variable_set(:"@#{attribute}", args[:default].deep_dup)
46
+ value = args[:default].deep_dup
47
+ value = Tainbox::DeferredValue.new(value) if value.is_a?(Proc)
48
+ instance_variable_set(:"@#{attribute}", value)
45
49
  end
46
50
  end
47
51
  end
@@ -0,0 +1,8 @@
1
+ class Tainbox::DeferredValue
2
+
3
+ attr_reader :proc
4
+
5
+ def initialize(proc)
6
+ @proc = proc
7
+ end
8
+ end
@@ -14,7 +14,6 @@ module Tainbox::InstanceMethods
14
14
  end.compact.to_h
15
15
  end
16
16
 
17
- # TODO Reset attributes that are missing in parameter hash
18
17
  def attributes=(attributes)
19
18
  attributes = attributes.symbolize_keys
20
19
  self.class.tainbox_attributes.each do |attribute|
@@ -1,3 +1,3 @@
1
1
  module Tainbox
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tainbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Gubitskiy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-26 00:00:00.000000000 Z
11
+ date: 2015-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -81,6 +81,7 @@ files:
81
81
  - lib/tainbox.rb
82
82
  - lib/tainbox/attribute_definer.rb
83
83
  - lib/tainbox/class_methods.rb
84
+ - lib/tainbox/deferred_value.rb
84
85
  - lib/tainbox/extensions.rb
85
86
  - lib/tainbox/instance_methods.rb
86
87
  - lib/tainbox/type_converter.rb