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



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

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

.can_include(*attrs) ⇒ Object



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

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)



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/roaster/decorator.rb', line 30

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



24
25
26
27
# File 'lib/roaster/decorator.rb', line 24

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

.includeable_attributesObject



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

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

.resource_name(name) ⇒ Object



57
58
59
# File 'lib/roaster/decorator.rb', line 57

def resource_name(name)
  @@overloaded_resource_name = name
end

.sortable_attributesObject



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

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

Instance Method Details

#resource_nameObject



8
9
10
11
12
13
14
# File 'lib/roaster/decorator.rb', line 8

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