is_association 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use --create ruby-1.8.7@is_association
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+
4
+ gem 'rspec-rails', '2.8.1'
5
+ gem 'activerecord', '>3.0.0'
6
+ gem 'sqlite3'
7
+
8
+ # Specify your gem's dependencies in is_association.gemspec
9
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,85 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ is_association (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ actionpack (3.2.8)
10
+ activemodel (= 3.2.8)
11
+ activesupport (= 3.2.8)
12
+ builder (~> 3.0.0)
13
+ erubis (~> 2.7.0)
14
+ journey (~> 1.0.4)
15
+ rack (~> 1.4.0)
16
+ rack-cache (~> 1.2)
17
+ rack-test (~> 0.6.1)
18
+ sprockets (~> 2.1.3)
19
+ activemodel (3.2.8)
20
+ activesupport (= 3.2.8)
21
+ builder (~> 3.0.0)
22
+ activerecord (3.2.8)
23
+ activemodel (= 3.2.8)
24
+ activesupport (= 3.2.8)
25
+ arel (~> 3.0.2)
26
+ tzinfo (~> 0.3.29)
27
+ activesupport (3.2.8)
28
+ i18n (~> 0.6)
29
+ multi_json (~> 1.0)
30
+ arel (3.0.2)
31
+ builder (3.0.4)
32
+ diff-lcs (1.1.3)
33
+ erubis (2.7.0)
34
+ hike (1.2.1)
35
+ i18n (0.6.1)
36
+ journey (1.0.4)
37
+ json (1.7.5)
38
+ multi_json (1.3.6)
39
+ rack (1.4.1)
40
+ rack-cache (1.2)
41
+ rack (>= 0.4)
42
+ rack-ssl (1.3.2)
43
+ rack
44
+ rack-test (0.6.2)
45
+ rack (>= 1.0)
46
+ railties (3.2.8)
47
+ actionpack (= 3.2.8)
48
+ activesupport (= 3.2.8)
49
+ rack-ssl (~> 1.3.2)
50
+ rake (>= 0.8.7)
51
+ rdoc (~> 3.4)
52
+ thor (>= 0.14.6, < 2.0)
53
+ rake (0.9.2.2)
54
+ rdoc (3.12)
55
+ json (~> 1.4)
56
+ rspec (2.8.0)
57
+ rspec-core (~> 2.8.0)
58
+ rspec-expectations (~> 2.8.0)
59
+ rspec-mocks (~> 2.8.0)
60
+ rspec-core (2.8.0)
61
+ rspec-expectations (2.8.0)
62
+ diff-lcs (~> 1.1.2)
63
+ rspec-mocks (2.8.0)
64
+ rspec-rails (2.8.1)
65
+ actionpack (>= 3.0)
66
+ activesupport (>= 3.0)
67
+ railties (>= 3.0)
68
+ rspec (~> 2.8.0)
69
+ sprockets (2.1.3)
70
+ hike (~> 1.2)
71
+ rack (~> 1.0)
72
+ tilt (~> 1.1, != 1.3.0)
73
+ sqlite3 (1.3.6)
74
+ thor (0.16.0)
75
+ tilt (1.3.3)
76
+ tzinfo (0.3.34)
77
+
78
+ PLATFORMS
79
+ ruby
80
+
81
+ DEPENDENCIES
82
+ activerecord (> 3.0.0)
83
+ is_association!
84
+ rspec-rails (= 2.8.1)
85
+ sqlite3
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "is_association/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "is_association"
7
+ s.version = IsAssociation::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Alain M. Lafon"]
10
+ s.email = ["alain.lafon@dispatched.ch"]
11
+ s.homepage = ""
12
+ s.summary = "Is a relation an association?"
13
+ s.description = %q{Patches ActiveRecord::Base to expose a method
14
+ is_association? The method will return true for all associations like
15
+ has_one, has_many and belongs_to while returning false for regular attributes
16
+ on the table.
17
+ }
18
+
19
+ s.rubyforge_project = "is_association"
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = ["lib"]
25
+
26
+ Gem::Specification.new do |s|
27
+ s.add_development_dependency "rspec"
28
+ s.add_development_dependency "activerecord", [">= 3.0.0"]
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module IsAssociation
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,10 @@
1
+ class ActiveRecord::Base
2
+ def is_association? relation
3
+ begin
4
+ self.association(relation)
5
+ rescue NoMethodError
6
+ return false
7
+ end
8
+ true
9
+ end
10
+ end
Binary file
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ActiveRecord::Base', %q{
4
+ This is a spec for a MonkeyPatch on ActiveRecord::Base.
5
+ It's exposing a method is_association? to find out wheter
6
+ a relation is an association.
7
+ } do
8
+
9
+
10
+ before(:each) do
11
+ ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":memory:"
12
+
13
+ ActiveRecord::Migration.create_table :posts do |t|
14
+ t.string :name
15
+ t.timestamps
16
+ end
17
+ ActiveRecord::Migration.create_table :comments do |t|
18
+ t.integer :post_id
19
+ t.timestamps
20
+ end
21
+
22
+ class Post < ActiveRecord::Base
23
+ has_many :comments
24
+ end
25
+
26
+ class Comment < ActiveRecord::Base
27
+ belongs_to :post
28
+ end
29
+ end
30
+
31
+
32
+ it 'responds to is_association?' do
33
+ post = Post.new
34
+ post.should respond_to(:is_association?)
35
+ end
36
+
37
+ it 'responds with "true" when relation is an association' do
38
+ post = Post.new
39
+ post.is_association?(:comments).should == true
40
+ end
41
+
42
+ it 'responds with "false" when relation is not an association' do
43
+ post = Post.new
44
+ post.is_association?(:name).should == false
45
+ end
46
+
47
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'active_record'
4
+
5
+ require 'is_association'
6
+
7
+ RSpec.configure do |config|
8
+ # some (optional) config here
9
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: is_association
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Alain M. Lafon
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-11-05 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: "Patches ActiveRecord::Base to expose a method\n is_association? The method will return true for all associations like\n has_one, has_many and belongs_to while returning false for regular attributes\n on the table.\n "
22
+ email:
23
+ - alain.lafon@dispatched.ch
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - .rvmrc
33
+ - Gemfile
34
+ - Gemfile.lock
35
+ - Rakefile
36
+ - is_association.gemspec
37
+ - lib/is_association.rb
38
+ - lib/is_association/version.rb
39
+ - spec/.is_association_spec.rb.swp
40
+ - spec/is_association_spec.rb
41
+ - spec/spec_helper.rb
42
+ homepage: ""
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project: is_association
71
+ rubygems_version: 1.8.24
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Is a relation an association?
75
+ test_files:
76
+ - spec/is_association_spec.rb
77
+ - spec/spec_helper.rb