Permalink
Browse files

add code

  • Loading branch information...
1 parent af1319f commit 21adb1216a8046ec307008e04914ce5fc60ca3a3 @mokevnin mokevnin committed Feb 27, 2012
Showing with 59 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +4 −0 Gemfile
  3. +1 −0 Rakefile
  4. +23 −0 lib/usefull_scopes.rb
  5. +3 −0 lib/usefull_scopes/version.rb
  6. +24 −0 usefull_scopes.gemspec
View
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
View
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in usefull_scopes.gemspec
+gemspec
View
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
View
@@ -0,0 +1,23 @@
+module UsefullScopes
+ autoload :Version, 'usefull_scopes/version'
+ extend ActiveSupport::Concern
+
+ included do
+ scope :random, order("RANDOM()")
+ scope :exclude, lambda {|id_or_object|
+ value = id_or_object.is_a?(ActiveRecord::Base) ? id_or_object.id : id_or_object
+ return scoped unless value
+ where("#{quoted_table_name}.id != ?", value)
+ }
+
+ attribute_names.each do |a|
+ scope "by_#{a}", order("#{a} DESC")
+ scope "asc_by_#{a}", order("#{a} ASC")
+ scope "like_by_#{a}", lambda {|term|
+ quoted_term = connection.quote(term + '%')
+ where("lower(#{a}) like #{quoted_term}")
+ }
+ end
+ end
+end
+
@@ -0,0 +1,3 @@
+module UsefullScopes
+ VERSION = "0.0.1"
+end
@@ -0,0 +1,24 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "usefull_scopes/version"
+
+Gem::Specification.new do |s|
+ s.name = "usefull_scopes"
+ s.version = UsefullScopes::VERSION
+ s.authors = ["Mokevnin Kirill"]
+ s.email = ["mokevnin@gmail.com"]
+ s.homepage = ""
+ s.summary = %q{TODO: Write a gem summary}
+ s.description = %q{TODO: Write a gem description}
+
+ s.rubyforge_project = "usefull_scopes"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ # specify any dependencies here; for example:
+ # s.add_development_dependency "rspec"
+ # s.add_runtime_dependency "rest-client"
+end

0 comments on commit 21adb12

Please sign in to comment.