class SuperRecursiveOpenStruct

Public Class Methods

new(hash, args = {}) click to toggle source
# File lib/super_recursive_open_struct.rb, line 5
def initialize(hash, args = {})
  @raise_on_missing_methods = args.fetch(:raise_on_missing_methods, true)

  @target = if hash.is_a?(Array)
    hash.map { |item| self.class.new(item) }
  else
    RecursiveOpenStruct.new(hash, recurse_over_arrays: true)
  end

  patch_object(@target) if @raise_on_missing_methods
end

Public Instance Methods

method_missing(method, *args, &block) click to toggle source
Calls superclass method Object#method_missing
# File lib/super_recursive_open_struct.rb, line 17
def method_missing(method, *args, &block)
  if !@raise_on_missing_methods || @target.respond_to?(method)
    @target.__send__(method, *args, &block)
  else
    super
  end
end
respond_to_missing?(method, include_private = false) click to toggle source
# File lib/super_recursive_open_struct.rb, line 25
def respond_to_missing?(method, include_private = false)
  @target.respond_to?(method, include_private)
end
to_json() click to toggle source
# File lib/super_recursive_open_struct.rb, line 29
def to_json
  ActiveSupport::JSON.encode @target
end