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

- (Serialized) initialize(raw)



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/ohm/contrib/typecast.rb', line 139

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

- (Object) object (readonly)

Returns the value of attribute object



137
138
139
# File 'lib/ohm/contrib/typecast.rb', line 137

def object
  @object
end

Instance Method Details

- (Object) ==(other)



157
158
159
# File 'lib/ohm/contrib/typecast.rb', line 157

def ==(other)
  object == other
end

- (Boolean) respond_to?(method)



166
167
168
# File 'lib/ohm/contrib/typecast.rb', line 166

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

- (Object) to_s Also known as: inspect



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

def to_s
  object.to_json
end