Sha256: 3ed6c26c3213523c1d3c7f452fe1d34bf2c3691c33d4f49ceab68c236090cef8
Contents?: true
Size: 1.71 KB
Versions: 1
Compression:
Stored size: 1.71 KB
Contents
module ActsAsAmico module AmicoObject def self.included(base) base.extend ClassMethods end module ClassMethods def amico_key @amico_key ||= :id end def acts_as_amico *args options = args.extract_options! options.assert_valid_keys(:amico_key) @amico_key = options[:amico_key] include ActsAsAmico::AmicoObject::InstanceMethods end end module InstanceMethods def amico_key self.send(self.class.amico_key) end def method_missing(sym, *args, &block) if Amico.respond_to? sym args[0] = args[0].amico_key if not args[0].nil? and args[0].respond_to?(:amico_key) args.unshift(amico_key) if sym.nil? Amico.send(*args, &block) else Amico.send(sym, *args, &block) end else super end end def respond_to?(sym) pass_sym_to_amico(sym) || super(sym) end def followers options = {} key = options[:scope] || Amico.default_scope_key Amico.followers(amico_key, options, key) end # Named destructive methods def follow! obj, *args Amico.follow(amico_key, obj.amico_key, *args) end def unfollow! obj, *args Amico.unfollow(amico_key, obj.amico_key, *args) end def accept! obj, *args Amico.accept(amico_key, obj.amico_key, *args) end def block! obj, *args Amico.block(amico_key, obj.amico_key, *args) end def unblock! obj, *args Amico.unblock(amico_key, obj.amico_key, *args) end private def pass_sym_to_amico sym Amico.respond_to? sym end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
acts_as_amico-0.2.2 | lib/acts_as_amico/amico_object.rb |