ducktape 0.3.1 → 0.3.2

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.
@@ -6,14 +6,28 @@ module Ducktape
6
6
  end
7
7
  end
8
8
 
9
+ class InconsistentAccessorError < StandardError
10
+ def initialize(writeonly, name)
11
+ type, accessor = writeonly ? [:Write, :getter] : [:Read, :setter]
12
+ super("#{type} only property with a custom #{accessor}: #{name}")
13
+ end
14
+ end
15
+
9
16
  module Bindable
10
17
  module ClassMethods
11
18
  def bindable(name, options = {})
12
19
  name = name.to_s
20
+ options[:access] ||= :both
13
21
  m = BindableAttributeMetadata.new(metadata(name) || name, options)
14
22
  bindings_metadata[name] = m
15
- define_method name, ->() { get_value(name) } unless options[:access] == :writeonly
16
- define_method "#{name}=", ->(value) { set_value(name, value) } unless options[:access] == :readonly
23
+ raise InconsistentAccessorError.new(true, name) if options[:access] == :writeonly && options[:getter]
24
+ raise InconsistentAccessorError.new(false, name) if options[:access] == :readonly && options[:setter]
25
+
26
+ define_method name, options[:getter] || ->() { get_value(name) } unless options[:access] == :writeonly
27
+
28
+ unless options[:access] == :readonly
29
+ define_method "#{name}=", options[:setter] || ->(value) { set_value(name, value) }
30
+ end
17
31
  nil
18
32
  end
19
33
 
@@ -79,10 +79,10 @@ module Ducktape
79
79
  old_value = @value
80
80
  @value = value
81
81
 
82
- old_value.remove_hook('on_changed', method('hookable_value_changed')) if old_value.respond_to?('on_changed')
83
- @value.on_changed(method('hookable_value_changed')) if @value.respond_to?('on_changed')
82
+ old_value.remove_hook(:on_changed, method(:hookable_value_changed)) if old_value.is_a?(Hookable)
83
+ @value.on_changed(method(:hookable_value_changed)) if @value.is_a?(Hookable)
84
84
 
85
- call_hooks('on_changed', owner, attribute: name.dup, value: @value, old_value: old_value)
85
+ call_hooks(:on_changed, owner, attribute: name.dup, value: @value, old_value: old_value)
86
86
  end
87
87
 
88
88
  propagate_value(exclusions)
@@ -1,9 +1,9 @@
1
1
  module Ducktape
2
2
  class BindableAttributeMetadata
3
3
 
4
- VALID_OPTIONS = [:access, :default, :validate, :coerce].freeze
4
+ VALID_OPTIONS = [:access, :coerce, :default, :getter, :setter, :validate].freeze
5
5
 
6
- attr_reader :name
6
+ attr_reader :name, :access, :getter, :setter
7
7
 
8
8
  def initialize(name, options = {})
9
9
 
@@ -15,11 +15,17 @@ module Ducktape
15
15
  @default = options.has_key?(:default) ? options[:default] : name.instance_variable_get(:@default)
16
16
  @validation = options.has_key?(:validate) ? options[:validate] : name.instance_variable_get(:@validation)
17
17
  @coercion = options.has_key?(:coerce) ? options[:coerce] : name.instance_variable_get(:@coercion)
18
+ @access = options.has_key?(:access) ? options[:access] : name.access
19
+ @getter = options.has_key?(:getter) ? options[:getter] : name.getter
20
+ @setter = options.has_key?(:setter) ? options[:setter] : name.setter
18
21
  else
19
22
  @name = name
20
23
  @default = options[:default]
21
24
  @validation = options[:validate]
22
25
  @coercion = options[:coerce]
26
+ @access = options[:access]
27
+ @getter = options[:getter]
28
+ @setter = options[:setter]
23
29
  end
24
30
 
25
31
  @validation = [*@validation] unless @validation.nil?
data/lib/ducktape.rb CHANGED
@@ -3,7 +3,7 @@ module Ducktape
3
3
  # may represent an incompatible implementation with the previous minor version, which should have been
4
4
  # represented by a major version number increase.
5
5
 
6
- VERSION = '0.3.1'
6
+ VERSION = '0.3.2'
7
7
 
8
8
  camelize = ->(f){ f.gsub(/(^|_)([^_]+)/) { |_| $2.capitalize } }
9
9
 
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.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-12-24 00:00:00.000000000 Z
13
+ date: 2012-12-27 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: Truly outrageous bindable attributes
16
16
  email: