Class: Plok::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/plok/engine.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.class_exists?(class_name) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
# File 'lib/plok/engine.rb', line 25

def self.class_exists?(class_name)
  klass = Module.const_get(class_name.to_s)
  klass.is_a?(Class)
rescue NameError
  return false
end

.module_exists?(module_name) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/plok/engine.rb', line 32

def self.module_exists?(module_name)
  # By casting to a string and making a constant, we can assume module_name
  # can be either one without it being a problem.
  module_name.to_s.constantize.is_a?(Module)
rescue NameError
  return false
end

Instance Method Details

#load_spec_supportsObject

You can call this in your spec/rails_helper.rb file so you can make use of the spec supports to test concerns.

You cannot call it in the engine itself, because RSpec won’t have the same context available when tests are ran.



45
46
47
# File 'lib/plok/engine.rb', line 45

def load_spec_supports
  Dir.glob("#{root}/spec/{factories,support}/**/*.rb").sort.each { |f| require f }
end