Sha256: e43479626d945bc42e356acd0678c00d80a9253d4c6c11f09219618b8060818a

Contents?: true

Size: 1.19 KB

Versions: 6

Compression:

Stored size: 1.19 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
        # Call daddy
        super

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


####### HELPERS

      helpers do

        def info message, lines = []
          Root.logger.info_with_id message,
            lines: lines,
            origin: self.class.to_s
        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

      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rest-ftp-daemon-0.214.0 lib/rest-ftp-daemon/api/root.rb
rest-ftp-daemon-0.213.0 lib/rest-ftp-daemon/api/root.rb
rest-ftp-daemon-0.212.0 lib/rest-ftp-daemon/api/root.rb
rest-ftp-daemon-0.210.2 lib/rest-ftp-daemon/api/root.rb
rest-ftp-daemon-0.210.1 lib/rest-ftp-daemon/api/root.rb
rest-ftp-daemon-0.210.0 lib/rest-ftp-daemon/api/root.rb