Sha256: 0e58c933b0677a1ebcc1a37987094c465fe8f20058cc2bbd3664d1e2eacc19e3

Contents?: true

Size: 1007 Bytes

Versions: 22

Compression:

Stored size: 1007 Bytes

Contents

require 'active_support/concern'
require 'active_support/all'

module Praxis
  module Controller
    extend ::ActiveSupport::Concern

    # A Controller always requires the callbacks
    include Praxis::Callbacks

    included do
      attr_reader :request
      attr_accessor :response
    end

    module ClassMethods
      def implements(definition)
        define_singleton_method(:definition) do
          definition
        end

        definition.controller = self
        Application.instance.controllers << self
      end

      def id
        self.name.gsub('::'.freeze,'-'.freeze)
      end
    end

    def initialize(request, response=Responses::Ok.new)
      @request = request
      @response = response
    end

    def definition
      self.class.definition
    end

    def media_type
      if (response_definition = self.request.action.responses[self.response.name])
        return response_definition.media_type
      else
        self.definition.media_type
      end
    end

  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
praxis-2.0.pre.18 lib/praxis/controller.rb
praxis-2.0.pre.17 lib/praxis/controller.rb
praxis-2.0.pre.16 lib/praxis/controller.rb
praxis-2.0.pre.15 lib/praxis/controller.rb
praxis-2.0.pre.14 lib/praxis/controller.rb
praxis-2.0.pre.13 lib/praxis/controller.rb
praxis-2.0.pre.12 lib/praxis/controller.rb
praxis-2.0.pre.11 lib/praxis/controller.rb
praxis-2.0.pre.10 lib/praxis/controller.rb
praxis-2.0.pre.9 lib/praxis/controller.rb
praxis-2.0.pre.8 lib/praxis/controller.rb
praxis-2.0.pre.7 lib/praxis/controller.rb
praxis-2.0.pre.6 lib/praxis/controller.rb
praxis-2.0.pre.5 lib/praxis/controller.rb
praxis-2.0.pre.4 lib/praxis/controller.rb
praxis-2.0.pre.3 lib/praxis/controller.rb
praxis-2.0.pre.2 lib/praxis/controller.rb
praxis-2.0.pre.1 lib/praxis/controller.rb
praxis-0.21 lib/praxis/controller.rb
praxis-0.20.1 lib/praxis/controller.rb