Class: Jets::Turbine

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::DescendantsTracker
Includes:
Initializable
Defined in:
lib/jets/turbine.rb,
lib/jets/turbine/configurable.rb,
lib/jets/turbine/configuration.rb

Direct Known Subclasses

Engine

Defined Under Namespace

Modules: Configurable Classes: Configuration

Constant Summary collapse

ABSTRACT_TURBINES =
%w(Jets::Turbine Jets::Engine Jets::Application)

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Initializable

included, #initializers, #run_initializers

Constructor Details

#initializeTurbine

:nodoc:



124
125
126
127
128
# File 'lib/jets/turbine.rb', line 124

def initialize # :nodoc:
  if self.class.abstract_turbine?
    raise "#{self.class.name} is abstract, you cannot instantiate it directly."
  end
end

Class Method Details

.<=>(other) ⇒ Object

:nodoc:



72
73
74
# File 'lib/jets/turbine.rb', line 72

def <=>(other) # :nodoc:
  load_index <=> other.load_index
end

.abstract_turbine?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/jets/turbine.rb', line 50

def abstract_turbine?
  ABSTRACT_TURBINES.include?(name)
end

.configure(&block) ⇒ Object

Allows you to configure the turbine. This is the same method seen in Turbine::Configurable, but this module is no longer required for all subclasses of Turbine so we provide the class method here.



68
69
70
# File 'lib/jets/turbine.rb', line 68

def configure(&block)
  instance.configure(&block)
end

.console(&blk) ⇒ Object



27
28
29
# File 'lib/jets/turbine.rb', line 27

def console(&blk)
  register_block_for(:load_console, &blk)
end

.generators(&blk) ⇒ Object



35
36
37
# File 'lib/jets/turbine.rb', line 35

def generators(&blk)
  register_block_for(:generators, &blk)
end

.inherited(subclass) ⇒ Object



76
77
78
79
# File 'lib/jets/turbine.rb', line 76

def inherited(subclass)
  subclass.increment_load_index
  super
end

.instanceObject

Since Jets::Turbine cannot be instantiated, any methods that call instance are intended to be called only on subclasses of a Turbine.



61
62
63
# File 'lib/jets/turbine.rb', line 61

def instance
  @instance ||= new
end

.on_exception(label, &blk) ⇒ Object

Jets specific. The label is no longer used and kept for backwards compatibility. Note it uses the same register_block_for but works a bit differently. See on_exception_blocks method to see how it works.



46
47
48
# File 'lib/jets/turbine.rb', line 46

def on_exception(label, &blk)
  register_block_for(:on_exception, &blk)
end

.rake_tasks(&blk) ⇒ Object



23
24
25
# File 'lib/jets/turbine.rb', line 23

def rake_tasks(&blk)
  register_block_for(:rake_tasks, &blk)
end

.runner(&blk) ⇒ Object



31
32
33
# File 'lib/jets/turbine.rb', line 31

def runner(&blk)
  register_block_for(:runner, &blk)
end

.server(&blk) ⇒ Object



39
40
41
# File 'lib/jets/turbine.rb', line 39

def server(&blk)
  register_block_for(:server, &blk)
end

.subclassesObject



19
20
21
# File 'lib/jets/turbine.rb', line 19

def subclasses
  super.reject(&:abstract_turbine?).sort
end

.turbine_name(name = nil) ⇒ Object



54
55
56
57
# File 'lib/jets/turbine.rb', line 54

def turbine_name(name = nil)
  @turbine_name = name.to_s if name
  @turbine_name ||= generate_turbine_name(self.name)
end

Instance Method Details

#configObject

This is used to create the config object on Turbines, an instance of Turbine::Configuration, that is used by Turbines and Application to store related configuration.



141
142
143
# File 'lib/jets/turbine.rb', line 141

def config
  @config ||= Turbine::Configuration.new
end

#configure(&block) ⇒ Object

:nodoc:



134
135
136
# File 'lib/jets/turbine.rb', line 134

def configure(&block) # :nodoc:
  instance_eval(&block)
end

#inspectObject

:nodoc:



130
131
132
# File 'lib/jets/turbine.rb', line 130

def inspect # :nodoc:
  "#<#{self.class.name}>"
end

#on_exception_blocksObject



149
150
151
# File 'lib/jets/turbine.rb', line 149

def on_exception_blocks
  self.class.instance_variable_get(:@on_exception) || []
end

#turbine_namespaceObject

:nodoc:



145
146
147
# File 'lib/jets/turbine.rb', line 145

def turbine_namespace # :nodoc:
  @turbine_namespace ||= self.class.module_parents.detect { |n| n.respond_to?(:turbine_namespace) }
end