module Hyperender::Action

Public Class Methods

included(base) click to toggle source
# File lib/hyperender.rb, line 90
def self.included(base)
  base.class_eval do
    def hateoas_data *args
      case args.count
      when 0 then @hateoas_data_render ||= {}
      when 1 then @hateoas_data_render = args[0]
      else        @hateoas_data_render = args
      end
      @hateoas_data_render
    end

    def hateoas_error *args
      case args.count
      when 0 then @errors ||= {}
      when 1 then @errors = args[0]
      else        @errors = args
      end
      @errors
    end

    def hateoas_params *args
      case args.count
      when 0 then @params ||= request.query_parameters
      when 1 then @params = args[0]
      else        @params = args
      end
      params_class = @params.class.to_s rescue nil
      unless params_class.in? ["Hash","Array","String"]
        @params = (@params.as_json rescue (@params.to_s rescue "not renderable"))
      end
      @params
    end

    def hateoas_message
      @message ||= HATEOAS_MSG[response.status]
      @message
    end

    def hateoas_status
      @status ||= response.status
      @status
    end

    def hateoas_request
      @request ||= request
      @request
    end

    def hateoas_render
      Hyperender.render (hateoas_data), (hateoas_error), (hateoas_params), (hateoas_message), (hateoas_status), (hateoas_request)
    end

    def hateoas_rendering
      render json: hateoas_render
    end
  end
end

Public Instance Methods

hateoas_data(*args) click to toggle source
# File lib/hyperender.rb, line 92
def hateoas_data *args
  case args.count
  when 0 then @hateoas_data_render ||= {}
  when 1 then @hateoas_data_render = args[0]
  else        @hateoas_data_render = args
  end
  @hateoas_data_render
end
hateoas_error(*args) click to toggle source
# File lib/hyperender.rb, line 101
def hateoas_error *args
  case args.count
  when 0 then @errors ||= {}
  when 1 then @errors = args[0]
  else        @errors = args
  end
  @errors
end
hateoas_message() click to toggle source
# File lib/hyperender.rb, line 123
def hateoas_message
  @message ||= HATEOAS_MSG[response.status]
  @message
end
hateoas_params(*args) click to toggle source
# File lib/hyperender.rb, line 110
def hateoas_params *args
  case args.count
  when 0 then @params ||= request.query_parameters
  when 1 then @params = args[0]
  else        @params = args
  end
  params_class = @params.class.to_s rescue nil
  unless params_class.in? ["Hash","Array","String"]
    @params = (@params.as_json rescue (@params.to_s rescue "not renderable"))
  end
  @params
end
hateoas_render() click to toggle source
# File lib/hyperender.rb, line 138
def hateoas_render
  Hyperender.render (hateoas_data), (hateoas_error), (hateoas_params), (hateoas_message), (hateoas_status), (hateoas_request)
end
hateoas_rendering() click to toggle source
# File lib/hyperender.rb, line 142
def hateoas_rendering
  render json: hateoas_render
end
hateoas_request() click to toggle source
# File lib/hyperender.rb, line 133
def hateoas_request
  @request ||= request
  @request
end
hateoas_status() click to toggle source
# File lib/hyperender.rb, line 128
def hateoas_status
  @status ||= response.status
  @status
end