Sha256: 1abc7585bb5e8be57d5d512e77b0ed5eefd1a92385bf463c63c094cfbd97e80f

Contents?: true

Size: 783 Bytes

Versions: 2

Compression:

Stored size: 783 Bytes

Contents

require 'active_support/concern'
require 'active_support/inflector'

module Roar
  module Contrib
    module Decorator
      module CollectionRepresenter
        extend ActiveSupport::Concern

        module ClassMethods
          def resource_representer
            (name.chomp('Representer').singularize << 'Representer').constantize
          end

          def represented_collection_name
            name.demodulize.chomp('Representer').underscore.pluralize
          end
        end

        included do
          define_method represented_collection_name do
            represented
          end

          collection represented_collection_name,
            :exec_context => :decorator,
            :decorator => resource_representer
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
roar-contrib-0.0.1 lib/roar/contrib/decorator/collection_representer.rb
roar-contrib-0.0.1.alpha1 lib/roar/contrib/decorator/collection_representer.rb