Class: Almodovar::ResourcePresenter

Inherits:
Object
  • Object
show all
Extended by:
Metadata
Defined in:
lib/almodovar-server/resource_presenter.rb,
lib/almodovar-server/resource_presenter/link.rb,
lib/almodovar-server/resource_presenter/metadata.rb,
lib/almodovar-server/resource_presenter/collection.rb,
lib/almodovar-server/resource_presenter/serializer.rb,
lib/almodovar-server/resource_presenter/xml_serializer.rb,
lib/almodovar-server/resource_presenter/html_serializer.rb,
lib/almodovar-server/resource_presenter/json_serializer.rb

Defined Under Namespace

Modules: Metadata Classes: Collection, HtmlSerializer, JsonSerializer, Link, Serializer, XmlSerializer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Metadata

attribute, desc, inherited, link, metadata

Instance Attribute Details

#urlObject

Returns the value of attribute url.



13
14
15
# File 'lib/almodovar-server/resource_presenter.rb', line 13

def url
  @url
end

Class Method Details

.resource_typeObject



23
24
25
# File 'lib/almodovar-server/resource_presenter.rb', line 23

def self.resource_type
  name.gsub(/Resource$/, '').underscore
end

Instance Method Details



51
52
53
# File 'lib/almodovar-server/resource_presenter.rb', line 51

def all_links
  ([link_to_self] + links).compact
end

#as_json(options = {}) ⇒ Object



43
44
45
# File 'lib/almodovar-server/resource_presenter.rb', line 43

def as_json(options = {})
  JsonSerializer.new(self, options).as_json
end

#attributesObject



15
16
17
# File 'lib/almodovar-server/resource_presenter.rb', line 15

def attributes
  @attributes ||= ActiveSupport::OrderedHash.new
end


55
56
57
# File 'lib/almodovar-server/resource_presenter.rb', line 55

def link_to_self
  Link.new(:self, @url) if @url
end


19
20
21
# File 'lib/almodovar-server/resource_presenter.rb', line 19

def links
  @links ||= []
end

#resource_classObject



27
28
29
# File 'lib/almodovar-server/resource_presenter.rb', line 27

def resource_class
  self.class
end

#resource_typeObject



31
32
33
# File 'lib/almodovar-server/resource_presenter.rb', line 31

def resource_type
  resource_class.resource_type
end

#to_html(options = {}) ⇒ Object



47
48
49
# File 'lib/almodovar-server/resource_presenter.rb', line 47

def to_html(options = {})
  HtmlSerializer.new(self, options).to_html
end

#to_json(options = {}) ⇒ Object



39
40
41
# File 'lib/almodovar-server/resource_presenter.rb', line 39

def to_json(options = {})
  JsonSerializer.new(self, options).to_json
end

#to_xml(options = {}) ⇒ Object



35
36
37
# File 'lib/almodovar-server/resource_presenter.rb', line 35

def to_xml(options = {})
  XmlSerializer.new(self, options).to_xml
end