JGailor-except 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Changelog +0 -0
- data/History.txt +6 -0
- data/LICENSE +0 -0
- data/Manifest.txt +9 -0
- data/README +48 -0
- data/Rakefile +11 -0
- data/lib/except.rb +22 -0
- data/test/except_spec.rb +19 -0
- data/test/models.rb +29 -0
- data/test/spec_helper.rb +9 -0
- metadata +62 -0
data/Changelog
ADDED
File without changes
|
data/History.txt
ADDED
data/LICENSE
ADDED
File without changes
|
data/Manifest.txt
ADDED
data/README
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= Except
|
2
|
+
|
3
|
+
* http://github.com/JGailor/except/tree/master
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Except gives you the ability to leave fields out of your ActiveRecord queries when querying for your models. If you have large fields that you don't want to take a performance hit for (such as binary fields, or text fields), just specify :except => "field1, field2, ..." in your find.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* I don't know yet. Feedback will help me find bugs!
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
Lets you leave out fields when retrieving ActiveRecord models
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* ActiveRecord
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* sudo gem install jgailor-except --source http://gems.github.com
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) 2008 FIX
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'spec/rake/spectask'
|
4
|
+
|
5
|
+
task :default => :spec
|
6
|
+
|
7
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
8
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
9
|
+
t.libs << "lib"
|
10
|
+
t.pattern = 'test/**/*_spec.rb'
|
11
|
+
end
|
data/lib/except.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'activerecord'
|
3
|
+
|
4
|
+
module Except
|
5
|
+
def self.included(base)
|
6
|
+
class << base
|
7
|
+
def find_with_except(*args)
|
8
|
+
options = args.last.is_a?(::Hash) ? args.pop : {}
|
9
|
+
if exceptions = options.delete(:except)
|
10
|
+
options[:select] = self.column_names.find_all {|name| !exceptions.include?(name)}.join(", ")
|
11
|
+
end
|
12
|
+
args << options
|
13
|
+
find_without_except(*args)
|
14
|
+
end
|
15
|
+
|
16
|
+
alias_method :find_without_except, :find
|
17
|
+
alias_method :find, :find_with_except
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
ActiveRecord::Base.send(:include, Except)
|
data/test/except_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe User do
|
4
|
+
before :each do
|
5
|
+
@user = User.create!(:email => "test@test.com", :password => "password")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should work normally when no except clause is given" do
|
9
|
+
User.first.should == @user
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should not throw an error when using the except clause" do
|
13
|
+
lambda{User.find(:all, :except => "password")}.should_not raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should only bring back all the fields except for the ones in the except clause" do
|
17
|
+
User.first(:except => "password").attribute_names.should_not include(:password)
|
18
|
+
end
|
19
|
+
end
|
data/test/models.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
ActiveRecord::Base.establish_connection(
|
2
|
+
:adapter => 'sqlite3',
|
3
|
+
:database => File.join(File.dirname(__FILE__), "test.db")
|
4
|
+
)
|
5
|
+
|
6
|
+
class CreateSchema < ActiveRecord::Migration
|
7
|
+
def self.up
|
8
|
+
create_table :users, :force => true do |t|
|
9
|
+
t.string :email, :password
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
|
13
|
+
create_table :profiles, :force => true do |t|
|
14
|
+
t.string :firstname, :lastname
|
15
|
+
t.integer :user_id, :age
|
16
|
+
t.timestamps
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
CreateSchema.suppress_messages { CreateSchema.migrate(:up) }
|
22
|
+
|
23
|
+
class User < ActiveRecord::Base
|
24
|
+
has_one :profile
|
25
|
+
end
|
26
|
+
|
27
|
+
class Profile < ActiveRecord::Base
|
28
|
+
belongs_to :user
|
29
|
+
end
|
data/test/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: JGailor-except
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy Gailor
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-12-28 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Except let's you specify fields to be left out when populating ActiveRecord models.'
|
17
|
+
email: jeremy@infinitecube.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README
|
26
|
+
- Changelog
|
27
|
+
- LICENSE
|
28
|
+
- History.txt
|
29
|
+
- Rakefile
|
30
|
+
- Manifest.txt
|
31
|
+
- test/models.rb
|
32
|
+
- test/spec_helper.rb
|
33
|
+
- test/except_spec.rb
|
34
|
+
- lib/except.rb
|
35
|
+
has_rdoc: false
|
36
|
+
homepage: http://github.com/JGailor/except/tree/master
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.2.0
|
58
|
+
signing_key:
|
59
|
+
specification_version: 2
|
60
|
+
summary: Except let's you specify fields to be left out when populating ActiveRecord models.'
|
61
|
+
test_files: []
|
62
|
+
|