Class: AR2DTO::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/ar2dto/converter.rb

Constant Summary collapse

ALLOWED_TYPES =
[Symbol, BigDecimal, Regexp, IO, Range, Time, Date, DateTime,
URI::Generic, Pathname, IPAddr, Process::Status, Exception].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, options) ⇒ Converter

Returns a new instance of Converter.



9
10
11
12
# File 'lib/ar2dto/converter.rb', line 9

def initialize(model, options)
  @model = model
  @options = apply_configs(options)
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



7
8
9
# File 'lib/ar2dto/converter.rb', line 7

def model
  @model
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/ar2dto/converter.rb', line 7

def options
  @options
end

Instance Method Details

#serializable_hashObject



14
15
16
17
18
# File 'lib/ar2dto/converter.rb', line 14

def serializable_hash
  hash = model.serializable_hash(options&.except(:methods, :include))
  hash = add_methods(hash)
  add_associations(hash)
end