Sha256: 45a7c65c9305dbb9fb39fffa2a9c6af5f80594b806d447d5455b60c6363de913

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

module DynamicController
  module ClassMethods

    def parent_resources
      @parent_resources ||= []
    end

    def include_action?(action_name)
      (@resource_options[:only] - @resource_options[:except]).include?(action_name)
    end

    def redefined_responders
      @redefined_responders ||= {}
    end

    def redefined_responder_to(action, format=nil)
      redefined_responders[redefined_responder_key(action, format)]
    end

    def redefined_responder_to?(action, format=nil)
      redefined_responders.has_key? redefined_responder_key(action, format)
    end

    def responder_formats
      @responder_formats ||= [:html, :json]
    end

    DynamicController::ACTIONS.each do |action|
      define_method "respond_to_#{action}" do |format=nil, &block|
        responder_formats << format if format and !responder_formats.include?(format)
        redefined_responders[redefined_responder_key(action, format)] = block
      end
    end

    private

    def redefined_responder_key(action, format=nil)
      [action, format].compact.join('_').to_sym
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dynamic_controller-0.0.12 lib/dynamic_controller/class_methods.rb
dynamic_controller-0.0.11 lib/dynamic_controller/class_methods.rb
dynamic_controller-0.0.10 lib/dynamic_controller/class_methods.rb
dynamic_controller-0.0.9 lib/dynamic_controller/class_methods.rb