Class: Rookout::Processor::Namespaces::RubyObjectNamespace

Inherits:
Namespace
  • Object
show all
Includes:
RubyObjectSerializer
Defined in:
lib/rookout/processor/namespaces/ruby_object_namespace.rb

Constant Summary

Constants included from RubyObjectSerializer

Rookout::Processor::Namespaces::RubyObjectSerializer::INT32_MAX, Rookout::Processor::Namespaces::RubyObjectSerializer::INT32_MIN, Rookout::Processor::Namespaces::RubyObjectSerializer::INT64_MAX, Rookout::Processor::Namespaces::RubyObjectSerializer::INT64_MIN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RubyObjectSerializer

#create_base_variant, #dump_array, #dump_code_object, #dump_exception, #dump_hash, #dump_integer, #dump_nil, #dump_numeric, #dump_raw_object, #dump_string, #dump_time, #dump_user_class, #unsafe_dump_object

Methods inherited from Namespace

#write_attribute

Constructor Details

#initialize(obj, dump_config = nil) ⇒ RubyObjectNamespace

Returns a new instance of RubyObjectNamespace.



43
44
45
46
47
# File 'lib/rookout/processor/namespaces/ruby_object_namespace.rb', line 43

def initialize obj, dump_config = nil
  super()
  @obj = obj
  @dump_config = dump_config || OBJECT_DUMP_CONFIG_DEFAULT
end

Instance Attribute Details

#dump_configObject (readonly)

Returns the value of attribute dump_config.



50
51
52
# File 'lib/rookout/processor/namespaces/ruby_object_namespace.rb', line 50

def dump_config
  @dump_config
end

#objObject (readonly)

Returns the value of attribute obj.



49
50
51
# File 'lib/rookout/processor/namespaces/ruby_object_namespace.rb', line 49

def obj
  @obj
end

Instance Method Details

#call_method(name, args) ⇒ Object



80
81
82
83
84
85
86
87
88
89
# File 'lib/rookout/processor/namespaces/ruby_object_namespace.rb', line 80

def call_method name, args
  case name
  when "type"
    RubyObjectNamespace.new @obj.class.to_s
  when "size"
    RubyObjectNamespace.new @obj.length
  else
    super
  end
end

#dump(log_object_errors) ⇒ Object



91
92
93
# File 'lib/rookout/processor/namespaces/ruby_object_namespace.rb', line 91

def dump log_object_errors
  dump_raw_object @obj, 0, @dump_config, log_object_errors
end

#read_attribute(name) ⇒ Object

Raises:

  • (RookAttributeNotFound)


63
64
65
66
67
# File 'lib/rookout/processor/namespaces/ruby_object_namespace.rb', line 63

def read_attribute name
  attributes = @obj.instance_variables
  raise RookAttributeNotFound, name unless attributes.include? name.to_sym
  RubyObjectNamespace.new @obj.instance_variable_get(name)
end

#read_key(key) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/rookout/processor/namespaces/ruby_object_namespace.rb', line 69

def read_key key
  case @obj
  when Array, String
    read_key_as_int key
  when Hash
    read_key_from_hash key
  else
    raise Exceptions::RookInvalidObjectForAccess.new(@obj.class.to_s, "ReadKey")
  end
end

#tailor_limits!Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/rookout/processor/namespaces/ruby_object_namespace.rb', line 52

def tailor_limits!
  if @obj.is_a? String
    @dump_config = OBJECT_DUMP_CONFIG_STRING
  elsif (@obj.is_a?(Hash) || @obj.is_a?(Array)) && @obj.length > OBJECT_DUMP_CONFIG_TOLERANT.max_width
    @dump_config = OBJECT_DUMP_CONFIG_COLLECTION
  else
    @dump_config = OBJECT_DUMP_CONFIG_TOLERANT
  end
  self
end