Class: Lookbook::RuntimeContext
- Inherits:
-
Object
- Object
- Lookbook::RuntimeContext
- Defined in:
- lib/lookbook/runtime_context.rb
Instance Attribute Summary collapse
- #env ⇒ Object readonly
Instance Method Summary collapse
- #actioncable_installed? ⇒ Boolean
- #app_name ⇒ Object
- #gem_installed?(name) ⇒ Boolean
-
#initialize(env: Rails.env) ⇒ RuntimeContext
constructor
A new instance of RuntimeContext.
- #listen_installed? ⇒ Boolean
- #rails_newer_than?(version) ⇒ Boolean
- #rails_older_than?(version) ⇒ Boolean
- #rake_task? ⇒ Boolean
- #web? ⇒ Boolean
Constructor Details
#initialize(env: Rails.env) ⇒ RuntimeContext
Returns a new instance of RuntimeContext.
5 6 7 |
# File 'lib/lookbook/runtime_context.rb', line 5 def initialize(env: Rails.env) @env = env end |
Instance Attribute Details
#env ⇒ Object (readonly)
3 4 5 |
# File 'lib/lookbook/runtime_context.rb', line 3 def env @env end |
Instance Method Details
#actioncable_installed? ⇒ Boolean
25 26 27 |
# File 'lib/lookbook/runtime_context.rb', line 25 def actioncable_installed? gem_installed?("actioncable") end |
#app_name ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/lookbook/runtime_context.rb', line 9 def app_name return @_app_name if @_app_name app_class = Rails.application.class name = app_class.respond_to?(:module_parent_name) ? app_class.module_parent_name : app_class.parent_name @_app_name ||= name.underscore end |
#gem_installed?(name) ⇒ Boolean
33 34 35 |
# File 'lib/lookbook/runtime_context.rb', line 33 def gem_installed?(name) Gem.loaded_specs.has_key?(name) end |
#listen_installed? ⇒ Boolean
29 30 31 |
# File 'lib/lookbook/runtime_context.rb', line 29 def listen_installed? gem_installed?("listen") end |
#rails_newer_than?(version) ⇒ Boolean
21 22 23 |
# File 'lib/lookbook/runtime_context.rb', line 21 def rails_newer_than?(version) Gem::Version.new(Rails.version) >= Gem::Version.new(version) end |
#rails_older_than?(version) ⇒ Boolean
17 18 19 |
# File 'lib/lookbook/runtime_context.rb', line 17 def rails_older_than?(version) Gem::Version.new(Rails.version) < Gem::Version.new(version) end |
#rake_task? ⇒ Boolean
41 42 43 44 45 46 47 |
# File 'lib/lookbook/runtime_context.rb', line 41 def rake_task? if defined?(Rake) && Rake.respond_to?(:application) File.basename($0) == "rake" || Rake.application.top_level_tasks.any? else false end end |
#web? ⇒ Boolean
37 38 39 |
# File 'lib/lookbook/runtime_context.rb', line 37 def web? !rake_task? && !Rails.const_defined?(:Console, false) end |