construct 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/construct.rb +29 -14
- metadata +2 -2
data/lib/construct.rb
CHANGED
@@ -3,7 +3,7 @@ class Construct
|
|
3
3
|
# Ruby and humans with text editors.
|
4
4
|
|
5
5
|
APP_NAME = 'Construct'
|
6
|
-
APP_VERSION = '0.1.
|
6
|
+
APP_VERSION = '0.1.3'
|
7
7
|
APP_AUTHOR = 'Kyle Kingsbury'
|
8
8
|
APP_EMAIL = 'aphyr@aphyr.com'
|
9
9
|
APP_URL = 'http://aphyr.com'
|
@@ -11,13 +11,6 @@ class Construct
|
|
11
11
|
|
12
12
|
require 'yaml'
|
13
13
|
|
14
|
-
YAML::add_domain_type("aphyr.com,2009", "construct") do |type, val|
|
15
|
-
# Not implemented ;)
|
16
|
-
Construct.load(val)
|
17
|
-
end
|
18
|
-
yaml_as "tag:aphyr.com,2009:construct"
|
19
|
-
yaml_as "tag:yaml.org,2002:map"
|
20
|
-
|
21
14
|
class << self
|
22
15
|
attr_writer :schema
|
23
16
|
end
|
@@ -51,7 +44,8 @@ class Construct
|
|
51
44
|
end
|
52
45
|
|
53
46
|
def ==(other)
|
54
|
-
|
47
|
+
other.respond_to? :schema and other.respond_to? :data and
|
48
|
+
@schema == other.schema and @data == other.data
|
55
49
|
end
|
56
50
|
|
57
51
|
def [](key)
|
@@ -139,13 +133,34 @@ class Construct
|
|
139
133
|
|
140
134
|
# Dumps the data (not the schema!) of this construct to YAML. Keys are
|
141
135
|
# expressed as strings.
|
136
|
+
#
|
137
|
+
# This gets a little complicated.
|
138
|
+
#
|
139
|
+
# If you define a schema where the default is a Construct
|
140
|
+
#
|
141
|
+
# conf.define :sub, :default => Construct
|
142
|
+
#
|
143
|
+
# and then try to write to it:
|
144
|
+
#
|
145
|
+
# conf.sub.opt = 2
|
146
|
+
#
|
147
|
+
# That opt gets stored on the *schema* sub. Everything works fine... except
|
148
|
+
# that when it comes time to serialize there's now *data* buried in the
|
149
|
+
# schema tree. Therefore, we write out schema objects as well when they are
|
150
|
+
# non-empty.
|
142
151
|
def to_yaml(opts = {})
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
152
|
+
hash = {}
|
153
|
+
@schema.each do |key, value|
|
154
|
+
if value[:default].kind_of? Construct
|
155
|
+
hashed = YAML::load(value[:default].to_yaml)
|
156
|
+
next if hashed.empty?
|
157
|
+
hash[key.to_s] = hashed
|
148
158
|
end
|
149
159
|
end
|
160
|
+
|
161
|
+
@data.each do |key, value|
|
162
|
+
hash[key.to_s] = value
|
163
|
+
end
|
164
|
+
hash.to_yaml(opts)
|
150
165
|
end
|
151
166
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: construct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Kingsbury
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-23 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|