Class: PaperPlane::FlightRoutes::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/paper_plane/flight_routes/base.rb

Direct Known Subclasses

Email

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(route_name = nil) ⇒ Base

Returns a new instance of Base.



19
20
21
22
# File 'lib/paper_plane/flight_routes/base.rb', line 19

def initialize(route_name = nil)
  @_route_name = route_name || _default_route_name
  @_engine = _default_engine
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



17
18
19
# File 'lib/paper_plane/flight_routes/base.rb', line 17

def context
  @context
end

#recipientObject

Returns the value of attribute recipient.



17
18
19
# File 'lib/paper_plane/flight_routes/base.rb', line 17

def recipient
  @recipient
end

Class Method Details

.fly(mid, context, **args) ⇒ Object



24
25
26
# File 'lib/paper_plane/flight_routes/base.rb', line 24

def self.fly(mid, context, **args)
  new.fly(mid, context, **args)
end

.inherited(subklass) ⇒ Object



10
11
12
13
14
15
# File 'lib/paper_plane/flight_routes/base.rb', line 10

def self.inherited(subklass)
  subklass.class_eval do
    extend PaperPlane::FlightRoutes::ClassMethods
    default_views 'app/paper_planes'
  end
end

Instance Method Details

#do_flyObject

Raises:



47
48
49
# File 'lib/paper_plane/flight_routes/base.rb', line 47

def do_fly
  raise DoFlyUndefined, 'Please override :do_fly in your flight route.'
end

#fly(mid, context, **args) ⇒ Object

to be overriden by children



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/paper_plane/flight_routes/base.rb', line 29

def fly(mid, context, **args)
  @method = mid
  @args = args
  @context = context

  _extract_recipient
  _extract_template_formats
  _extract_paper_plane_name

  begin
    do_fly
  rescue NoTemplateError
    _logger.debug "'#{route_name}' skipped for lack of suited template => path: '#{_template_file_path}'; extension: #{_template_formats}."
  else
    _logger.debug "#{route_name} sent!"
  end
end