Sha256: 48cc6a045e5cd46677048b64f79706a1012755067569938efc7d584e9f42ce61

Contents?: true

Size: 713 Bytes

Versions: 14

Compression:

Stored size: 713 Bytes

Contents

module My
  module Nested
    module Remixable
      module Rating

        def self.included(base)
          base.extend ClassMethods
        end

        include DataMapper::Resource

        is :remixable

        # properties

        property :id, Serial
        property :user_id, Integer, :required => true
        property :rating,  Integer, :required => true, :default => 0

        module ClassMethods

          # total rating for all rateable instances of this type
          def total_rating
            rating_sum = self.sum(:rating).to_f
            rating_count = self.count.to_f
            rating_count > 0 ? rating_sum / rating_count : 0
          end

        end

      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
dm-is-remixable-1.2.0 spec/data/rating.rb
dm-is-remixable-1.2.0.rc2 spec/data/rating.rb
dm-is-remixable-1.2.0.rc1 spec/data/rating.rb
dm-is-remixable-1.1.0 spec/data/rating.rb
dm-is-remixable-1.1.0.rc3 spec/data/rating.rb
dm-is-remixable-1.1.0.rc2 spec/data/rating.rb
dm-is-remixable-1.1.0.rc1 spec/data/rating.rb
dm-is-remixable-1.0.2 spec/data/rating.rb
dm-is-remixable-1.0.1 spec/data/rating.rb
dm-is-remixable-1.0.0 spec/data/rating.rb
dm-is-remixable-1.0.0.rc3 spec/data/rating.rb
dm-is-remixable-1.0.0.rc2 spec/data/rating.rb
dm-is-remixable-1.0.0.rc1 spec/data/rating.rb
dm-is-remixable-0.10.2 spec/data/rating.rb