class SpaceObject::Base
Public Instance Methods
[](key)
click to toggle source
Calls superclass method
# File lib/space_object/base.rb, line 6 def [](key) key = convert_key!(key) unless key[' '] super(key) else first_key = key[/^[^ ]+/] value = self[first_key] return nil if hash.nil? rest_keys = key[(first_key.length + 1)..-1] value[rest_keys] end end
[]=(key, value)
click to toggle source
Calls superclass method
# File lib/space_object/base.rb, line 20 def []=(key, value) key = convert_key!(key) unless key[' '] super(key, convert_value!(value)) else first_key = key[/^[^ ]+/] value = (self[first_key] ||= self.class.new) value[(first_key.length + 1)..-1] = value end end
Also aliased as: store
default(key = nil)
click to toggle source
Calls superclass method
# File lib/space_object/base.rb, line 33 def default(key = nil) super(key ? convert_key!(key) : nil) end
default=(val)
click to toggle source
Calls superclass method
# File lib/space_object/base.rb, line 37 def default=(val) super(key ? convert_key!(key) : nil) end
fetch(key, *extras)
click to toggle source
Calls superclass method
# File lib/space_object/base.rb, line 41 def fetch(key, *extras) key = convert_key!(key) first_key = key[/^[^ ]+/] value = self[first_key] if key[' '].nil? || hash.nil? super(key, *extras) else value.fetch(first_key, *extras) end end
Protected Instance Methods
convert_key(key)
click to toggle source
# File lib/space_object/base.rb, line 54 def convert_key(key) key.to_nested_space_key end
convert_key!(key)
click to toggle source
# File lib/space_object/base.rb, line 58 def convert_key!(key) raise(ArgumentError, "#{key.class} cannot be stored as a key in a #{self.class}") unless key.respond_to?(:to_nested_space_key) convert_key(key) end
convert_value(val)
click to toggle source
# File lib/space_object/base.rb, line 63 def convert_value(val) val.to_space_value end
convert_value!(val)
click to toggle source
# File lib/space_object/base.rb, line 67 def convert_value!(val) raise(ArgumentError, "#{val.class} cannot be stored as a key in a #{self.class}") unless val.respond_to?(:to_space_value) convert_value(val) end