Sha256: a38f00b7a281f3508faeadc6903798d665023e667f4d9bb6765c8b4ea9c2a8aa

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

# This class represents a single resource.
# It contains attributes from parsed definition.
# So anywhere in view template we can use this object.
class Calamum::Resource
  attr_accessor :uri, :action, :headers,
    :auth, :params, :errors, :description, :response

  # Initialize object from attributes.
  #
  # @param attrs [Hash] attributes to set
  def initialize(attrs)
    @uri = attrs['uri']
    @action = attrs['action'].upcase
    @headers = attrs['headers'] || {}
    @auth = !!attrs['authentication']
    @params = attrs['params'] || {}
    @errors = attrs['errors'] || {}
    @description = attrs['description']
    @response = attrs['response']
  end
  
  # @override
  # Returns a string representing a label css class.
  #
  # @return [String] css class
  def action_label
    case @action
    when 'GET'
      'label-info'
    when 'POST'
      'label-success'
    when 'PUT'
      'label-warning'
    when 'DELETE'
      'label-important'
    end
  end

  # @override
  # Returns a string representing a resource.
  #
  # @return [String] resource in a form (action: uri)
  def to_s
    "#{action}: #{uri}"
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
calamum-1.1.0 lib/calamum/resource.rb