Class: Roaster::Decorator

Inherits:
Representable::Decorator
  • Object
show all
Defined in:
lib/roaster/decorator.rb

Direct Known Subclasses

JsonApi::Mapping

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.can_filter_by(*attrs) ⇒ Object



14
15
16
17
# File 'lib/roaster/decorator.rb', line 14

def can_filter_by(*attrs)
  representable_attrs[:_filterable_attributes] ||= []
  representable_attrs[:_filterable_attributes].push(*attrs.map(&:to_sym)).uniq!
end

.can_include(*attrs) ⇒ Object



42
43
44
45
# File 'lib/roaster/decorator.rb', line 42

def can_include(*attrs)
  representable_attrs[:_includeable_attributes] ||= []
  representable_attrs[:_includeable_attributes].push(*attrs.map(&:to_sym)).uniq!
end

.can_sort_by(*attrs) ⇒ Object

TODO: Disallow sorting directly by relationship (need relationship field)



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/roaster/decorator.rb', line 25

def can_sort_by(*attrs)
  representable_attrs[:_sortable_attributes] ||= []
  sort_keys = attrs.map do |option|
    if option.class == Hash
      { option.first[0].to_sym => option.first[1].map(&:to_sym) }
    else
      option.to_sym
    end
  end
  representable_attrs[:_sortable_attributes].push(*sort_keys).uniq!
end

.filterable_attributesObject



19
20
21
22
# File 'lib/roaster/decorator.rb', line 19

def filterable_attributes
  representable_attrs[:_filterable_attributes] ||= []
  representable_attrs[:_filterable_attributes]
end

.get_resource_nameObject



52
53
54
55
56
57
58
# File 'lib/roaster/decorator.rb', line 52

def get_resource_name
  if defined? @@overloaded_resource_name
    @@overloaded_resource_name
  else
    self.to_s.gsub(/Mapping\Z/, '').underscore.pluralize
  end
end

.includeable_attributesObject



47
48
49
50
# File 'lib/roaster/decorator.rb', line 47

def includeable_attributes
  representable_attrs[:_includeable_attributes] ||= []
  representable_attrs[:_includeable_attributes]
end

.resource_name(name) ⇒ Object



60
61
62
# File 'lib/roaster/decorator.rb', line 60

def resource_name(name)
  @@overloaded_resource_name = name
end

.sortable_attributesObject



37
38
39
40
# File 'lib/roaster/decorator.rb', line 37

def sortable_attributes
  representable_attrs[:_sortable_attributes] ||= []
  representable_attrs[:_sortable_attributes]
end

Instance Method Details

#resource_idObject



8
9
10
# File 'lib/roaster/decorator.rb', line 8

def resource_id
  self.represented.attributes['id']
end