Class: Calamum::Resource
- Inherits:
-
Object
- Object
- Calamum::Resource
- Defined in:
- lib/calamum/resource.rb
Overview
This class represents a single resource. It contains attributes from parsed definition. So anywhere in view template we can use this object.
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#auth ⇒ Object
Returns the value of attribute auth.
-
#description ⇒ Object
Returns the value of attribute description.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#params ⇒ Object
Returns the value of attribute params.
-
#response ⇒ Object
Returns the value of attribute response.
-
#tryit ⇒ Object
Returns the value of attribute tryit.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#action_label ⇒ String
Returns a string representing a label css class.
-
#initialize(attrs) ⇒ Resource
constructor
Initialize object from attributes.
-
#slug ⇒ String
Returns a unique, but readable name for this resource suitable for use as a filename.
-
#to_s ⇒ String
Returns a string representing a resource.
Constructor Details
#initialize(attrs) ⇒ Resource
Initialize object from attributes.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/calamum/resource.rb', line 11 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'] @tryit = attrs['tryit'] end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
5 6 7 |
# File 'lib/calamum/resource.rb', line 5 def action @action end |
#auth ⇒ Object
Returns the value of attribute auth.
5 6 7 |
# File 'lib/calamum/resource.rb', line 5 def auth @auth end |
#description ⇒ Object
Returns the value of attribute description.
5 6 7 |
# File 'lib/calamum/resource.rb', line 5 def description @description end |
#errors ⇒ Object
Returns the value of attribute errors.
5 6 7 |
# File 'lib/calamum/resource.rb', line 5 def errors @errors end |
#headers ⇒ Object
Returns the value of attribute headers.
5 6 7 |
# File 'lib/calamum/resource.rb', line 5 def headers @headers end |
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'lib/calamum/resource.rb', line 5 def params @params end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/calamum/resource.rb', line 5 def response @response end |
#tryit ⇒ Object
Returns the value of attribute tryit.
5 6 7 |
# File 'lib/calamum/resource.rb', line 5 def tryit @tryit end |
#uri ⇒ Object
Returns the value of attribute uri.
5 6 7 |
# File 'lib/calamum/resource.rb', line 5 def uri @uri end |
Instance Method Details
#action_label ⇒ String
Returns a string representing a label css class.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/calamum/resource.rb', line 35 def action_label case @action when 'GET' 'label-info' when 'POST' 'label-success' when 'PUT' 'label-warning' when 'DELETE' 'label-important' end end |
#slug ⇒ String
Returns a unique, but readable name for this resource suitable for use as a filename
26 27 28 29 |
# File 'lib/calamum/resource.rb', line 26 def slug sanitized_uri = uri.gsub(/[^\w]/, '_').gsub('__', '_') "#{sanitized_uri}_#{action.downcase}_#{self.object_id}" end |
#to_s ⇒ String
Returns a string representing a resource.
52 53 54 |
# File 'lib/calamum/resource.rb', line 52 def to_s "#{action}: #{uri}" end |