Sha256: 4d3a7f4446027850bcb734bab773cc3b23a9266c618de817f27f201f9d0970bf

Contents?: true

Size: 1.07 KB

Versions: 12

Compression:

Stored size: 1.07 KB

Contents

module Lookbook
  class RuntimeContext
    attr_reader :env

    def initialize(env: Rails.env)
      @env = env
    end

    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

    def rails_older_than?(version)
      Gem::Version.new(Rails.version) < Gem::Version.new(version)
    end

    def rails_newer_than?(version)
      Gem::Version.new(Rails.version) >= Gem::Version.new(version)
    end

    def actioncable_installed?
      gem_installed?("actioncable")
    end

    def listen_installed?
      gem_installed?("listen")
    end

    def gem_installed?(name)
      Gem.loaded_specs.has_key?(name)
    end

    def web?
      !rake_task? && !Rails.const_defined?(:Console)
    end

    def rake_task?
      if defined?(Rake) && Rake.respond_to?(:application)
        File.basename($0) == "rake" || Rake.application.top_level_tasks.any?
      else
        false
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
lookbook-2.0.0.rc.2 lib/lookbook/runtime_context.rb
lookbook-2.0.0.rc.1 lib/lookbook/runtime_context.rb
lookbook-2.0.0.beta.9 lib/lookbook/runtime_context.rb
lookbook-2.0.0.beta.8 lib/lookbook/runtime_context.rb
lookbook-2.0.0.beta.7 lib/lookbook/runtime_context.rb
lookbook-2.0.0.beta.6 lib/lookbook/runtime_context.rb
lookbook-2.0.0.beta.5 lib/lookbook/runtime_context.rb
lookbook-2.0.0.beta.4 lib/lookbook/runtime_context.rb
lookbook-2.0.0.beta.3 lib/lookbook/runtime_context.rb
lookbook-2.0.0.beta.2 lib/lookbook/runtime_context.rb
lookbook-2.0.0.beta.1 lib/lookbook/runtime_context.rb
lookbook-2.0.0.beta.0 lib/lookbook/runtime_context.rb