Class: AR2DTO::DTO
- Inherits:
-
Object
- Object
- AR2DTO::DTO
- Defined in:
- lib/ar2dto/dto.rb
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #as_json(options = nil) ⇒ Object
-
#initialize(attributes = {}) ⇒ DTO
constructor
A new instance of DTO.
Constructor Details
#initialize(attributes = {}) ⇒ DTO
Returns a new instance of DTO.
12 13 14 15 |
# File 'lib/ar2dto/dto.rb', line 12 def initialize(attributes = {}) attributes.each { |key, value| define_singleton_method(key) { value } } super() end |
Class Method Details
.[](original_model) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/ar2dto/dto.rb', line 5 def self.[](original_model) Class.new(self) do include ::AR2DTO::ActiveModel if original_model.ar2dto.active_model_compliance define_singleton_method(:original_model) { original_model } end end |
Instance Method Details
#==(other) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/ar2dto/dto.rb', line 22 def ==(other) if other.instance_of?(self.class) as_json == other.as_json else super end end |
#as_json(options = nil) ⇒ Object
17 18 19 20 |
# File 'lib/ar2dto/dto.rb', line 17 def as_json( = nil) attribute_names = self.class.original_model.attribute_names attribute_names.map { |name| [name.to_sym, send(name)] }.to_h.as_json() end |