Module: Sraas::HasSraas::ClassMethods

Defined in:
lib/sraas/has_sraas.rb

Instance Method Summary collapse

Instance Method Details

#has_sraas(name: nil, fingerprint: nil, deck: nil) ⇒ Object

name: string – the name of the deck to use with Sraas

symbol -- the method to call on this object that returns a deck name
nil    -- use the default in configuration or errors...

fingerprint: string – allows locking to one specific deck version



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sraas/has_sraas.rb', line 8

def has_sraas(name: nil, fingerprint: nil, deck: nil)
  if deck # v1.0 Syntax
    raise "Since GEM 0.3.0, semantics changed for has_sraas. You need to say has_sraas name: ..."
  end
  has_one :sraas, as: :sraas_consumerable, class_name: 'Sraas::Consumer'

  after_create :configure_sraas_consumer!

  if name.is_a?(Symbol)
    # We allow specifying a symbol as a method name/attribute that will return the deck name
    # make sure model supports it:
    raise "[Undefined Method Error] Class '#{self.name}' doesn't have a method #{name}" unless self.method_defined?(name) || self.has_attribute?(name)
  end
  self.sraas_default_deck_name = name || Sraas.configuration.default_deck_name
  self.sraas_default_deck_fingerprint = fingerprint || Sraas.configuration.default_deck_fingerprint
end