Sha256: e64deca7d6f8378bbf92d5c93cbb41d24083bdbd8cb7ad25673713394e51ec10

Contents?: true

Size: 565 Bytes

Versions: 4

Compression:

Stored size: 565 Bytes

Contents

# frozen_string_literal: true

require 'ostruct'

module Zenaton
  # :nodoc
  module Refinements
    refine OpenStruct do
      # Convert to a simple hash
      def to_zenaton
        class_name = self.class.name.to_s
        error_message = 'Only named structs are supported'
        raise ArgumentError, error_message if class_name.empty?
        {
          't' => table
        }
      end
    end
  end
end

# Reimplements `json/add/ostruct`
class OpenStruct
  # Parse from simple hash
  def self.from_zenaton(props)
    new(props['t'] || props[:t])
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
zenaton-0.6.0 lib/zenaton/refinements/open_struct.rb
zenaton-0.5.3 lib/zenaton/refinements/open_struct.rb
zenaton-0.5.2 lib/zenaton/refinements/open_struct.rb
zenaton-0.5.1 lib/zenaton/refinements/open_struct.rb