Class: ReeObject::ToObj

Inherits:
Object
  • Object
show all
Includes:
Ree::FnDSL
Defined in:
lib/ree_lib/packages/ree_object/package/ree_object/functions/to_obj.rb

Instance Method Summary collapse

Instance Method Details

#call(obj, **opts) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ree_lib/packages/ree_object/package/ree_object/functions/to_obj.rb', line 21

def call(obj, **opts)
  dump = to_hash(obj)

  options = prepare_options(opts)

  if opts[:include]
    dump = slice(dump, options[:include])
  end

  if opts[:exclude]
    dump = except(dump, options[:exclude])
  end

  if opts[:global_exclude]
    dump = except(dump, global_except: options[:global_exclude])
  end

  ancestors = dump.class.ancestors
  return dump if ancestors.intersection(BASIC_TYPES).size > 0

  if dump.is_a?(Array)
    build_array(dump)
  else
    recursively_assign(Object.new, dump)
  end
end