ducktape 0.0.1 → 0.0.3
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.
- data/lib/ducktape/bindable.rb +21 -5
- metadata +3 -3
data/lib/ducktape/bindable.rb
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
module Ducktape
|
2
|
+
class AttributeNotDefinedError < StandardError
|
3
|
+
def initialize(klass, name)
|
4
|
+
super("attribute #{name.to_s.inspect} not defined for class #{klass}")
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
2
8
|
module Bindable
|
3
9
|
module ClassMethods
|
4
10
|
def inherited(child)
|
@@ -9,9 +15,9 @@ module Ducktape
|
|
9
15
|
def bindable(name, options = {})
|
10
16
|
name = name.to_s
|
11
17
|
m = BindableAttributeMetadata.new(metadata(name) || name, options)
|
12
|
-
@bindings_metadata[name
|
13
|
-
define_method name, ->{
|
14
|
-
define_method "#{name}=", ->(value){
|
18
|
+
@bindings_metadata[name] = m
|
19
|
+
define_method name, ->() { get_value(name) } unless options[:access] == :writeonly
|
20
|
+
define_method "#{name}=", ->(value) { set_value(name, value) } unless options[:access] == :readonly
|
15
21
|
nil
|
16
22
|
end
|
17
23
|
|
@@ -47,7 +53,7 @@ module Ducktape
|
|
47
53
|
|
48
54
|
def on_changed(attr_name, &block)
|
49
55
|
return nil unless block
|
50
|
-
get_bindable_attr(attr_name.to_s).
|
56
|
+
get_bindable_attr(attr_name.to_s).on_changed(&block)
|
51
57
|
block
|
52
58
|
end
|
53
59
|
|
@@ -57,13 +63,23 @@ module Ducktape
|
|
57
63
|
block
|
58
64
|
end
|
59
65
|
|
66
|
+
protected
|
67
|
+
def get_value(attr_name)
|
68
|
+
get_bindable_attr(attr_name.to_s).value
|
69
|
+
end
|
70
|
+
|
71
|
+
def set_value(attr_name, value)
|
72
|
+
get_bindable_attr(attr_name.to_s).value = value
|
73
|
+
end
|
74
|
+
|
60
75
|
private
|
61
76
|
def bindable_attrs
|
62
77
|
@bindable_attrs ||= {}
|
63
78
|
end
|
64
79
|
|
65
80
|
def get_bindable_attr(name)
|
66
|
-
|
81
|
+
raise AttributeNotDefinedError.new(self.class, name.to_s) unless metadata(name)
|
82
|
+
bindable_attrs[name.to_s] ||= BindableAttribute.new(self, name)
|
67
83
|
end
|
68
84
|
end
|
69
85
|
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.0.
|
4
|
+
version: 0.0.3
|
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-04-
|
13
|
+
date: 2012-04-30 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: Truly outrageous bindable attributes
|
16
16
|
email:
|
@@ -46,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
46
|
version: '0'
|
47
47
|
requirements: []
|
48
48
|
rubyforge_project:
|
49
|
-
rubygems_version: 1.8.
|
49
|
+
rubygems_version: 1.8.24
|
50
50
|
signing_key:
|
51
51
|
specification_version: 3
|
52
52
|
summary: Truly outrageous bindable attributes
|