Class: Ohm::Types::Serialized

Inherits:
Base
  • Object
show all
Defined in:
lib/ohm/contrib/typecast.rb

Direct Known Subclasses

Array, Hash

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

[], delegate_to, empty

Constructor Details

#initialize(raw) ⇒ Serialized

Returns a new instance of Serialized.



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/ohm/contrib/typecast.rb', line 163

def initialize(raw)
  @object = case raw
  when self.class::RAW
    raw
  when ::String
    begin
      ::JSON.parse(raw)
    rescue ::JSON::ParserError
      raw
    end
  when self.class
    raw.object
  else
    ::Kernel.raise ::TypeError,
      "%s does not accept %s" % [self.class, raw.inspect]
  end
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



161
162
163
# File 'lib/ohm/contrib/typecast.rb', line 161

def object
  @object
end

Instance Method Details

#==(other) ⇒ Object



181
182
183
# File 'lib/ohm/contrib/typecast.rb', line 181

def ==(other)
  object == other
end

#respond_to?(method) ⇒ Boolean

Returns:



190
191
192
# File 'lib/ohm/contrib/typecast.rb', line 190

def respond_to?(method)
  object.respond_to?(method)
end

#to_sObject Also known as: inspect



185
186
187
# File 'lib/ohm/contrib/typecast.rb', line 185

def to_s
  object.to_json
end

#typeObject



194
195
196
# File 'lib/ohm/contrib/typecast.rb', line 194

def type
  self.class::RAW
end