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,
  ActiveSupport::TimeWithZone
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, options) ⇒ Converter

Returns a new instance of Converter.



12
13
14
15
# File 'lib/ar2dto/converter.rb', line 12

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

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



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

def model
  @model
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#serializable_hashObject



17
18
19
20
21
# File 'lib/ar2dto/converter.rb', line 17

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