Sha256: 8ca11d8590de772cb3f225187b1a54b2c294fec21762b9f9f1fb68602c9e877c

Contents?: true

Size: 834 Bytes

Versions: 15

Compression:

Stored size: 834 Bytes

Contents

# frozen_string_literal: true

module ROM
  # ROM's open structs are used for relations with empty schemas.
  # Such relations may exist in cases like using raw SQL strings
  # where schema was not explicitly defined using `view` DSL.
  #
  # @api public
  class OpenStruct
    IVAR = -> v { :"@#{v}" }

    # @api private
    def initialize(attributes)
      attributes.each do |key, value|
        instance_variable_set(IVAR[key], value)
      end
    end

    # @api private
    def respond_to_missing?(meth, include_private = false)
      super || instance_variables.include?(IVAR[meth])
    end

    private

    # @api private
    def method_missing(meth, *args, &block)
      ivar = IVAR[meth]

      if instance_variables.include?(ivar)
        instance_variable_get(ivar)
      else
        super
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rom-core-5.3.2 lib/rom/open_struct.rb
rom-core-5.3.1 lib/rom/open_struct.rb
rom-core-5.3.0 lib/rom/open_struct.rb
rom-core-5.2.6 lib/rom/open_struct.rb
rom-core-5.2.5 lib/rom/open_struct.rb
rom-core-5.2.4 lib/rom/open_struct.rb
rom-core-5.2.3 lib/rom/open_struct.rb
rom-core-5.2.2 lib/rom/open_struct.rb
rom-core-5.2.1 lib/rom/open_struct.rb
rom-core-5.1.2 lib/rom/open_struct.rb
rom-core-5.1.1 lib/rom/open_struct.rb
rom-core-5.1.0 lib/rom/open_struct.rb
rom-core-5.0.2 lib/rom/open_struct.rb
rom-core-5.0.1 lib/rom/open_struct.rb
rom-core-5.0.0 lib/rom/open_struct.rb