Sha256: 0c633ae0979f8d8aecbff8ce7e1ba6e55bf2e37ea7787f62c74483940337750c

Contents?: true

Size: 717 Bytes

Versions: 1

Compression:

Stored size: 717 Bytes

Contents

module Reviewed
  module Attachable

    def attachments tag=nil, opts={}
      if default_attachments.include?(tag.to_s)
        return attributes['attachments'].select { |x| x.tags.include?(tag.to_s) }
      else
        fetch_attachments(opts.merge!(tags: tag)).to_a
      end
    end

    def gallery tags=nil, num=8, page=1
      fetch_attachments tags: tags, :gallery => true, :per_page => num, :page => page, :order => 'priority'
    end

    private

    def default_attachments
      attributes['attachments'] ||= []
      attributes['attachments'].map(&:tags).flatten.uniq.compact
    end

    def fetch_attachments opts={}
      req = client.attachments(scope: self)
      req.where opts
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reviewed-0.8.0 lib/reviewed/attachable.rb