Class: Workarea::Fulfillment::Sku

Inherits:
Object
  • Object
show all
Extended by:
Dragonfly::Model
Includes:
ApplicationDocument
Defined in:
app/models/workarea/fulfillment/sku.rb

Defined Under Namespace

Classes: InvalidPolicy

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ApplicationDocument

#releasable?

Methods included from Sidekiq::Callbacks

add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list

Methods included from Mongoid::Document

#embedded_children

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



43
44
45
46
47
48
# File 'app/models/workarea/fulfillment/sku.rb', line 43

def method_missing(sym, *args, &block)
  method = sym.to_s.chomp('?')
  return super unless self.class.policies.include?(method)

  method == policy
end

Class Method Details

.find_or_initialize_all(ids) ⇒ Object



26
27
28
29
# File 'app/models/workarea/fulfillment/sku.rb', line 26

def self.find_or_initialize_all(ids)
  existing = self.in(id: ids).to_a
  ids.map { |id| existing.detect { |sku| sku.id == id } || new(id: id) }
end

.policiesObject



18
19
20
# File 'app/models/workarea/fulfillment/sku.rb', line 18

def self.policies
  Workarea.config.fulfillment_policies.map(&:demodulize).map(&:underscore)
end

.process!(id, **args) ⇒ Object



22
23
24
# File 'app/models/workarea/fulfillment/sku.rb', line 22

def self.process!(id, **args)
  find_or_initialize_by(id: id).process!(args)
end

Instance Method Details

#downloadable?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/models/workarea/fulfillment/sku.rb', line 39

def downloadable?
  download? && file.present?
end

#nameObject



31
32
33
# File 'app/models/workarea/fulfillment/sku.rb', line 31

def name
  I18n.t('workarea.fulfillment_sku.name', id: id)
end

#process!(**args) ⇒ Object



35
36
37
# File 'app/models/workarea/fulfillment/sku.rb', line 35

def process!(**args)
  policy_object.process(args)
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'app/models/workarea/fulfillment/sku.rb', line 50

def respond_to_missing?(method_name, include_private = false)
  self.class.policies.include?(method_name.to_s.chomp('?')) || super
end