class Roaster::Decorator
Public Class Methods
can_filter_by(*attrs)
click to toggle source
# File lib/roaster/decorator.rb, line 27 def can_filter_by(*attrs) representable_attrs[:_filterable_attributes] ||= [] representable_attrs[:_filterable_attributes].push(*attrs.map(&:to_sym)).uniq! end
can_include(*attrs)
click to toggle source
# File lib/roaster/decorator.rb, line 55 def can_include(*attrs) representable_attrs[:_includeable_attributes] ||= [] representable_attrs[:_includeable_attributes].push(*attrs.map(&:to_sym)).uniq! end
can_sort_by(*attrs)
click to toggle source
TODO: Disallow sorting directly by relationship (need relationship field)
# File lib/roaster/decorator.rb, line 38 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_attributes()
click to toggle source
# File lib/roaster/decorator.rb, line 32 def filterable_attributes representable_attrs[:_filterable_attributes] ||= [] representable_attrs[:_filterable_attributes] end
get_resource_name()
click to toggle source
# File lib/roaster/decorator.rb, line 65 def get_resource_name if defined? @@overloaded_resource_name @@overloaded_resource_name else self.to_s.gsub(/Mapping\Z/, '').underscore.pluralize end end
has_many(name)
click to toggle source
PING: Overriding build_definition is maybe required
# File lib/roaster/decorator.rb, line 21 def has_many(name) representable_attrs[:_has_many] ||= [] collection name representable_attrs[:_has_many].push({key: name.to_s.singularize + '_ids', name: name.to_s}) end
has_one(name)
click to toggle source
# File lib/roaster/decorator.rb, line 14 def has_one(name) representable_attrs[:_has_one] ||= [] property name representable_attrs[:_has_one].push({key: name.to_s + '_id', name: name.to_s}) end
includeable_attributes()
click to toggle source
# File lib/roaster/decorator.rb, line 60 def includeable_attributes representable_attrs[:_includeable_attributes] ||= [] representable_attrs[:_includeable_attributes] end
resource_name(name)
click to toggle source
# File lib/roaster/decorator.rb, line 73 def resource_name(name) @@overloaded_resource_name = name end
sortable_attributes()
click to toggle source
# File lib/roaster/decorator.rb, line 50 def sortable_attributes representable_attrs[:_sortable_attributes] ||= [] representable_attrs[:_sortable_attributes] end
Public Instance Methods
resource_id()
click to toggle source
# File lib/roaster/decorator.rb, line 8 def resource_id self.represented.attributes['id'] end