Sha256: 2b2b5500b41b49c236b121a8831f544063223ec0be67f27892098cbe554995ed

Contents?: true

Size: 982 Bytes

Versions: 2

Compression:

Stored size: 982 Bytes

Contents

require 'pathname'
require 'fileutils'

module Daemons
  module Rails
    class Configuration
      def detect_root
        if defined?(::Rails)
          ::Rails.root
        else
          root = Pathname.new(FileUtils.pwd)
          root = root.parent unless root.directory?
          root = root.parent until File.exists?(root.join('config.ru')) || root.root?
          raise "Can't detect Rails application root" if root.root?
          root
        end
      end

      def daemons_path=(path)
        @daemons_path = path && (path.is_a?(Pathname) ? path : Pathname.new(File.expand_path(path)))
      end

      def root=(path)
        @root = path && (path.is_a?(Pathname) ? path : Pathname.new(File.expand_path(path)))
      end

      def root
        @root ||= detect_root
      end

      def daemons_path
        @daemons_path || root.join('lib', 'daemons')
      end

      def daemons_directory
        daemons_path.relative_path_from(root)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
daemons-rails-1.1.2 lib/daemons/rails/configuration.rb
daemons-rails-1.1.1 lib/daemons/rails/configuration.rb