Sha256: 73077046dfa2efefe2e4eef702e1d99a0bb1748d147ba702c4c036a2aeece6e1

Contents?: true

Size: 1.28 KB

Versions: 10

Compression:

Stored size: 1.28 KB

Contents

module Almodovar
  
  class ResourcePresenter
    
    autoload :Serializer,     'almodovar/resource_presenter/serializer'
    autoload :XmlSerializer,  'almodovar/resource_presenter/xml_serializer'
    autoload :JsonSerializer, 'almodovar/resource_presenter/json_serializer'
    autoload :HtmlSerializer, 'almodovar/resource_presenter/html_serializer'
    autoload :Metadata,       'almodovar/resource_presenter/metadata'

    extend Metadata

    attr_accessor :url
    
    def attributes
      @attributes ||= ActiveSupport::OrderedHash.new
    end
    
    def links
      @links ||= []
    end
    
    def self.resource_type
      name.gsub(/Resource$/, '').underscore
    end
    
    def resource_class
      self.class
    end

    def resource_type
      resource_class.resource_type
    end

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

    def to_html(options = {})
      HtmlSerializer.new(self, options).to_html
    end
    
    def all_links
      ([link_to_self] + links).compact
    end
    
    def link_to_self
      Link.new(:self, @url) if @url
    end

  end
  
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
almodovar-0.9.8 lib/almodovar/resource_presenter.rb
almodovar-0.9.7 lib/almodovar/resource_presenter.rb
almodovar-0.9.6 lib/almodovar/resource_presenter.rb
almodovar-0.9.5 lib/almodovar/resource_presenter.rb
almodovar-0.9.4 lib/almodovar/resource_presenter.rb
almodovar-0.9.2 lib/almodovar/resource_presenter.rb
almodovar-0.9.3 lib/almodovar/resource_presenter.rb
almodovar-0.9.1 lib/almodovar/resource_presenter.rb
almodovar-0.9.0 lib/almodovar/resource_presenter.rb
almodovar-0.8.0 lib/almodovar/resource_presenter.rb