Sha256: bd81d27be4f80259be4c9bf24cd1e82a191b159ab7afecc9a963eed248465c2d

Contents?: true

Size: 942 Bytes

Versions: 12

Compression:

Stored size: 942 Bytes

Contents

module EnjuLibrary
  module LibraryItem
    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods
      def enju_library_item_model
        include InstanceMethods
        has_one :accept
        scope :accepted_between, lambda{|from, to| includes(:accept).where('items.created_at BETWEEN ? AND ?', Time.zone.parse(from).beginning_of_day, Time.zone.parse(to).end_of_day)}

        belongs_to :shelf, counter_cache: true, validate: true
        validates_associated :shelf

        searchable do
          string :library do
            shelf.library.name if shelf
          end
        end
      end
    end

    module InstanceMethods
      def shelf_name
        shelf.name
      end

      def hold?(library)
        return true if shelf.library == library
        false
      end

      def library_url
        "#{LibraryGroup.site_config.url}libraries/#{shelf.library.name}"
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
enju_library-0.1.2 lib/enju_library/item.rb
enju_library-0.1.1 lib/enju_library/item.rb
enju_library-0.1.0 lib/enju_library/item.rb
enju_library-0.1.0.pre45 lib/enju_library/item.rb
enju_library-0.1.0.pre44 lib/enju_library/item.rb
enju_library-0.1.0.pre43 lib/enju_library/item.rb
enju_library-0.1.0.pre42 lib/enju_library/item.rb
enju_library-0.1.0.pre41 lib/enju_library/item.rb
enju_library-0.1.0.pre40 lib/enju_library/item.rb
enju_library-0.1.0.pre39 lib/enju_library/item.rb
enju_library-0.1.0.pre38 lib/enju_library/item.rb
enju_library-0.1.0.pre37 lib/enju_library/item.rb