public
Description: Ruby on Rails plugin based on NamedScope to select single columns without crippling your code.
Homepage: www.monkey-patch.me/column_scope
Clone URL: git://github.com/boof/column_scope.git
boof (author)
Fri Jan 02 04:46:11 -0800 2009
commit  bef057bad6ab03bc08e1b52a3c85f984694f765a
tree    2bc30c472502efc5d99696a4b0142f523ec9ca4b
parent  2728648e199520be755207ff5f6c47b35b57b0a3
name age message
file MIT-LICENSE Loading commit data...
file README.rdoc
file Rakefile
file init.rb
directory lib/
directory test/
README.rdoc

ColumnScope

Selecting only specified columns can safe you resources and processing time.

I wrote this plugin because I do this all the time and I don’t want to cripple my code anymore.

ColumnScope is build on top of NamedScope so it only works with Ruby on Rails 2.1+.

Examples:

  Item.selects(:name).proxy_options[:select] # => '"items"."name"'

  content = 'Foo Bar Baz'

  Item.create :name => 'foo', :value => 1, :content => content
  Item.create :name => 'bar', :value => 2, :content => content
  Item.create :name => 'baz', :value => 3, :content => content

  Item.selects(:name).values.all :order => 'id' # => %w[foo bar baz]

  # use a shortcut to retrieve values of name and content distinct
  Item.select_first :distinct_name__content # => ['foo', content]

  # without shortcut
  Item.selects(:name, :content).uniq!.values.all # => ['foo', content]

  # reject named columns in scope :a_named_scope and select only the values
  Item.a_named_scope.rejects(:content).values.all # => [[1, 'foo', 1], ...]

See test/column_scope_test.rb for more examples.

Install (rails):

  $ script/plugin install git://github.com/boof/column_scope.git

  # alternativly:
  $ cd vendor/plugins
  $ git clone git://github.com/boof/column_scope.git

Copyright © 2008 Florian Aßmann, released under the MIT license