Sha256: fe0a3d96e7773240f0c455af466b58bfcfb33b7aed84fb024c1dcda670610fa0

Contents?: true

Size: 737 Bytes

Versions: 8

Compression:

Stored size: 737 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 = Request.new :resource => Attachment, :scope => self
      req.where opts
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
reviewed-0.7.1 lib/reviewed/attachable.rb
reviewed-0.7 lib/reviewed/attachable.rb
reviewed-0.6.4 lib/reviewed/attachable.rb
reviewed-0.6.3 lib/reviewed/attachable.rb
reviewed-0.6.2 lib/reviewed/attachable.rb
reviewed-0.6.1 lib/reviewed/attachable.rb
reviewed-0.6.0 lib/reviewed/attachable.rb
reviewed-0.5.0 lib/reviewed/attachable.rb