grammer 0.1.0.edge → 0.1.1.edge
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/grammer/macros.rb +18 -15
- data/lib/grammer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3efaa410d894849bb8745cb2587906913fd0b47
|
4
|
+
data.tar.gz: 95e81e4fa7e1a66543af2250ef52cf93c3ed213a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7aaaa0fd4b5cb468f02125cea29da80db7627714f5efeca3b924aab4b8e15338cdda57f17c2d262c47ad24a199147bb4d666d902e828058b64ce94f3ede1309f
|
7
|
+
data.tar.gz: e02c3fa58f25e98b2303f76d768bcba886ce4b5f776214fbed6e433c6051deed963c029fa5ad1e896f522d4ae6f2c3930444f4c6071640cdfc701c5c77940bfc
|
data/lib/grammer/macros.rb
CHANGED
@@ -9,28 +9,31 @@ module Grammer
|
|
9
9
|
# Defines class macros
|
10
10
|
module Macros
|
11
11
|
def get_or_set_const(module_name)
|
12
|
-
|
13
|
-
|
12
|
+
if const_defined?(module_name)
|
13
|
+
const_get(module_name)
|
14
|
+
else
|
15
|
+
const_set(module_name, Module.new)
|
16
|
+
end
|
14
17
|
end
|
15
18
|
|
16
|
-
def
|
17
|
-
mod = get_or_set_const(:"GammerMod#{object_id}")
|
19
|
+
def define_module_method(mod, method_name, opts)
|
18
20
|
mod.class_eval do
|
19
|
-
target_attribute =
|
21
|
+
target_attribute = opts[:on]
|
20
22
|
define_method(target_attribute) do
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
instance_variable_set(
|
27
|
-
instance_var,
|
28
|
-
Node.new(username, service: options[:service])
|
29
|
-
)
|
23
|
+
instance_variable_name = "@#{target_attribute}"
|
24
|
+
if instance_variable_defined?(instance_variable_name)
|
25
|
+
instance_variable_get(instance_variable_name)
|
26
|
+
else
|
27
|
+
node = Node.new(send(method_name), service: opts[:service])
|
28
|
+
instance_variable_set(instance_variable_name, node)
|
30
29
|
end
|
31
|
-
instance_var_value
|
32
30
|
end
|
33
31
|
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def grammed_by(method_name, opts = {})
|
35
|
+
mod = get_or_set_const(:"GammerMod#{object_id}")
|
36
|
+
define_module_method(mod, method_name, opts)
|
34
37
|
prepend mod
|
35
38
|
end
|
36
39
|
|
data/lib/grammer/version.rb
CHANGED