Class: Plok::Engine

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

Instance Method Summary collapse

Instance Method Details

#class_exists?(class_name) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
# File 'lib/plok/engine.rb', line 22

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

#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.



42
43
44
# File 'lib/plok/engine.rb', line 42

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

#module_exists?(module_name) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
# File 'lib/plok/engine.rb', line 29

def 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