Module: Decanter::Extensions::ClassMethods
- Defined in:
- lib/decanter/extensions.rb
Instance Method Summary collapse
- #decant(args, options = {}) ⇒ Object
- #decant_args(args, options) ⇒ Object
- #decant_collection(args, options) ⇒ Object
- #decant_create(args, **options) ⇒ Object
- #decant_create!(args, **options) ⇒ Object
- #decant_new(args, **options) ⇒ Object
Instance Method Details
#decant(args, options = {}) ⇒ Object
37 38 39 |
# File 'lib/decanter/extensions.rb', line 37 def decant(args, ={}) is_collection?(args, [:is_collection]) ? decant_collection(args, ) : decant_args(args, ) end |
#decant_args(args, options) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/decanter/extensions.rb', line 45 def decant_args(args, ) if specified_decanter = [:decanter] Decanter.decanter_from(specified_decanter) else Decanter.decanter_for(self) end.decant(args) end |
#decant_collection(args, options) ⇒ Object
41 42 43 |
# File 'lib/decanter/extensions.rb', line 41 def decant_collection(args, ) args.map { |resource| decant_args(resource, ) } end |
#decant_create(args, **options) ⇒ Object
23 24 25 26 |
# File 'lib/decanter/extensions.rb', line 23 def decant_create(args, **) self.new(decant(args, )) .save(context: [:context]) end |
#decant_create!(args, **options) ⇒ Object
32 33 34 35 |
# File 'lib/decanter/extensions.rb', line 32 def decant_create!(args, **) self.new(decant(args, )) .save!(context: [:context]) end |
#decant_new(args, **options) ⇒ Object
28 29 30 |
# File 'lib/decanter/extensions.rb', line 28 def decant_new(args, **) self.new(decant(args, )) end |