blobject 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/blobject.rb +11 -9
- data/lib/blobject/version.rb +2 -2
- metadata +1 -1
data/lib/blobject.rb
CHANGED
@@ -2,14 +2,14 @@ Dir["#{File.dirname __FILE__}/blobject/*.rb"].each {|file| require "#{file}" }
|
|
2
2
|
|
3
3
|
def blobject *parameters, &block
|
4
4
|
Blobject.new *parameters, &block
|
5
|
-
end
|
5
|
+
end
|
6
6
|
|
7
7
|
# similar to OpenStruct
|
8
8
|
# b.foo.bar = 8 automatically creates a blobject called "foo" on "b"
|
9
9
|
# to check whether a variable is defined use the '?' syntax i.e: b.is_it_here? => nil, b.foo? == b.foo
|
10
10
|
# calling an unassigned member returns a new blobject unless the blobject is frozen
|
11
11
|
# a frozen blobject cannot be assigned new members or populated from a hash
|
12
|
-
# does no cycle checking, intended for use in serialization
|
12
|
+
# does no cycle checking, intended for use in serialization
|
13
13
|
class Blobject
|
14
14
|
class AssignToFrozenBlobjectException < Exception; end
|
15
15
|
|
@@ -49,6 +49,8 @@ public
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def method_missing(sym, *args, &block)
|
52
|
+
# fixes for ruby 1.9.2, otherwise blobjects can't be used in arrays that may have the flatten method called
|
53
|
+
super if [:to_ary].include? sym
|
52
54
|
|
53
55
|
str = sym.to_s
|
54
56
|
|
@@ -61,7 +63,7 @@ public
|
|
61
63
|
raise AssignToFrozenBlobjectException if @blobject_frozen
|
62
64
|
@values[assignment.to_s] = args[0]
|
63
65
|
else
|
64
|
-
#
|
66
|
+
#return the value or a new blobject
|
65
67
|
value = @values[str]
|
66
68
|
|
67
69
|
return value unless value.nil?
|
@@ -103,7 +105,7 @@ public
|
|
103
105
|
h
|
104
106
|
end
|
105
107
|
|
106
|
-
#
|
108
|
+
#builds a hash for json conversion
|
107
109
|
def as_json *ps
|
108
110
|
to_hash
|
109
111
|
end
|
@@ -159,9 +161,9 @@ public
|
|
159
161
|
|
160
162
|
def empty?
|
161
163
|
@values.empty? || @values.values.empty? || !@values.values.any? do |v|
|
162
|
-
#
|
163
|
-
#
|
164
|
-
#
|
164
|
+
#if the value is a Blobject, Hash or Array return
|
165
|
+
#true if it is not empty.
|
166
|
+
#else just return true, the value is regarded as not empty.
|
165
167
|
if [Blobject, Array, Hash].include?(v.class)
|
166
168
|
!v.empty?
|
167
169
|
else
|
@@ -169,5 +171,5 @@ public
|
|
169
171
|
end
|
170
172
|
end
|
171
173
|
end
|
172
|
-
|
173
|
-
end
|
174
|
+
|
175
|
+
end
|
data/lib/blobject/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.1.
|
1
|
+
class Blobject
|
2
|
+
VERSION = "0.1.3"
|
3
3
|
end
|