Sha256: 21a7ad422fd60dc5829859971afd934f7849a6e37013357c12474d33948fe6de

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

# List of classes to encode mirrors JSON encodable objects in ActiveSupport

require 'time'
require 'space_object/string_encodable'

class Array
  def to_space_object
    Hash[each_with_index.map do |item, index|
      [index, item]
    end].to_space_object
  end

  def to_space_value
    to_space_object
  end
end

class Date
  include SpaceObject::StringEncodable
end

class DateTime
  include SpaceObject::StringEncodable
end

module Enumerable
  def to_space_object
    to_a.to_space_object
  end

  def to_space_value
    to_space_object
  end
end

class FalseClass
  include SpaceObject::StringEncodable
end

class Hash
  def to_space_object
    SpaceObject::Encoder.new(self).encode
  end
end

class NilClass
  include SpaceObject::StringEncodable
end

class Numeric
  include SpaceObject::StringEncodable
end

class Object
  # Highly inspired by ActiveSupport
  def to_space_object
    hash = respond_to?(:to_hash) ? to_hash : insance_values
    hash.to_space_object
  end

  def to_space_value
    to_space_object
  end
end

class Process::Status
  include SpaceObject::StringEncodable
end

class Regexp
  include SpaceObject::StringEncodable
end

class String
  include SpaceObject::StringEncodable
end

class Symbol
  include SpaceObject::StringEncodable
end

class Struct
  # Highly inspired by ActiveSupport
  def to_space_object
    hash = Hash[members.zip(values)]
    hash.to_space_object
  end

  def to_space_value
    to_space_object
  end
end

class Time
  include SpaceObject::StringEncodable
end

class TrueClass
  include SpaceObject::StringEncodable
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
space_object-0.1.4 lib/space_object/core_ext/object/space_object.rb