aetherical_utils 0.0.2 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/lib/aetherical_utils/attribute.rb +38 -31
- data/lib/aetherical_utils/version.rb +1 -1
- metadata +2 -2
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
@@ -8,40 +8,47 @@
|
|
8
8
|
|
9
9
|
module AethericalUtils
|
10
10
|
module Attribute
|
11
|
-
# Attribute is a method of declaring default values for a property.
|
12
|
-
# These default values may be either an explicit value, such as 1,
|
13
|
-
# or "dog", or they may be a block _which is evaluated at runtime_.
|
14
|
-
# As such, the block could return different values each time it is
|
15
|
-
# invoked.
|
16
|
-
#
|
17
|
-
# If the attribute is a boolean, denoted by '?', such as
|
18
|
-
# 'billable?', then the library will correctly create 'billable?'
|
19
|
-
# and 'billable=' methods.
|
20
|
-
#
|
21
|
-
# *Important*: Since the instance variable ('@billable') may not be
|
22
|
-
# defined or the attribute may represent the value returned by a
|
23
|
-
# block, it is important to access the attribute via the method
|
24
|
-
# ('billable?') as opposed to the instance variable name
|
25
|
-
# ('@billable').
|
26
11
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
12
|
+
def self.included(base)
|
13
|
+
base.extend(ClassMethods)
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
# Attribute is a method of declaring default values for a property.
|
18
|
+
# These default values may be either an explicit value, such as 1,
|
19
|
+
# or "dog", or they may be a block _which is evaluated at runtime_.
|
20
|
+
# As such, the block could return different values each time it is
|
21
|
+
# invoked.
|
22
|
+
#
|
23
|
+
# If the attribute is a boolean, denoted by '?', such as
|
24
|
+
# 'billable?', then the library will correctly create 'billable?'
|
25
|
+
# and 'billable=' methods.
|
26
|
+
#
|
27
|
+
# *Important*: Since the instance variable ('@billable') may not be
|
28
|
+
# defined or the attribute may represent the value returned by a
|
29
|
+
# block, it is important to access the attribute via the method
|
30
|
+
# ('billable?') as opposed to the instance variable name
|
31
|
+
# ('@billable').
|
32
|
+
|
33
|
+
|
34
|
+
def attribute(*arg,&block)
|
35
|
+
(name, default) = arg
|
36
|
+
short_name = name.to_s.sub(/\?/,"")
|
37
|
+
self.send(:define_method, name) {
|
38
|
+
if instance_variables.include? "@#{short_name}"
|
39
|
+
self.instance_eval "@#{short_name}"
|
37
40
|
else
|
38
|
-
|
41
|
+
if block_given?
|
42
|
+
instance_eval &block
|
43
|
+
else
|
44
|
+
default
|
45
|
+
end
|
39
46
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
47
|
+
}
|
48
|
+
self.send(:define_method, "#{short_name}="){ |value|
|
49
|
+
self.instance_eval "@#{short_name} = value"
|
50
|
+
}
|
51
|
+
end
|
45
52
|
end
|
46
53
|
end
|
47
54
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aetherical_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Williams
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
DG139ofzQTE=
|
31
31
|
-----END CERTIFICATE-----
|
32
32
|
|
33
|
-
date: 2008-06-
|
33
|
+
date: 2008-06-19 00:00:00 -04:00
|
34
34
|
default_executable:
|
35
35
|
dependencies: []
|
36
36
|
|
metadata.gz.sig
CHANGED
Binary file
|