Class: Restapi::ResourceDescription

Inherits:
Object
  • Object
show all
Defined in:
lib/restapi/resource_description.rb

Overview

Resource description

version - api version (1) description path - relative path (/api/articles) methods - array of keys to Restapi.method_descriptions (array of Restapi::MethodDescription) name - human readable alias of resource (Articles) id - resouce name

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, resource_name, &block) ⇒ ResourceDescription

Returns a new instance of ResourceDescription.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/restapi/resource_description.rb', line 16

def initialize(controller, resource_name, &block)
  @_methods = []
  @_params_ordered = []

  @controller = controller
  @_id = resource_name
  @_version = "1"
  @_name = @_id.humanize
  @_full_description = ""
  @_short_description = ""
  @_path = ""
  
  block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
end

Instance Attribute Details

#_full_descriptionObject (readonly)

Returns the value of attribute _full_description.



13
14
15
# File 'lib/restapi/resource_description.rb', line 13

def _full_description
  @_full_description
end

#_idObject (readonly)

Returns the value of attribute _id.



13
14
15
# File 'lib/restapi/resource_description.rb', line 13

def _id
  @_id
end

#_methodsObject (readonly)

Returns the value of attribute _methods.



13
14
15
# File 'lib/restapi/resource_description.rb', line 13

def _methods
  @_methods
end

#_nameObject (readonly)

Returns the value of attribute _name.



13
14
15
# File 'lib/restapi/resource_description.rb', line 13

def _name
  @_name
end

#_params_orderedObject (readonly)

Returns the value of attribute _params_ordered.



13
14
15
# File 'lib/restapi/resource_description.rb', line 13

def _params_ordered
  @_params_ordered
end

#_pathObject (readonly)

Returns the value of attribute _path.



13
14
15
# File 'lib/restapi/resource_description.rb', line 13

def _path
  @_path
end

#_short_descriptionObject (readonly)

Returns the value of attribute _short_description.



13
14
15
# File 'lib/restapi/resource_description.rb', line 13

def _short_description
  @_short_description
end

#_versionObject (readonly)

Returns the value of attribute _version.



13
14
15
# File 'lib/restapi/resource_description.rb', line 13

def _version
  @_version
end

#controllerObject (readonly)

Returns the value of attribute controller.



13
14
15
# File 'lib/restapi/resource_description.rb', line 13

def controller
  @controller
end

Instance Method Details

#add_method(mapi_key) ⇒ Object

add description of resource method



53
54
55
56
# File 'lib/restapi/resource_description.rb', line 53

def add_method(mapi_key)
  @_methods << mapi_key
  @_methods.uniq!
end

#api_urlObject



62
# File 'lib/restapi/resource_description.rb', line 62

def api_url; "#{Restapi.configuration.api_base_url}#{@_path}"; end

#desc(description) ⇒ Object Also known as: description, full_description



45
46
47
48
# File 'lib/restapi/resource_description.rb', line 45

def desc(description)
  description ||= ''
  @_full_description = Restapi.markup_to_html(description)
end

#doc_urlObject



58
59
60
# File 'lib/restapi/resource_description.rb', line 58

def doc_url
  Restapi.full_url(@_id)
end

#name(name) ⇒ Object



40
# File 'lib/restapi/resource_description.rb', line 40

def name(name); @_name = name; end

#param(param_name, *args, &block) ⇒ Object



31
32
33
34
# File 'lib/restapi/resource_description.rb', line 31

def param(param_name, *args, &block)
  param_description = Restapi::ParamDescription.new(param_name, *args, &block)
  @_params_ordered << param_description
end

#path(path) ⇒ Object



36
# File 'lib/restapi/resource_description.rb', line 36

def path(path); @_path = path; end

#short(short) ⇒ Object Also known as: short_description



42
# File 'lib/restapi/resource_description.rb', line 42

def short(short); @_short_description = short; end

#to_json(method_name = nil) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/restapi/resource_description.rb', line 64

def to_json(method_name = nil)

  _methods = if method_name.blank?
    @_methods.collect { |key| Restapi.method_descriptions[key].to_json }
  else
    [Restapi.method_descriptions[[@_id, method_name].join('#')].to_json]
  end

  {
    :doc_url => doc_url,
    :api_url => api_url,
    :name => @_name,
    :short_description => @_short_description,
    :full_description => @_full_description,
    :version => @_version,
    :methods => _methods
  }
end

#version(version) ⇒ Object



38
# File 'lib/restapi/resource_description.rb', line 38

def version(version); @_version = version; end