Sha256: 4fbe9cfca0361c826e0c73b7832668245ac93fb492e805c28f4ea29c2c7dd6c9

Contents?: true

Size: 944 Bytes

Versions: 3

Compression:

Stored size: 944 Bytes

Contents

module NewspaperWorks
  module Data
    # Mixin module for fileset methods for work, presumes an @work
    #   instance attribute refering to a work object
    module FilesetHelper
      def fileset_id
        # if context is itself a string, presume it is a file set id
        return @work if @work.class == String
        # if context is not a String, presume a work or fileset context:
        fileset.nil? ? nil : fileset.id
      end

      def first_fileset
        # if context is fileset id (e.g. caller is view partial) string,
        #   get the fileset from that id
        return FileSet.find(@work) if @work.class == String
        # if "work" context is a FileSet, not actual work, return it
        return @work if @work.class == FileSet
        # in most cases, get from work's members:
        filesets = @work.members.select { |m| m.class == FileSet }
        filesets.empty? ? nil : filesets[0]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
newspaper_works-1.0.1 lib/newspaper_works/data/fileset_helper.rb
newspaper_works-1.0.0 lib/newspaper_works/data/fileset_helper.rb
newspaper_works-0.1.0 lib/newspaper_works/data/fileset_helper.rb