woyo-world 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/woyo/world/actions.rb +24 -0
- data/lib/woyo/world/attributes.rb +105 -154
- data/lib/woyo/world/character.rb +4 -1
- data/lib/woyo/world/{dsl.rb → evaluate.rb} +1 -2
- data/lib/woyo/world/group.rb +21 -6
- data/lib/woyo/world/item.rb +26 -0
- data/lib/woyo/world/location.rb +5 -3
- data/lib/woyo/world/version.rb +1 -1
- data/lib/woyo/world/way.rb +5 -4
- data/lib/woyo/world/world.rb +7 -3
- data/lib/woyo/world/world_object.rb +8 -4
- data/rspec.json +1 -0
- data/spec/spec_doc.haml +68 -0
- data/spec/spec_doc_formatter.rb +89 -0
- data/spec/spec_helper.rb +115 -0
- data/spec/woyo/dsl/dsl_spec.rb +367 -0
- data/spec/woyo/world/actions_spec.rb +71 -0
- data/spec/woyo/world/attributes_spec.rb +300 -382
- data/spec/woyo/world/character_spec.rb +30 -28
- data/spec/woyo/world/evaluate_spec.rb +75 -0
- data/spec/woyo/world/group_spec.rb +45 -44
- data/spec/woyo/world/item_spec.rb +46 -0
- data/spec/woyo/world/location_spec.rb +48 -32
- data/spec/woyo/world/way_spec.rb +54 -45
- data/spec/woyo/world/world_object_spec.rb +48 -6
- data/spec/woyo/world/world_spec.rb +15 -7
- data/todo.txt +2 -2
- data/woyo-world.gemspec +3 -2
- metadata +38 -11
- data/spec/woyo/world/dsl_spec.rb +0 -74
- data/spec/woyo/world/language_spec.rb +0 -350
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c1c941040eef171a088f6ee54a6416f55eb46ba
|
4
|
+
data.tar.gz: 881d8203e4a35f0965a191cf47f6706cc18ee8ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb02560ec28f3cc4c370406424518b5c9246a69c34225903e5a17abde911be52231a9cc1670ffc37036c1da788492b39d78b141a00aa17d1f1776996b748bf84
|
7
|
+
data.tar.gz: 958c5a2eacdf5be0ef4e3e3a0fd0ba420040bc8842efebdf18d03a5e427cfbf5bfa05eac7eac2fb4b12e84bb653157cc11f8aaee8998a4d6c946c714bea429cd
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'attributes'
|
2
|
+
|
3
|
+
module Woyo
|
4
|
+
|
5
|
+
module Actions
|
6
|
+
|
7
|
+
include Attributes
|
8
|
+
|
9
|
+
def action *acts, &block
|
10
|
+
send :_attributes, acts, ivn: '@actions', &block
|
11
|
+
end
|
12
|
+
|
13
|
+
def actions *acts, &block
|
14
|
+
send :_attributes, acts, ivn: '@actions', &block
|
15
|
+
end
|
16
|
+
|
17
|
+
def do act
|
18
|
+
send act
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
@@ -8,195 +8,146 @@ module Woyo
|
|
8
8
|
|
9
9
|
module Attributes
|
10
10
|
|
11
|
-
def
|
12
|
-
|
11
|
+
def attribute *attrs, &block
|
12
|
+
send :_attributes, attrs, ivn: '@attributes', &block
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
15
|
+
def attributes *attrs, &block
|
16
|
+
send :_attributes, attrs, ivn: '@attributes', &block
|
17
17
|
end
|
18
|
-
|
19
|
-
def initialize *args
|
20
|
-
initialize_attributes
|
21
|
-
initialize_groups
|
22
|
-
initialize_boolean_groups
|
23
|
-
initialize_is_overrides
|
24
|
-
#super # we'll need this if we prepend Attributes again
|
25
|
-
end
|
26
|
-
|
27
|
-
module ClassMethods
|
28
18
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
define_attr? attr
|
35
|
-
define_attr! attr
|
36
|
-
end
|
19
|
+
def _attributes attrs, ivn:, &block
|
20
|
+
if instance_variable_defined? ivn
|
21
|
+
ivar = instance_variable_get ivn
|
22
|
+
else
|
23
|
+
ivar = instance_variable_set ivn, Woyo::Attributes::AttributesHash.new
|
37
24
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
25
|
+
return ivar if attrs.empty?
|
26
|
+
attrs.each do |attr|
|
27
|
+
case
|
28
|
+
when attr.kind_of?( Hash )
|
29
|
+
attr.each do |attr_sym,default|
|
30
|
+
define_attr_methods attr_sym, default, ivn: ivn
|
31
|
+
ivar[attr_sym] = send "#{attr_sym}_default"
|
43
32
|
end
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def define_attr attr
|
55
|
-
define_method attr do |arg = nil|
|
56
|
-
return attributes[attr] = arg unless arg.nil?
|
57
|
-
return attributes[attr] unless attributes[attr].kind_of? Hash
|
58
|
-
true_attribute_match = attributes[attr].detect { |name,value| attributes[name] == true }
|
59
|
-
return true_attribute_match[1] if true_attribute_match
|
60
|
-
attributes[attr]
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def define_attr? attr
|
65
|
-
define_method "#{attr}?" do
|
66
|
-
( send attr ) ? true : false
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def define_attr! attr
|
71
|
-
define_method "#{attr}!" do
|
72
|
-
send "#{attr}=", true
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def attributes *attrs
|
77
|
-
@attributes ||= []
|
78
|
-
return @attributes if attrs.empty?
|
79
|
-
attrs.each do |attr|
|
80
|
-
if attr.kind_of? Hash
|
81
|
-
attr.each do |attr_sym,default_value|
|
82
|
-
@attributes << attr_sym unless @attributes.include? attr_sym
|
83
|
-
define_attr_methods attr_sym, default_value
|
84
|
-
end
|
85
|
-
else
|
86
|
-
unless @attributes.include? attr
|
87
|
-
@attributes << attr
|
88
|
-
define_attr_methods attr
|
89
|
-
end
|
33
|
+
when block
|
34
|
+
define_attr_methods attr, block, ivn: ivn
|
35
|
+
ivar[attr] = send "#{attr}_default"
|
36
|
+
else
|
37
|
+
unless ivar.include? attr
|
38
|
+
define_attr_methods attr, ivn: ivn
|
39
|
+
ivar[attr] = nil
|
90
40
|
end
|
91
41
|
end
|
92
42
|
end
|
43
|
+
end
|
93
44
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
45
|
+
def define_attr_methods( attr, default = nil, ivn: )
|
46
|
+
define_attr_default attr, default
|
47
|
+
define_attr_equals attr, ivn: ivn
|
48
|
+
define_attr attr, ivn: ivn
|
49
|
+
if default == true || default == false # boolean convenience methods
|
50
|
+
define_attr? attr
|
51
|
+
define_attr! attr
|
100
52
|
end
|
53
|
+
end
|
101
54
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
self.attributes *attrs
|
106
|
-
attrs.each do |attr|
|
107
|
-
if attr.kind_of? Hash
|
108
|
-
attr.each do |attr_sym,default_value|
|
109
|
-
group << attr_sym
|
110
|
-
end
|
111
|
-
else
|
112
|
-
group << attr
|
113
|
-
end
|
114
|
-
end
|
115
|
-
define_method sym do
|
116
|
-
groups[sym]
|
117
|
-
end
|
118
|
-
group
|
55
|
+
def define_attr_default attr, default
|
56
|
+
define_singleton_method "#{attr}_default" do
|
57
|
+
default
|
119
58
|
end
|
59
|
+
end
|
120
60
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
def group! sym, *attrs
|
126
|
-
@boolean_groups ||= {}
|
127
|
-
group = @boolean_groups[sym] ? @boolean_groups[sym] : ( @boolean_groups[sym] = [] )
|
128
|
-
self.attributes *attrs
|
129
|
-
attrs.each do |attr|
|
130
|
-
define_attr? attr
|
131
|
-
define_attr! attr
|
132
|
-
if attr.kind_of? Hash
|
133
|
-
attr.each do |attr_sym,default_value|
|
134
|
-
group << attr_sym
|
135
|
-
end
|
136
|
-
else
|
137
|
-
group << attr
|
138
|
-
end
|
139
|
-
end
|
140
|
-
define_method sym do
|
141
|
-
boolean_groups[sym]
|
142
|
-
end
|
143
|
-
group
|
61
|
+
def define_attr_equals( attr, ivn: )
|
62
|
+
define_singleton_method "#{attr}=" do |arg|
|
63
|
+
ivar = instance_variable_get ivn
|
64
|
+
ivar[attr] = arg
|
144
65
|
end
|
66
|
+
end
|
145
67
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
68
|
+
def define_attr( attr, ivn: )
|
69
|
+
define_singleton_method attr do |arg = nil|
|
70
|
+
ivar = instance_variable_get ivn
|
71
|
+
return ivar[attr] = arg unless arg.nil?
|
72
|
+
case
|
73
|
+
when ivar[attr].kind_of?( Hash )
|
74
|
+
true_attribute_match = ivar[attr].detect { |name,value| ivar[name] == true }
|
75
|
+
return true_attribute_match[1] if true_attribute_match
|
76
|
+
ivar[attr]
|
77
|
+
when ivar[attr].respond_to?( :call )
|
78
|
+
return ivar[attr].arity == 0 ? ivar[attr].call : ivar[attr].call(self)
|
79
|
+
else
|
80
|
+
ivar[attr]
|
151
81
|
end
|
152
82
|
end
|
83
|
+
end
|
153
84
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
end # module ClassMethods
|
159
|
-
|
160
|
-
def initialize_attributes
|
161
|
-
@attributes = self.class.attributes.each_with_object(Woyo::Attributes::AttributesHash.new) do |attr,hash|
|
162
|
-
hash[attr] = send "#{attr}_default"
|
85
|
+
def define_attr? attr
|
86
|
+
define_singleton_method "#{attr}?" do
|
87
|
+
( send attr ) ? true : false
|
163
88
|
end
|
164
89
|
end
|
165
90
|
|
166
|
-
def
|
167
|
-
|
168
|
-
|
169
|
-
|
91
|
+
def define_attr! attr
|
92
|
+
define_singleton_method "#{attr}!" do
|
93
|
+
send "#{attr}=", true
|
94
|
+
end
|
170
95
|
end
|
171
96
|
|
172
|
-
def
|
173
|
-
|
174
|
-
self.class.boolean_groups.each { |sym,members| @boolean_groups[sym] = Woyo::Attributes::BooleanGroup.new @attributes, *members }
|
175
|
-
@boolean_groups
|
97
|
+
def is? attr
|
98
|
+
send "#{attr}?"
|
176
99
|
end
|
177
100
|
|
178
|
-
def
|
179
|
-
|
101
|
+
def is attr
|
102
|
+
send "#{attr}=", true
|
180
103
|
end
|
181
104
|
|
182
|
-
def attributes
|
183
|
-
@attributes
|
184
|
-
end
|
185
|
-
|
186
105
|
def groups
|
187
106
|
@groups
|
188
107
|
end
|
189
108
|
|
190
|
-
def
|
191
|
-
@
|
109
|
+
def group sym, *attrs
|
110
|
+
@groups ||= {}
|
111
|
+
grp = @groups[sym] ? @groups[sym] : ( @groups[sym] = Woyo::Attributes::Group.new attributes )
|
112
|
+
attributes *attrs
|
113
|
+
attrs.each do |attr|
|
114
|
+
if attr.kind_of? Hash
|
115
|
+
attr.each do |attr_sym,default_value|
|
116
|
+
grp << attr_sym
|
117
|
+
end
|
118
|
+
else
|
119
|
+
grp << attr
|
120
|
+
end
|
121
|
+
end
|
122
|
+
define_singleton_method sym do
|
123
|
+
@groups[sym]
|
124
|
+
end
|
125
|
+
grp
|
192
126
|
end
|
193
127
|
|
194
|
-
def
|
195
|
-
|
128
|
+
def exclusions
|
129
|
+
@exclusions
|
196
130
|
end
|
197
|
-
|
198
|
-
def
|
199
|
-
|
131
|
+
|
132
|
+
def exclusion sym, *attrs
|
133
|
+
@exclusions ||= {}
|
134
|
+
exc = @exclusions[sym] ? @exclusions[sym] : ( @exclusions[sym] = Woyo::Attributes::Exclusion.new attributes )
|
135
|
+
attributes *attrs
|
136
|
+
attrs.each do |attr|
|
137
|
+
define_attr? attr
|
138
|
+
define_attr! attr
|
139
|
+
if attr.kind_of? Hash
|
140
|
+
attr.each do |attr_sym,default_value|
|
141
|
+
exc << attr_sym
|
142
|
+
end
|
143
|
+
else
|
144
|
+
exc << attr
|
145
|
+
end
|
146
|
+
end
|
147
|
+
define_singleton_method sym do
|
148
|
+
@exclusions[sym]
|
149
|
+
end
|
150
|
+
exc
|
200
151
|
end
|
201
152
|
|
202
153
|
end
|
data/lib/woyo/world/character.rb
CHANGED
@@ -4,7 +4,10 @@ module Woyo
|
|
4
4
|
|
5
5
|
class Character < WorldObject
|
6
6
|
|
7
|
-
|
7
|
+
def initialize_object
|
8
|
+
super
|
9
|
+
attributes :description, name: lambda { |this| this.id.to_s.capitalize }
|
10
|
+
end
|
8
11
|
|
9
12
|
def world
|
10
13
|
@world ||= context if context.is_a? World
|
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
module Woyo
|
3
3
|
|
4
|
-
module
|
4
|
+
module Evaluate
|
5
5
|
|
6
6
|
def evaluate &block
|
7
7
|
(block.arity < 1 ? (instance_eval &block) : block.call(self)) if block_given?
|
@@ -35,7 +35,6 @@ module DSL
|
|
35
35
|
when !#{child} && !known && block_given? then #{child} = self.#{child}s[id] = #{child.capitalize}.new id, context: self, &block
|
36
36
|
when !#{child} && !known && !block_given? then #{child} = self.#{child}s[id] = #{child.capitalize}.new id, context: self
|
37
37
|
end
|
38
|
-
# maybe: god-like lists of everything at world level... would need unique ids... self.world.#{child}s[id] = #{child} if !known && self.world
|
39
38
|
#{child}
|
40
39
|
end
|
41
40
|
|
data/lib/woyo/world/group.rb
CHANGED
@@ -33,7 +33,7 @@ module Attributes
|
|
33
33
|
|
34
34
|
extend Forwardable
|
35
35
|
|
36
|
-
def_delegators :@members, :count
|
36
|
+
def_delegators :@members, :count, :<<
|
37
37
|
def_delegators :@attributes, :[], :[]=
|
38
38
|
|
39
39
|
attr_reader :members, :attributes
|
@@ -53,19 +53,34 @@ module Attributes
|
|
53
53
|
|
54
54
|
end
|
55
55
|
|
56
|
-
class
|
56
|
+
class Exclusion < Group
|
57
57
|
|
58
58
|
attr_reader :default
|
59
59
|
|
60
60
|
def initialize attributes, *members
|
61
61
|
super
|
62
|
-
@
|
63
|
-
|
64
|
-
|
62
|
+
if @members && ! @members.empty?
|
63
|
+
@default = @members.first
|
64
|
+
self[@default] = true
|
65
|
+
@members.each { |member| @attributes.add_attribute_listener member, self }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def << new_member
|
70
|
+
raise "#{new_member} is not an attribute" unless @attributes.names.include? new_member
|
71
|
+
super
|
72
|
+
if @members.count == 1
|
73
|
+
@default = new_member
|
74
|
+
@attributes.set new_member, true
|
75
|
+
else
|
76
|
+
@attributes.set new_member, false
|
77
|
+
end
|
78
|
+
@attributes.add_attribute_listener new_member, self
|
79
|
+
self
|
65
80
|
end
|
66
81
|
|
67
82
|
def []= this_member, value
|
68
|
-
raise
|
83
|
+
raise "#{this_member} is not a member of this group" unless @members.include? this_member
|
69
84
|
super
|
70
85
|
if value #true
|
71
86
|
# sync group members via AttributesHash#set to prevent triggering notify
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'world_object'
|
2
|
+
|
3
|
+
module Woyo
|
4
|
+
|
5
|
+
class Item < WorldObject
|
6
|
+
|
7
|
+
def initialize_object
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def location
|
12
|
+
self.context.instance_of?( Location ) ? self.context : nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def world
|
16
|
+
case
|
17
|
+
when self.context.instance_of?( World ) then self.context
|
18
|
+
when self.context.instance_of?( Location) then self.context.world
|
19
|
+
else nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
data/lib/woyo/world/location.rb
CHANGED
@@ -4,12 +4,14 @@ module Woyo
|
|
4
4
|
|
5
5
|
class Location < WorldObject
|
6
6
|
|
7
|
-
|
7
|
+
children :way, :item
|
8
8
|
|
9
|
-
|
9
|
+
def initialize_object
|
10
|
+
super
|
11
|
+
end
|
10
12
|
|
11
13
|
def world
|
12
|
-
|
14
|
+
context
|
13
15
|
end
|
14
16
|
|
15
17
|
def here
|