Module: Decanter::Extensions::ClassMethods

Defined in:
lib/decanter/extensions.rb

Instance Method Summary collapse

Instance Method Details

#decant(args, options = {}) ⇒ Object



37
38
39
# File 'lib/decanter/extensions.rb', line 37

def decant(args, options={})
  is_collection?(args, options[:is_collection]) ? decant_collection(args, options) : decant_args(args, options)
end

#decant_args(args, options) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/decanter/extensions.rb', line 45

def decant_args(args, options)
  if specified_decanter = options[: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, options)
  args.map { |resource| decant_args(resource, options) }
end

#decant_create(args, **options) ⇒ Object



23
24
25
26
# File 'lib/decanter/extensions.rb', line 23

def decant_create(args, **options)
  self.new(decant(args, options))
      .save(context: options[:context])
end

#decant_create!(args, **options) ⇒ Object



32
33
34
35
# File 'lib/decanter/extensions.rb', line 32

def decant_create!(args, **options)
  self.new(decant(args, options))
      .save!(context: options[:context])
end

#decant_new(args, **options) ⇒ Object



28
29
30
# File 'lib/decanter/extensions.rb', line 28

def decant_new(args, **options)
  self.new(decant(args, options))
end