Sha256: 08eda080fdb4326027578d92c6e908e64e002993e3dfa99001a209d463f6f906

Contents?: true

Size: 797 Bytes

Versions: 32

Compression:

Stored size: 797 Bytes

Contents

#frozen_string_literal: false
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
  require 'json'
end
require 'ostruct'

class OpenStruct

  # Deserializes JSON string by constructing new Struct object with values
  # <tt>t</tt> serialized by <tt>to_json</tt>.
  def self.json_create(object)
    new(object['t'] || object[:t])
  end

  # Returns a hash, that will be turned into a JSON object and represent this
  # object.
  def as_json(*)
    klass = self.class.name
    klass.to_s.empty? and raise JSON::JSONError, "Only named structs are supported!"
    {
      JSON.create_id => klass,
      't'            => table,
    }
  end

  # Stores class name (OpenStruct) with this struct's values <tt>v</tt> as a
  # JSON string.
  def to_json(*args)
    as_json.to_json(*args)
  end
end

Version data entries

32 entries across 29 versions & 12 rubygems

Version Path
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/json-2.1.0/lib/json/add/ostruct.rb
cloudsmith-api-0.30.7 vendor/bundle/ruby/2.3.0/gems/json-2.1.0/lib/json/add/ostruct.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/json-2.1.0/lib/json/add/ostruct.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/json-2.1.0/lib/json/add/ostruct.rb
cloudsmith-api-0.21.4 vendor/bundle/ruby/2.3.0/gems/json-2.1.0/lib/json/add/ostruct.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/json-2.1.0/lib/json/add/ostruct.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/json-2.1.0/lib/json/add/ostruct.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/json-2.1.0/lib/json/add/ostruct.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/json-2.1.0/lib/json/add/ostruct.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/json-2.1.0/lib/json/add/ostruct.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/json-2.1.0-java/lib/json/add/ostruct.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/json-2.1.0-java/lib/json/add/ostruct.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/json-2.1.0-java/lib/json/add/ostruct.rb
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/json-2.1.0-java/lib/json/add/ostruct.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/json-2.0.3/lib/json/add/ostruct.rb
tdiary-5.0.5 vendor/bundle/gems/json-2.1.0/lib/json/add/ostruct.rb
tdiary-5.0.5 vendor/bundle/gems/json-2.0.3/lib/json/add/ostruct.rb
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/json-2.1.0/lib/json/add/ostruct.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/json-2.1.0/lib/json/add/ostruct.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/json-2.1.0/lib/json/add/ostruct.rb