object_struct 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/lib/object_struct/object_struct.rb +2 -1
- data/lib/object_struct/version.rb +22 -0
- data/test/test_object_struct.rb +3 -3
- metadata +4 -3
data/CHANGELOG
CHANGED
@@ -49,7 +49,8 @@ class ObjectStruct < OpenStruct
|
|
49
49
|
plural = options.delete(:plural)
|
50
50
|
property, type = *options.first
|
51
51
|
class_name = plural ? property.to_s.classify : property.to_s.camelize
|
52
|
-
|
52
|
+
klass = (name.split('::')[0..-2]).join('::').constantize rescue Object
|
53
|
+
klass.const_set class_name, Class.new(type)
|
53
54
|
end
|
54
55
|
|
55
56
|
# Create a new ObjectStruct.
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# ---------------------------------------------------------------------------
|
2
|
+
# Copyright 2010, Quid, Inc.
|
3
|
+
#
|
4
|
+
# object_struct is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# object_struct is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with object_struct. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
# ---------------------------------------------------------------------------
|
18
|
+
require 'ostruct'
|
19
|
+
|
20
|
+
class ObjectStruct < OpenStruct
|
21
|
+
VERSION = '0.0.9'
|
22
|
+
end
|
data/test/test_object_struct.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
$:.unshift
|
1
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
2
2
|
|
3
3
|
require 'minitest/autorun'
|
4
4
|
require 'json'
|
@@ -69,12 +69,12 @@ class ObjectStructTest < MiniTest::Unit::TestCase
|
|
69
69
|
refute @widget.has_id?
|
70
70
|
assert @widget.has_text?
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
def test_modulizes_array_class_names
|
74
74
|
obj = {'sub_knobs' => [{'a' => 'a'}, {'b' => 'b'}, {'c' => 'c'}]}
|
75
75
|
knobwizzle = KnobModule::Knobwizzle.convert(obj, 'KnobModule::Knobwizzle')
|
76
76
|
assert knobwizzle.is_a?(KnobModule::Knobwizzle), "Knobwizzle is a #{knobwizzle.class.name}, not a KnobModule::Knobwizzle"
|
77
77
|
assert knobwizzle.sub_knobs.all? {|sk| sk.is_a?(KnobModule::SubKnob)}, "sub_knobs are #{knobwizzle.sub_knobs.first.class.name}, not KnobModule::SubKnobs"
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 9
|
9
|
+
version: 0.0.9
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Quid, Inc.
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-10-
|
17
|
+
date: 2010-10-19 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -54,6 +54,7 @@ extra_rdoc_files: []
|
|
54
54
|
|
55
55
|
files:
|
56
56
|
- lib/object_struct/object_struct.rb
|
57
|
+
- lib/object_struct/version.rb
|
57
58
|
- lib/object_struct.rb
|
58
59
|
- test/test_data.json
|
59
60
|
- test/test_object_struct.rb
|