Class: Spree::Emails::EditableTemplates::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/spree/emails/editable_templates.rb

Overview

One editable template.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, kind:, sample: nil) ⇒ Definition

Returns a new instance of Definition.

Parameters:

  • key (String) —

    the template's view path, e.g. "spree/order_mailer/confirm_email"

  • kind (Symbol) —

    :email, :layout or :partial

  • sample (String, nil) (defaults to: nil) —

    class building sample variables for an email (see Spree::Emails::Samples::Base)

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
# File 'lib/spree/emails/editable_templates.rb', line 26

def initialize(key:, kind:, sample: nil)
  raise ArgumentError, "Unknown email template kind: #{kind.inspect}" unless KINDS.include?(kind)

  @key = key
  @kind = kind
  @sample = sample
end

Instance Attribute Details

#key ⇒ Object (readonly)

Returns the value of attribute key.



21
22
23
# File 'lib/spree/emails/editable_templates.rb', line 21

def key
  @key
end

#kind ⇒ Object (readonly)

Returns the value of attribute kind.



21
22
23
# File 'lib/spree/emails/editable_templates.rb', line 21

def kind
  @kind
end

#sample ⇒ Object (readonly)

Returns the value of attribute sample.



21
22
23
# File 'lib/spree/emails/editable_templates.rb', line 21

def sample
  @sample
end

Instance Method Details

#email? ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/spree/emails/editable_templates.rb', line 34

def email?
  kind == :email
end

#sample_class ⇒ Class?

Returns:

  • (Class, nil)


39
40
41
# File 'lib/spree/emails/editable_templates.rb', line 39

def sample_class
  sample&.constantize
end