Sha256: 5415c23d85e4fb3b6685f3c251fcbaa274d013517fded792a8440772ce41a446
Contents?: true
Size: 979 Bytes
Versions: 2
Compression:
Stored size: 979 Bytes
Contents
module Bitmarkable module Bitmarked extend ActiveSupport::Concern included do include Redis::Objects unless include?(Redis::Objects) value :bitmark cattr_accessor :url_field after_save :generate_bitmark bitmarks self.url_field || 'url' def generate_bitmark if self.class.respond_to? :delay self.class.delay.save_bitmark(self, "#{Bitmarkable.config.base_url}#{self.send(url_field.to_sym)}") else self.class.save_bitmark(self, "#{Bitmarkable.config.base_url}#{self.send(url_field.to_sym)}") end end end module ClassMethods def bitmarks(url_field = nil) self.url_field = url_field end def save_bitmark(object, url) if defined?(Rails) && !(Rails.env.development? || Rails.env.test?) object.bitmark = Bitly.shorten(url) else object.bitmark = url end end end extend ClassMethods end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
bitmarkable-0.1.2 | lib/bitmarkable/bitmarked.rb |
bitmarkable-0.1.1 | lib/bitmarkable/bitmarked.rb |