ducktape 0.5.0 → 0.5.1

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: c0f795c6666e9a4c52a4bada0c0cb9f523c6bc8b
4
- data.tar.gz: 60d1edc8db2aa8c1334d6d0a1a8a4fdaabacc634
3
+ metadata.gz: d8a085735246f605392018ae227b1ff561bb2a12
4
+ data.tar.gz: 2d3baf29ccdb08ac0728b3cf34b5e602a7cb6e94
5
5
  SHA512:
6
- metadata.gz: 6544f7a65a030f457598adacd40e2209f645d518d6905c119fafe1fe6160599bc7176c2008811e3a12d8840327622981a7e269274a794245a879844cb82aef07
7
- data.tar.gz: 12b3a55f99fbeac0c386fa7ede356c5744ecf02d83bc64f0734f768e427e800f84e7cb49af02aa2f2005673314e79b592d375c4af21f02f3e0671fbfeec3cab5
6
+ metadata.gz: 1c74d85e393cf8a48fcf2f3596f4cca53f4c0d3d35fdb948a1117037080db06f429133f2b5241f95ae1736b74a0282a5221ec0c43a3183a1a8418e4509c90577
7
+ data.tar.gz: 65367871b957ae760debacf750b2b3702c56dc7432b521d91efc4ad606e9f68c931ce59745ceccad3430ab0dd31f55ba94b9887d76c110c7ef28a032adec3d45
@@ -76,7 +76,7 @@ module Ducktape
76
76
  end
77
77
 
78
78
  def bind(attr_name, *args)
79
- send "#{attr_name}=", BindingSource.new(*args)
79
+ BindingSource.new(*args).tap { |source| send "#{attr_name}=", source }
80
80
  end
81
81
 
82
82
  def bindable_attr?(attr_name)
@@ -12,16 +12,16 @@ module Ducktape
12
12
  options.keys.reject { |k| VALID_OPTIONS.member?(k) }.
13
13
  each { |k| $stderr.puts "WARNING: invalid option #{k.inspect} for #{name.inspect} attribute. Will be ignored." }
14
14
 
15
- if name.is_a?(BindableAttributeMetadata)
16
- @name = name.name
17
- options = name.send(:as_options).merge!(options)
18
- else
19
- @name = name
20
- end
15
+ @name = if name.is_a?(BindableAttributeMetadata)
16
+ options = name.send(:as_options).merge!(options)
17
+ name.name
18
+ else
19
+ name
20
+ end
21
21
 
22
22
  @default = options[:default]
23
23
  @validation = validation(*options[:validate])
24
- @coercion = options[:coerce] || ->(_owner, value) { value }
24
+ @coercion = options[:coerce]
25
25
  @access = options[:access] || :both
26
26
  @getter = options[:getter]
27
27
  @setter = options[:setter]
@@ -59,8 +59,9 @@ module Ducktape
59
59
  raise InvalidAttributeValueError.new(@name, value) unless valid?(value)
60
60
  end
61
61
 
62
- def coercion(&block)
63
- @coercion = block
62
+ def coercion(proc_obj = nil, &block)
63
+ raise ArgumentError, 'Expected only a parameter or a block, but both were passed.' if proc_obj && block
64
+ @coercion = block || proc_obj
64
65
  end
65
66
 
66
67
  def coerce(owner, value)
@@ -68,7 +69,7 @@ module Ducktape
68
69
  end
69
70
 
70
71
  def self.register_validator(validator_class)
71
- @validators << validator_class
72
+ @validators.unshift validator_class
72
73
  end
73
74
 
74
75
  private
@@ -1,9 +1,10 @@
1
1
  module Ducktape
2
2
  module Hookable
3
3
  def self.included(base)
4
+ base.extend ClassMethods
5
+
4
6
  if base.is_a?(Class)
5
7
  base.include InstanceMethods
6
- base.extend ClassMethods
7
8
  base.def_hook(:on_changed) unless base.method_defined?(:on_changed)
8
9
  return
9
10
  end
@@ -90,12 +91,12 @@ module Ducktape
90
91
  define_method(original_method.name) do |*args, &block|
91
92
  bound_method = original_method.bind(self)
92
93
  result = bound_method.(*args, &block)
93
- params = OpenStruct.new(args: args, result: result)
94
+ params = OpenStruct.new(args: args, method: original_method.name, result: result)
94
95
  call_name = "call_#{ type }s"
95
- result = send(call_name, hook_name, original_method.name, params)
96
- unless result && type == :handler
96
+ hook_result = send(call_name, hook_name, self, params)
97
+ unless hook_result && type == :handler
97
98
  # invoke if previous call is false or nil
98
- send call_name, :on_changed, original_method.name, params
99
+ send call_name, :on_changed, self, params
99
100
  end
100
101
  result
101
102
  end
@@ -3,5 +3,5 @@
3
3
  # which should have been represented by a major version number increase.
4
4
 
5
5
  module Ducktape
6
- VERSION = '0.5.0'.freeze
6
+ VERSION = '0.5.1'.freeze
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ducktape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - SilverPhoenix99
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-22 00:00:00.000000000 Z
12
+ date: 2015-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: facets
@@ -110,7 +110,7 @@ post_install_message: |
110
110
  Thank you for choosing Ducktape.
111
111
 
112
112
  ==========================================================================
113
- 0.5.0 Changes:
113
+ 0.5.1 Changes:
114
114
  - Added Bindable::bind method to wrap BindingSource construction.
115
115
  - Added support for Range validation in bindable attributes.
116
116
  - Internal refactorings.