Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of git@github.com:weppos/activerecord-multicond…

…itions
  • Loading branch information...
commit e34217c0975ed7bb42c9a6c88e8b7a5aa5d6f5b5 2 parents c5bab14 + fb44c57
Simone Carletti authored
5 .gitignore
View
@@ -1,2 +1,5 @@
+*.gemspec
+Manifest
nbproject
-test/db/*.sqlite3
+pkg
+test/db/*.sqlite3
2  CHANGELOG
View
@@ -1,5 +1,5 @@
= Changelog
-== Release 0.0.0
+== Release 0.1.0
* Initial public release.
189 README
View
@@ -0,0 +1,189 @@
+= ActiveRecord::MultiConditions
+
+MultiConditions is a simple ActiveRecord plugin for storing ActiveRecord query conditions and make complex queries painless.
+
+
+== Overview
+
+This plugin doesn't replace ActiveRecord#with_scope method,
+nor the basic :condition usage but extends it with the ability
+of storing illimitate conditions in multiple step.
+
+ conditions = MultiConditions.new
+ # ... do some elaboration
+ conditions.append_condition(['active = ? AND query LIKE ?', true, '%foo']
+ # ... other elaboration
+ conditions.append_condition(['name = ?', 'aname']
+
+ conditions.to_conditions
+ # => "active = true AND query LIKE '%foo' AND name = 'aname'"
+
+
+== Dependencies
+
+* Ruby 1.8.6
+* ActiveRecord 2.0 (or greater)
+
+If you want to run the test suite:
+
+* sqlite3-ruby
+
+
+== Source
+
+MultiConditions source code is managed via GIT and hosted at GitHub: http://github.com/weppos/activerecord-multiconditions/.
+
+
+== Download and Installation
+
+Installing ActiveRecord MultiConditions as a GEM is probably the best and easiest way. You must have {RubyGems}[http://rubyforge.org/projects/rubygems/] installed for the following instruction to work:
+
+ $ sudo gem install activerecord-multiconditions
+
+To install the library manually grab the source code from the website, navigate to the root library directory and enter:
+
+ $ sudo ruby setup.rb
+
+If you need the latest development version you can download the source code from the GIT repositories listed above. Beware that the code might not as stable as the official release.
+
+
+== Usage
+
+First, don't forget to require the library.
+
+ gem 'activerecord-multiconditions'
+ require 'multi_conditions'
+
+Now +MultiConditions+ object is automatically available as subclass of any ActiveRecord object.
+
+ class Task < ActiveRecord::Base; end
+
+ multiconditions = Task::Multiconditions.new
+ # => new instance
+
+=== Create a new instance
+
+As stated by the Important section above, you first need a valid ActiveRecord model
+to create a MultiConditions instance.
+Because MultiConditions helps you to deal with ActiveRecord queries,
+it's easy to understand why you *MUST* establish a valid database connection
+and have at least one table (mapped with a Model) to query.
+
+If you use ActiveRecord from Rails, this is just a matter of creating a new Model.
+
+ # create the Task model
+ class Task < ActiveRecord::Base
+ end
+
+Now MultiConditions is automatically available within your Task namespace.
+You can use it in whatever class method, for example:
+
+ class Task < ActiveRecord::Base
+
+ def complex_search()
+ c = MultiConditions.new(:foo => 'bar')
+ Task.find(:all, c.to_conditions)
+ end
+
+ end
+
+But you can also create a new instance from an other library, class or model.
+Just remember to initialize MultiConditions from its own namespace.
+
+ class Foo
+ class << self
+ def my_cool_conditions
+ Task::MultiConditions.new(:foo => 1).to_conditions
+ end
+ end
+ end
+
+ Foo.my_cool_conditions
+ # => 'foo = 1'
+
+=== Appending conditions
+
+You can append new conditions calling
+
+* #append_condition
+* #prepend_condition
+
+and passing the conditions you want to append or prepend.
+See Condition Types section to lean more about supported objects.
+
+ conditions = MultiConditions.new
+ conditions.append_condition(['active = ? AND query LIKE ?', true, '%foo']
+ conditions.prepend_condition(['name = ?', 'aname']
+
+ conditions.to_conditions
+ # => "name = 'aname' AND active = true AND query LIKE '%foo'"
+
+
+=== Condition types
+
+The MultiConditions object accepts any type of conditions supported by ActiveRecord,
+including Strings, Arrays and Hashes, and merges them alltogether
+just before sending the final :condition value to ActiveRecord search method.
+
+ conditions = MultiConditions.new
+ conditions.append_conditions(:foo => 1, :bar => 2)
+ conditions.append_conditions('active = 1')
+ conditions.append_conditions(['name LIKE ?', '%foo'])
+
+ conditions.to_conditions
+ # => 'foo = 1 AND :bar = 2 AND active = 1 AND name LIKE '%foo'
+
+See ActiveRecord::Base#find documentation for more conditions examples.
+
+
+
+== Important
+
+Once loaded, this library become part of ActiveRecord package and
+creates its own namespace at ActiveRecord::Base::MultiConditions.
+
+ require 'multi_conditions'
+
+For various reason, you cannot initialize a new ActiveRecord::Base::MultiConditions
+but you *MUST* initialize a MultiConditions instance from a Model.
+
+ # The wrong way
+ # raises Message: <"undefined method `abstract_class?' for Object:Class">
+ ActiveRecord::Base::MultiConditions.new
+
+ # The right way
+ class Model < ActiveRecord::Base
+
+ def a_method()
+ c = MultiConditions.new
+ find(:all, :conditions => c.to_conditions)
+ end
+
+ end
+
+
+== Author
+
+* {Simone Carletti}[http://www.simonecarletti.com/] <weppos@weppos.net>
+
+If you like this software, please {recommend me}[http://www.workingwithrails.com/person/11967-simone-carletti] at Working with Rails.
+
+
+== Website and Project Home
+
+* {Project Homepage}[http://code.simonecarletti.com/activerecord-multiconditions]
+* {At GitHub}[http://github.com/weppos/activerecord-multiconditions/]
+
+
+== FeedBack and Bug reports
+
+Feel free to email {Simone Carletti}[mailto:weppos@weppos.net]
+with any questions or feedback.
+
+Please submit your bug reports to the Redmine installation for MultiConditions
+available at http://code.simonecarletti.com/activerecord-multiconditions.
+
+
+== Changelog
+
+See CHANGELOG file.
1  README
View
171 README.rdoc
View
@@ -1,171 +0,0 @@
-= ActiveRecord::MultiConditions
-
-MultiConditions is a simple ActiveRecord plugin for storing ActiveRecord
-query and make complex queries painless.
-
-
-== Overview
-
-This plugin doesn't replace ActiveRecord#with_scope method,
-nor the basic :condition usage but extends it with the ability
-of storing illimitate conditions in multiple step.
-
- conditions = MultiConditions.new
- # ... do some elaboration
- conditions.append_condition(['active = ? AND query LIKE ?', true, '%foo']
- # ... other elaboration
- conditions.append_condition(['name = ?', 'aname']
-
- conditions.to_conditions
- # => "active = true AND query LIKE '%foo' AND name = 'aname'"
-
-
-== Dependencies
-
-* Ruby 1.8.6
-* ActiveRecord 2.0 (or greater)
-
-If you want to run the test suite:
-
-* sqlite3-ruby
-
-
-== Source
-
-MultiConditions source code is managed via GIT and hosted at GitHub: http://github.com/weppos/activerecord-multiconditions/.
-
-
-== Download and Installation
-
-MultiConditions is at the beginning of development stage.
-It's stable enough to be used, but at the moment the only way to install it
-is to grab the source code and install it manually.
-
-In a few days it will be packaged as a GEM.
-Stay tuned!
-
-
-== Usage
-
-=== Create a new instance
-
-As stated by the Important section above, you first need a valid ActiveRecord model
-to create a MultiConditions instance.
-Because MultiConditions helps you to deal with ActiveRecord queries,
-it's easy to understand why you *MUST* establish a valid database connection
-and have at least one table (mapped with a Model) to query.
-
-If you use ActiveRecord from Rails, this is just a matter of creating a new Model.
-
- # create the Task model
- class Task < ActiveRecord::Base
- end
-
-Now MultiConditions is automatically available within your Task namespace.
-You can use it in whatever class method, for example:
-
- class Task < ActiveRecord::Base
-
- def complex_search()
- c = MultiConditions.new(:foo => 'bar')
- Task.find(:all, c.to_conditions)
- end
-
- end
-
-But you can also create a new instance from an other library, class or model.
-Just remember to initialize MultiConditions from its own namespace.
-
- class Foo
- class << self
- def my_cool_conditions
- Task::MultiConditions.new(:foo => 1).to_conditions
- end
- end
- end
-
- Foo.my_cool_conditions
- # => 'foo = 1'
-
-=== Appending conditions
-
-You can append new conditions calling
-
-* #append_condition
-* #prepend_condition
-
-and passing the conditions you want to append or prepend.
-See Condition Types section to lean more about supported objects.
-
- conditions = MultiConditions.new
- conditions.append_condition(['active = ? AND query LIKE ?', true, '%foo']
- conditions.prepend_condition(['name = ?', 'aname']
-
- conditions.to_conditions
- # => "name = 'aname' AND active = true AND query LIKE '%foo'"
-
-
-=== Condition types
-
-The MultiConditions object accepts any type of conditions supported by ActiveRecord,
-including Strings, Arrays and Hashes, and merges them alltogether
-just before sending the final :condition value to ActiveRecord search method.
-
- conditions = MultiConditions.new
- conditions.append_conditions(:foo => 1, :bar => 2)
- conditions.append_conditions('active = 1')
- conditions.append_conditions(['name LIKE ?', '%foo'])
-
- conditions.to_conditions
- # => 'foo = 1 AND :bar = 2 AND active = 1 AND name LIKE '%foo'
-
-See ActiveRecord::Base#find documentation for more conditions examples.
-
-
-
-== Important
-
-Once loaded, this library become part of ActiveRecord package and
-creates its own namespace at ActiveRecord::Base::MultiConditions.
-
-For various reason, you cannot initialize a new ActiveRecord::Base::MultiConditions
-but you *MUST* initialize a MultiConditions instance from a Model.
-
- # The wrong way
- # raises Message: <"undefined method `abstract_class?' for Object:Class">
- ActiveRecord::Base::MultiConditions.new
-
- # The right way
- class Model < ActiveRecord::Base
-
- def a_method()
- c = MultiConditions.new
- find(:all, :conditions => c.to_conditions)
- end
-
- end
-
-
-== Author
-
-* {Simone Carletti}[http://www.simonecarletti.com/] <weppos@weppos.net>
-
-
-== Website and Project Home
-
-* {Project Homepage}[http://code.simonecarletti.com/activerecord-multiconditions]
-* {At GitHub}[http://github.com/weppos/activerecord-multiconditions/]
-
-
-== FeedBack and Bug reports
-
-Feel free to email {Simone Carletti}[mailto:weppos@weppos.net]
-with any questions or feedback.
-
-Please submit your bug reports to the Redmine installation for MultiConditions
-available at http://code.simonecarletti.com/activerecord-multiconditions.
-
-
-== Changelog
-
-See CHANGELOG file.
58 Rakefile
View
@@ -0,0 +1,58 @@
+require 'rubygems'
+require 'echoe'
+
+$LOAD_PATH.unshift(File.dirname(__FILE__) + "/lib")
+require 'multi_conditions'
+
+
+# Common package properties
+PKG_NAME = ENV['PKG_NAME'] || ActiveRecord::Base::MultiConditions::GEM
+PKG_VERSION = ENV['PKG_VERSION'] || ActiveRecord::Base::MultiConditions::VERSION
+PKG_SUMMARY = "An ActiveRecord plugin for dealing with complex search :conditions."
+PKG_FILES = FileList.new("{lib,test}/**/*.rb") do |fl|
+ fl.exclude 'TODO'
+ fl.include %w(README.rdoc README CHANGELOG MIT-LICENSE)
+ fl.include %w(Rakefile setup.rb)
+end
+RUBYFORGE_PROJECT = 'activerecord-multiconditions'
+
+if ENV['SNAPSHOT'].to_i == 1
+ PKG_VERSION << "." << Time.now.utc.strftime("%Y%m%d%H%M%S")
+end
+
+
+Echoe.new(PKG_NAME, PKG_VERSION) do |p|
+ p.author = "Simone Carletti"
+ p.email = "weppos@weppos.net"
+ p.summary = PKG_SUMMARY
+ p.description = <<-EOF
+ MultiConditions is a simple ActiveRecord plugin \
+ for storing ActiveRecord query conditions and make complex queries painless.
+ EOF
+ p.url = "http://code.simonecarletti.com/activerecord-multiconditions"
+
+ p.version = PKG_VERSION
+ p.changes = ''
+
+ p.dependencies = ['activerecord >=2.0.0']
+ p.rcov_options = ["-xRakefile"]
+
+ p.need_zip = true
+ p.include_rakefile = true
+
+ p.project = RUBYFORGE_PROJECT
+
+ p.rdoc_pattern = /^(lib|CHANGELOG|MIT\-LICENSE|README)/
+end
+
+
+begin
+ require 'code_statistics'
+ desc "Show library's code statistics"
+ task :stats do
+ CodeStatistics.new(["MultiConditions", "lib"],
+ ["Tests", "test"]).to_s
+ end
+rescue LoadError
+ puts "CodeStatistics (Rails) is not available"
+end
16 lib/multi_conditions.rb
View
@@ -75,21 +75,21 @@ class Base
#
class MultiConditions
- NAME = 'ActiveRecord::MultiConditions'
- GEM = 'activerecord-multiconditions'
- AUTHOR = 'Simone Carletti <weppos@weppos.net>'
- VERSION = defined?(Version) ? Version::STRING : nil
- STATUS = 'alpha'
- BUILD = ''.match(/(\d+)/).to_a.first
-
module Version #:nodoc:
MAJOR = 0
- MINOR = 0
+ MINOR = 1
TINY = 0
STRING = [MAJOR, MINOR, TINY].join('.')
end
+ NAME = 'ActiveRecord::MultiConditions'
+ GEM = 'activerecord-multiconditions'
+ AUTHOR = 'Simone Carletti <weppos@weppos.net>'
+ VERSION = defined?(Version) ? Version::STRING : nil
+ STATUS = 'alpha'
+ BUILD = ''.match(/(\d+)/).to_a.first
+
# Conditions collection
attr_reader :conditions
16 lib/multiconditions.rb
View
@@ -0,0 +1,16 @@
+#
+# = ActiveRecord::MultiConditions
+#
+# An ActiveRecord plugin for dealing with complex search :conditions.
+#
+#
+# Category:: ActiveRecord
+# Package:: ActiveRecord::MultiConditions
+# Author:: Simone Carletti <weppos@weppos.net>
+#
+#--
+# SVN: $Id$
+#++
+
+
+require 'multi_conditions'
16 test/test_all.rb
View
@@ -0,0 +1,16 @@
+#
+# = ActiveRecord::MultiConditions
+#
+# An ActiveRecord plugin for dealing with complex search :conditions.
+#
+#
+# Category:: ActiveRecord
+# Package:: ActiveRecord::MultiConditions
+# Author:: Simone Carletti <weppos@weppos.net>
+#
+#--
+# SVN: $Id$
+#++
+
+
+Dir.glob(File.dirname(__FILE__) + '/unit/**/*_test.rb').sort.each { |unit| require unit }
0  test/unit/test_multi_conditions.rb → test/unit/multi_conditions_test.rb
View
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.