Sha256: 9aca86228c8f39ed42ad9ce751084d9a9f21fa200fc7b10f569208754be7bad2

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

require File.join(File.dirname(__FILE__), %w[.. app_slice])
require File.join(File.dirname(__FILE__), %w[rails initializer])

module AppSlice
  module Rails
    class << self
      def init!
        ::Rails.public_path = File.join(root, 'public')
        ::ActionController::Routing::Routes.add_configuration_file File.join(config_path, 'routes.rb')
        # Update frameworks with view_paths
        [::ActionController, ::ActionMailer].each do |framework|
          framework::Base.send(:view_paths).unshift(view_path)
        end
        @initialized = true
      end
      
      def root
        if AppSlice.exists?
          File.join(RAILS_ROOT, 'app_slices', AppSlice.app)
        else
          RAILS_ROOT
        end
      end
      
      def environment_path
        File.join(config_path, 'environments', "#{RAILS_ENV}.rb")
      end
      
      def root_environment_path
        File.join(config_path, 'environment.rb')
      end
      
      def config_path
        File.join(root, 'config')
      end
      
      def view_path
        File.join(root, %w[app views])
      end
      
      def configure(configuration = ::Rails::Configuration.new)
        # Create our new configuration block here
        configuration.database_configuration_file = database_configuration_file
        return configuration
      end
      
      def initialized?
        @initialized
      end
      
    protected
      def routes_configuration_file
        File.join(config_path, 'routes.rb')
      end
      
      def database_configuration_file
        File.join(config_path, 'database.yml')
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bradgessler-app-slice-0.2.2 lib/app_slice/rails.rb
bradgessler-app-slice-0.2.3 lib/app_slice/rails.rb