Class: Yaks::Resource

Inherits:
Object
  • Object
show all
Extended by:
Util::Deprecated
Defined in:
lib/yaks/resource.rb,
lib/yaks/resource/form.rb,
lib/yaks/resource/link.rb,
lib/yaks/resource/form/field.rb,
lib/yaks/resource/has_fields.rb,
lib/yaks/resource/form/legend.rb,
lib/yaks/resource/form/fieldset.rb,
lib/yaks/resource/form/field/option.rb

Direct Known Subclasses

CollectionResource, NullResource

Defined Under Namespace

Modules: HasFields Classes: Form, Link

Instance Method Summary collapse

Methods included from Util::Deprecated

deprecated_alias

Constructor Details

#initialize(attrs = {}) ⇒ Resource

Returns a new instance of Resource.



13
14
15
16
# File 'lib/yaks/resource.rb', line 13

def initialize(attrs = {})
  raise attrs.inspect if attrs.key?(:subresources) && !attrs[:subresources].instance_of?(Array)
  super
end

Instance Method Details

#[](attr) ⇒ Object



18
19
20
# File 'lib/yaks/resource.rb', line 18

def [](attr)
  attributes[attr]
end

#add_form(form) ⇒ Object



80
81
82
# File 'lib/yaks/resource.rb', line 80

def add_form(form)
  append_to(:forms, form)
end


76
77
78
# File 'lib/yaks/resource.rb', line 76

def add_link(link)
  append_to(:links, link)
end

#add_rel(rel) ⇒ Object



72
73
74
# File 'lib/yaks/resource.rb', line 72

def add_rel(rel)
  append_to(:rels, rel)
end

#add_subresource(subresource) ⇒ Object



84
85
86
# File 'lib/yaks/resource.rb', line 84

def add_subresource(subresource)
  append_to(:subresources, subresource)
end

#collection?Boolean Also known as: collection

Returns:

  • (Boolean)


46
47
48
# File 'lib/yaks/resource.rb', line 46

def collection?
  false
end

#find_form(name) ⇒ Object



22
23
24
# File 'lib/yaks/resource.rb', line 22

def find_form(name)
  forms.find { |form| form.name.equal? name }
end

#membersObject Also known as: each, map, each_with_object, with_members



59
60
61
# File 'lib/yaks/resource.rb', line 59

def members
  raise UnsupportedOperationError, "Only Yaks::CollectionResource has members"
end

#merge_attributes(new_attrs) ⇒ Object



67
68
69
# File 'lib/yaks/resource.rb', line 67

def merge_attributes(new_attrs)
  with(attributes: @attributes.merge(new_attrs))
end

#null_resource?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/yaks/resource.rb', line 55

def null_resource?
  false
end


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/yaks/resource.rb', line 30

def self_link
  # This reverse is there so that the last :self link specified
  # "wins". The use case is having a self link defined in a base
  # mapper class, but having it overridden in specific
  # subclasses. In combination with formats that expect resources
  # to have up to one self link, this is the preferred behavior.
  # However since 0.7.5 links take a "replace: true" option to
  # specifiy they should replace previous defintions with the same
  # rel, wich should be used instead. The behavior that the last
  # link "wins" will be deprecated, the result of multiple links
  # with the same rel will be unspecified.
  links.reverse.find do |link|
    link.rel.equal? :self
  end
end

#seqObject



26
27
28
# File 'lib/yaks/resource.rb', line 26

def seq
  [self]
end

#with_collectionObject



51
52
53
# File 'lib/yaks/resource.rb', line 51

def with_collection(*)
  self
end