Class: Almodovar::ResourcePresenter::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/almodovar-server/resource_presenter/link.rb

Defined Under Namespace

Classes: JsonSerializer, Serializer, XmlSerializer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Link

Returns a new instance of Link.



7
8
9
10
# File 'lib/almodovar-server/resource_presenter/link.rb', line 7

def initialize(*args)
  @rel, @href, @expand_resource, @expand_args, @attributes = args
  @attributes ||= {}
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



5
6
7
# File 'lib/almodovar-server/resource_presenter/link.rb', line 5

def attributes
  @attributes
end

#expand_argsObject (readonly)

Returns the value of attribute expand_args.



5
6
7
# File 'lib/almodovar-server/resource_presenter/link.rb', line 5

def expand_args
  @expand_args
end

#expand_resourceObject (readonly)

Returns the value of attribute expand_resource.



5
6
7
# File 'lib/almodovar-server/resource_presenter/link.rb', line 5

def expand_resource
  @expand_resource
end

#hrefObject (readonly)

Returns the value of attribute href.



5
6
7
# File 'lib/almodovar-server/resource_presenter/link.rb', line 5

def href
  @href
end

#relObject (readonly)

Returns the value of attribute rel.



5
6
7
# File 'lib/almodovar-server/resource_presenter/link.rb', line 5

def rel
  @rel
end

Instance Method Details

#as_json(options = {}) ⇒ Object



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

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

#expand_resource?Boolean

Returns:

  • (Boolean)


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

def expand_resource?
  expand_resource.present?
end

#resourceObject



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

def resource
  resource_collection? ? resource_collection : single_resource
end

#resource_collectionObject



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

def resource_collection
  ResourcePresenter::Collection.new(expand_resource, expand_args)
end

#resource_collection?Boolean

Returns:

  • (Boolean)


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

def resource_collection?
  expand_args.is_a?(Array)
end

#single_resourceObject



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

def single_resource
  expand_resource.new(*[expand_args].compact)        
end

#to_xml(options = {}) ⇒ Object



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

def to_xml(options = {})
  XmlSerializer.new(self, options.merge(:skip_instruct => true)).to_xml
end