Sha256: dca656104ce141fe2e4438b7f225c51a2956dd1abb61ca5b268b5040eb9ebf7d

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

module RestFtpDaemon
  module API
    class Root < Grape::API


####### CLASS CONFIG

      # logger RestFtpDaemon::Logger.new(:api, "API")
      logger RestFtpDaemon::LoggerPool.instance.get :api

      do_not_route_head!
      do_not_route_options!

      # FIXME
      # add_swagger_documentation
      # default_error_formatter :json
      format :json


####### INITIALIZATION

      def initialize
        super
      end


####### HELPERS

      helpers do

        def info message
          Root.logger.info_with_id message
        end

        def api_error exception
          {
          :error => exception.message,
          :message => exception.backtrace.first,
          }
        end

        def render name, values={}
          template = File.read("#{APP_LIBS}/views/#{name.to_s}.haml")
          haml_engine = Haml::Engine.new(template)
          haml_engine.render(binding, values)
        end

        def job_find job_id
          return nil if ($queue.all_size==0)

          # Find a job with exactly this id, or prefixed if not found
          $queue.find_by_id(job_id) || $queue.find_by_id(job_id, true)
        end

      end


####### INITIALIZATION

      def initialize
        # Call daddy
        super

        # Check that Queue and Pool are available
        raise RestFtpDaemon::MissingQueue unless defined? $queue
        raise RestFtpDaemon::MissingQueue unless defined? $pool
      end


    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rest-ftp-daemon-0.100.2 lib/rest-ftp-daemon/api/root.rb
rest-ftp-daemon-0.100 lib/rest-ftp-daemon/api/root.rb