has_siblings 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6633db6d43a93a25d0fa12314e2d2a88d7b90c54
4
+ data.tar.gz: 68dc51e3f6efc128deab3f9f10bff610f05c76a2
5
+ SHA512:
6
+ metadata.gz: ee0122b626469b407280aeb284c7a03b0f38903f79f9562e644f9e44a223e8dc341d997bc6f9a4ded9bfb384e7ee65e8dd8edf2757fd5d613d3906157543eb5b
7
+ data.tar.gz: d105363ef3d4f2c4da15c0165e24a18b05ef2ef8246890188d3143d227101302e9f9254c59a690dbaace9a96f1ae9ed1beaff2f0568acb28d4c064dce76abc3d
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.6
4
+ - 2.0.0
5
+ before_install: gem install bundler -v 1.10.5
6
+ gemfile:
7
+ - gemfiles/rails_4.0.gemfile
8
+ - gemfiles/rails_4.1.gemfile
9
+ - gemfiles/rails_4.2.gemfile
data/Appraisals ADDED
@@ -0,0 +1,11 @@
1
+ appraise "rails-4.0" do
2
+ gem "rails", "~> 4.0.0"
3
+ end
4
+
5
+ appraise "rails-4.1" do
6
+ gem "rails", "~> 4.1.0"
7
+ end
8
+
9
+ appraise "rails-4.2" do
10
+ gem "rails", "~> 4.2.0"
11
+ end
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'appraisal'
4
+
5
+ # Specify your gem's dependencies in has_siblings.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # HasSiblings
2
+
3
+ [![Build Status](https://travis-ci.org/annkissam/has_siblings.svg)](https://travis-ci.org/annkissam/has_siblings)
4
+
5
+ My brother from another mother!
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'has_siblings'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install has_siblings
22
+
23
+ ## Usage
24
+
25
+ Add has_siblings to a child model to get a siblings method that returns all of the parents'
26
+ other children.
27
+
28
+ ```ruby
29
+ class Mother < ActiveRecord::Base
30
+ has_many :children
31
+ end
32
+
33
+ class Father < ActiveRecord::Base
34
+ has_many :children
35
+ end
36
+
37
+ class Child < ActiveRecord::Base
38
+ belongs_to :mother, inverse_of: :children
39
+ belongs_to :father, inverse_of: :children
40
+
41
+ has_siblings through: [:mother, :father]
42
+ has_siblings through: :mother, name: :step_siblings
43
+ end
44
+ ```
45
+
46
+ An example of what it returns:
47
+
48
+ ```ruby
49
+ [1] pry> child
50
+ => #<Child:0x007fe5b3371c20 id: 6, mother_id: 3, father_id: 2>
51
+ [2] pry> sister
52
+ => #<Child:0x007fe5b3379e70 id: 7, mother_id: 3, father_id: 2>
53
+ [3] pry> brother
54
+ => #<Child:0x007fe5b337e0b0 id: 8, mother_id: 3, father_id: 2>
55
+ [4] pry> half_sister
56
+ => #<Child:0x007fe5b3386300 id: 9, mother_id: 3, father_id: nil>
57
+ [5] pry> just_a_friend
58
+ => #<Child:0x007fe5b338c390 id: 10, mother_id: 4, father_id: nil>
59
+ [6] pry> child.siblings
60
+ => [#<Child:0x007fe5b33dc6b0 id: 7, mother_id: 3, father_id: 2>,
61
+ #<Child:0x007fe5b33dc3e0 id: 8, mother_id: 3, father_id: 2>]
62
+ [7] pry> child.step_siblings
63
+ => [#<Child:0x007fe5b335fcc8 id: 7, mother_id: 3, father_id: 2>,
64
+ #<Child:0x007fe5b335f9d0 id: 8, mother_id: 3, father_id: 2>,
65
+ #<Child:0x007fe5b335f598 id: 9, mother_id: 3, father_id: nil>]
66
+ ```
67
+
68
+ ## Options
69
+
70
+ `has_siblings` accepts a `through: [...]` option that specifies the parents and can
71
+ be an array or a single symbol, and an optional `name` that will be the name of
72
+ the siblings method (default to `siblings`).
73
+
74
+ ## Compatibility
75
+
76
+ `ActiveRecord.version.to_s >= "4.0"`
77
+
78
+ ## Development
79
+
80
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
81
+
82
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
83
+
84
+ ## Contributing
85
+
86
+ Bug reports and pull requests are welcome on GitHub at https://github.com/annkissam/has_siblings.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ require 'wwtd/tasks'
7
+ task :local => "wwtd:local"
8
+
9
+ if ENV["TRAVIS"] || ENV["INSIDE_WWTD"]
10
+ task :default => :spec
11
+ else
12
+ task :default => :wwtd
13
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "has_siblings"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "rails", "~> 4.0.0"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,117 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ has_siblings (0.1.0)
5
+ activerecord (>= 3.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionmailer (4.0.13)
11
+ actionpack (= 4.0.13)
12
+ mail (~> 2.5, >= 2.5.4)
13
+ actionpack (4.0.13)
14
+ activesupport (= 4.0.13)
15
+ builder (~> 3.1.0)
16
+ erubis (~> 2.7.0)
17
+ rack (~> 1.5.2)
18
+ rack-test (~> 0.6.2)
19
+ activemodel (4.0.13)
20
+ activesupport (= 4.0.13)
21
+ builder (~> 3.1.0)
22
+ activerecord (4.0.13)
23
+ activemodel (= 4.0.13)
24
+ activerecord-deprecated_finders (~> 1.0.2)
25
+ activesupport (= 4.0.13)
26
+ arel (~> 4.0.0)
27
+ activerecord-deprecated_finders (1.0.4)
28
+ activesupport (4.0.13)
29
+ i18n (~> 0.6, >= 0.6.9)
30
+ minitest (~> 4.2)
31
+ multi_json (~> 1.3)
32
+ thread_safe (~> 0.1)
33
+ tzinfo (~> 0.3.37)
34
+ appraisal (2.0.1)
35
+ activesupport (>= 3.2.21)
36
+ bundler
37
+ rake
38
+ thor (>= 0.14.0)
39
+ arel (4.0.2)
40
+ builder (3.1.4)
41
+ coderay (1.1.0)
42
+ diff-lcs (1.2.5)
43
+ erubis (2.7.0)
44
+ i18n (0.7.0)
45
+ mail (2.6.3)
46
+ mime-types (>= 1.16, < 3)
47
+ method_source (0.8.2)
48
+ mime-types (2.6.1)
49
+ minitest (4.7.5)
50
+ multi_json (1.11.2)
51
+ pry (0.10.1)
52
+ coderay (~> 1.1.0)
53
+ method_source (~> 0.8.1)
54
+ slop (~> 3.4)
55
+ rack (1.5.5)
56
+ rack-test (0.6.3)
57
+ rack (>= 1.0)
58
+ rails (4.0.13)
59
+ actionmailer (= 4.0.13)
60
+ actionpack (= 4.0.13)
61
+ activerecord (= 4.0.13)
62
+ activesupport (= 4.0.13)
63
+ bundler (>= 1.3.0, < 2.0)
64
+ railties (= 4.0.13)
65
+ sprockets-rails (~> 2.0)
66
+ railties (4.0.13)
67
+ actionpack (= 4.0.13)
68
+ activesupport (= 4.0.13)
69
+ rake (>= 0.8.7)
70
+ thor (>= 0.18.1, < 2.0)
71
+ rake (10.4.2)
72
+ rspec (3.3.0)
73
+ rspec-core (~> 3.3.0)
74
+ rspec-expectations (~> 3.3.0)
75
+ rspec-mocks (~> 3.3.0)
76
+ rspec-core (3.3.2)
77
+ rspec-support (~> 3.3.0)
78
+ rspec-expectations (3.3.1)
79
+ diff-lcs (>= 1.2.0, < 2.0)
80
+ rspec-support (~> 3.3.0)
81
+ rspec-its (1.2.0)
82
+ rspec-core (>= 3.0.0)
83
+ rspec-expectations (>= 3.0.0)
84
+ rspec-mocks (3.3.2)
85
+ diff-lcs (>= 1.2.0, < 2.0)
86
+ rspec-support (~> 3.3.0)
87
+ rspec-support (3.3.0)
88
+ slop (3.6.0)
89
+ sprockets (3.2.0)
90
+ rack (~> 1.0)
91
+ sprockets-rails (2.3.2)
92
+ actionpack (>= 3.0)
93
+ activesupport (>= 3.0)
94
+ sprockets (>= 2.8, < 4.0)
95
+ sqlite3 (1.3.10)
96
+ thor (0.19.1)
97
+ thread_safe (0.3.5)
98
+ tzinfo (0.3.44)
99
+ wwtd (0.9.1)
100
+
101
+ PLATFORMS
102
+ ruby
103
+
104
+ DEPENDENCIES
105
+ appraisal
106
+ bundler (~> 1.10)
107
+ has_siblings!
108
+ pry
109
+ rails (~> 4.0.0)
110
+ rake (~> 10.0)
111
+ rspec
112
+ rspec-its
113
+ sqlite3
114
+ wwtd
115
+
116
+ BUNDLED WITH
117
+ 1.10.5
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "rails", "~> 4.1.0"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,122 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ has_siblings (0.1.0)
5
+ activerecord (>= 3.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionmailer (4.1.10)
11
+ actionpack (= 4.1.10)
12
+ actionview (= 4.1.10)
13
+ mail (~> 2.5, >= 2.5.4)
14
+ actionpack (4.1.10)
15
+ actionview (= 4.1.10)
16
+ activesupport (= 4.1.10)
17
+ rack (~> 1.5.2)
18
+ rack-test (~> 0.6.2)
19
+ actionview (4.1.10)
20
+ activesupport (= 4.1.10)
21
+ builder (~> 3.1)
22
+ erubis (~> 2.7.0)
23
+ activemodel (4.1.10)
24
+ activesupport (= 4.1.10)
25
+ builder (~> 3.1)
26
+ activerecord (4.1.10)
27
+ activemodel (= 4.1.10)
28
+ activesupport (= 4.1.10)
29
+ arel (~> 5.0.0)
30
+ activesupport (4.1.10)
31
+ i18n (~> 0.6, >= 0.6.9)
32
+ json (~> 1.7, >= 1.7.7)
33
+ minitest (~> 5.1)
34
+ thread_safe (~> 0.1)
35
+ tzinfo (~> 1.1)
36
+ appraisal (2.0.1)
37
+ activesupport (>= 3.2.21)
38
+ bundler
39
+ rake
40
+ thor (>= 0.14.0)
41
+ arel (5.0.1.20140414130214)
42
+ builder (3.2.2)
43
+ coderay (1.1.0)
44
+ diff-lcs (1.2.5)
45
+ erubis (2.7.0)
46
+ i18n (0.7.0)
47
+ json (1.8.3)
48
+ mail (2.6.3)
49
+ mime-types (>= 1.16, < 3)
50
+ method_source (0.8.2)
51
+ mime-types (2.6.1)
52
+ minitest (5.7.0)
53
+ pry (0.10.1)
54
+ coderay (~> 1.1.0)
55
+ method_source (~> 0.8.1)
56
+ slop (~> 3.4)
57
+ rack (1.5.5)
58
+ rack-test (0.6.3)
59
+ rack (>= 1.0)
60
+ rails (4.1.10)
61
+ actionmailer (= 4.1.10)
62
+ actionpack (= 4.1.10)
63
+ actionview (= 4.1.10)
64
+ activemodel (= 4.1.10)
65
+ activerecord (= 4.1.10)
66
+ activesupport (= 4.1.10)
67
+ bundler (>= 1.3.0, < 2.0)
68
+ railties (= 4.1.10)
69
+ sprockets-rails (~> 2.0)
70
+ railties (4.1.10)
71
+ actionpack (= 4.1.10)
72
+ activesupport (= 4.1.10)
73
+ rake (>= 0.8.7)
74
+ thor (>= 0.18.1, < 2.0)
75
+ rake (10.4.2)
76
+ rspec (3.3.0)
77
+ rspec-core (~> 3.3.0)
78
+ rspec-expectations (~> 3.3.0)
79
+ rspec-mocks (~> 3.3.0)
80
+ rspec-core (3.3.2)
81
+ rspec-support (~> 3.3.0)
82
+ rspec-expectations (3.3.1)
83
+ diff-lcs (>= 1.2.0, < 2.0)
84
+ rspec-support (~> 3.3.0)
85
+ rspec-its (1.2.0)
86
+ rspec-core (>= 3.0.0)
87
+ rspec-expectations (>= 3.0.0)
88
+ rspec-mocks (3.3.2)
89
+ diff-lcs (>= 1.2.0, < 2.0)
90
+ rspec-support (~> 3.3.0)
91
+ rspec-support (3.3.0)
92
+ slop (3.6.0)
93
+ sprockets (3.2.0)
94
+ rack (~> 1.0)
95
+ sprockets-rails (2.3.2)
96
+ actionpack (>= 3.0)
97
+ activesupport (>= 3.0)
98
+ sprockets (>= 2.8, < 4.0)
99
+ sqlite3 (1.3.10)
100
+ thor (0.19.1)
101
+ thread_safe (0.3.5)
102
+ tzinfo (1.2.2)
103
+ thread_safe (~> 0.1)
104
+ wwtd (0.9.1)
105
+
106
+ PLATFORMS
107
+ ruby
108
+
109
+ DEPENDENCIES
110
+ appraisal
111
+ bundler (~> 1.10)
112
+ has_siblings!
113
+ pry
114
+ rails (~> 4.1.0)
115
+ rake (~> 10.0)
116
+ rspec
117
+ rspec-its
118
+ sqlite3
119
+ wwtd
120
+
121
+ BUNDLED WITH
122
+ 1.10.5
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "rails", "~> 4.2.0"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,147 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ has_siblings (0.1.0)
5
+ activerecord (>= 3.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionmailer (4.2.3)
11
+ actionpack (= 4.2.3)
12
+ actionview (= 4.2.3)
13
+ activejob (= 4.2.3)
14
+ mail (~> 2.5, >= 2.5.4)
15
+ rails-dom-testing (~> 1.0, >= 1.0.5)
16
+ actionpack (4.2.3)
17
+ actionview (= 4.2.3)
18
+ activesupport (= 4.2.3)
19
+ rack (~> 1.6)
20
+ rack-test (~> 0.6.2)
21
+ rails-dom-testing (~> 1.0, >= 1.0.5)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
23
+ actionview (4.2.3)
24
+ activesupport (= 4.2.3)
25
+ builder (~> 3.1)
26
+ erubis (~> 2.7.0)
27
+ rails-dom-testing (~> 1.0, >= 1.0.5)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
+ activejob (4.2.3)
30
+ activesupport (= 4.2.3)
31
+ globalid (>= 0.3.0)
32
+ activemodel (4.2.3)
33
+ activesupport (= 4.2.3)
34
+ builder (~> 3.1)
35
+ activerecord (4.2.3)
36
+ activemodel (= 4.2.3)
37
+ activesupport (= 4.2.3)
38
+ arel (~> 6.0)
39
+ activesupport (4.2.3)
40
+ i18n (~> 0.7)
41
+ json (~> 1.7, >= 1.7.7)
42
+ minitest (~> 5.1)
43
+ thread_safe (~> 0.3, >= 0.3.4)
44
+ tzinfo (~> 1.1)
45
+ appraisal (2.0.1)
46
+ activesupport (>= 3.2.21)
47
+ bundler
48
+ rake
49
+ thor (>= 0.14.0)
50
+ arel (6.0.2)
51
+ builder (3.2.2)
52
+ coderay (1.1.0)
53
+ diff-lcs (1.2.5)
54
+ erubis (2.7.0)
55
+ globalid (0.3.5)
56
+ activesupport (>= 4.1.0)
57
+ i18n (0.7.0)
58
+ json (1.8.3)
59
+ loofah (2.0.2)
60
+ nokogiri (>= 1.5.9)
61
+ mail (2.6.3)
62
+ mime-types (>= 1.16, < 3)
63
+ method_source (0.8.2)
64
+ mime-types (2.6.1)
65
+ mini_portile (0.6.2)
66
+ minitest (5.7.0)
67
+ nokogiri (1.6.6.2)
68
+ mini_portile (~> 0.6.0)
69
+ pry (0.10.1)
70
+ coderay (~> 1.1.0)
71
+ method_source (~> 0.8.1)
72
+ slop (~> 3.4)
73
+ rack (1.6.4)
74
+ rack-test (0.6.3)
75
+ rack (>= 1.0)
76
+ rails (4.2.3)
77
+ actionmailer (= 4.2.3)
78
+ actionpack (= 4.2.3)
79
+ actionview (= 4.2.3)
80
+ activejob (= 4.2.3)
81
+ activemodel (= 4.2.3)
82
+ activerecord (= 4.2.3)
83
+ activesupport (= 4.2.3)
84
+ bundler (>= 1.3.0, < 2.0)
85
+ railties (= 4.2.3)
86
+ sprockets-rails
87
+ rails-deprecated_sanitizer (1.0.3)
88
+ activesupport (>= 4.2.0.alpha)
89
+ rails-dom-testing (1.0.6)
90
+ activesupport (>= 4.2.0.beta, < 5.0)
91
+ nokogiri (~> 1.6.0)
92
+ rails-deprecated_sanitizer (>= 1.0.1)
93
+ rails-html-sanitizer (1.0.2)
94
+ loofah (~> 2.0)
95
+ railties (4.2.3)
96
+ actionpack (= 4.2.3)
97
+ activesupport (= 4.2.3)
98
+ rake (>= 0.8.7)
99
+ thor (>= 0.18.1, < 2.0)
100
+ rake (10.4.2)
101
+ rspec (3.3.0)
102
+ rspec-core (~> 3.3.0)
103
+ rspec-expectations (~> 3.3.0)
104
+ rspec-mocks (~> 3.3.0)
105
+ rspec-core (3.3.2)
106
+ rspec-support (~> 3.3.0)
107
+ rspec-expectations (3.3.1)
108
+ diff-lcs (>= 1.2.0, < 2.0)
109
+ rspec-support (~> 3.3.0)
110
+ rspec-its (1.2.0)
111
+ rspec-core (>= 3.0.0)
112
+ rspec-expectations (>= 3.0.0)
113
+ rspec-mocks (3.3.2)
114
+ diff-lcs (>= 1.2.0, < 2.0)
115
+ rspec-support (~> 3.3.0)
116
+ rspec-support (3.3.0)
117
+ slop (3.6.0)
118
+ sprockets (3.2.0)
119
+ rack (~> 1.0)
120
+ sprockets-rails (2.3.2)
121
+ actionpack (>= 3.0)
122
+ activesupport (>= 3.0)
123
+ sprockets (>= 2.8, < 4.0)
124
+ sqlite3 (1.3.10)
125
+ thor (0.19.1)
126
+ thread_safe (0.3.5)
127
+ tzinfo (1.2.2)
128
+ thread_safe (~> 0.1)
129
+ wwtd (0.9.1)
130
+
131
+ PLATFORMS
132
+ ruby
133
+
134
+ DEPENDENCIES
135
+ appraisal
136
+ bundler (~> 1.10)
137
+ has_siblings!
138
+ pry
139
+ rails (~> 4.2.0)
140
+ rake (~> 10.0)
141
+ rspec
142
+ rspec-its
143
+ sqlite3
144
+ wwtd
145
+
146
+ BUNDLED WITH
147
+ 1.10.5
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'has_siblings/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "has_siblings"
8
+ spec.version = HasSiblings::VERSION
9
+ spec.authors = ["Octavian Neamtu"]
10
+ spec.email = ["octavian.neamtu@annkissam.com"]
11
+
12
+ spec.summary = %q{Easily define a siblings method for a child model instance.}
13
+ spec.description = %q{ parent.children.where.not(id: self.id), extended to n parents }
14
+ spec.homepage = "https://github.com/annkissam/has_siblings"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "activerecord", ">= 3.2"
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec"
33
+ spec.add_development_dependency "rspec-its"
34
+ spec.add_development_dependency "sqlite3"
35
+ spec.add_development_dependency "pry"
36
+ spec.add_development_dependency "wwtd"
37
+ end
@@ -0,0 +1,34 @@
1
+ require 'has_siblings/errors'
2
+
3
+ module HasSiblings
4
+ module ClassMethods
5
+ # This is similar to how rails defines association methods.
6
+ # https://github.com/rails/rails/blob/3e36db4406beea32772b1db1e9a16cc1e8aea14c/activerecord/lib/active_record/associations/builder/association.rb#L102
7
+ def has_siblings(options = {})
8
+ *parents = options.fetch(:through)
9
+ name = options.fetch(:name, "siblings")
10
+
11
+ parent_association_pairs = parents.map do |parent|
12
+ reflection = reflect_on_association(parent)
13
+ fail HasSiblings::ThroughAssociationNotFoundError.new(parent, self) if reflection.nil?
14
+ [parent, reflection]
15
+ end
16
+ parent_association_name_pairs = parent_association_pairs.map do |parent, association|
17
+ fail HasSiblings::InverseOfNotFoundError.new(parent, self) if association.inverse_of.nil?
18
+ [parent, association.inverse_of.name]
19
+ end
20
+ merge_scopes = parent_association_name_pairs[1..-1].map do |parent, association_name|
21
+ "merge(#{parent}.#{association_name})"
22
+ end
23
+ first_parent_association = parent_association_name_pairs[0].join(".")
24
+
25
+ mixin = ActiveRecord.version.to_s >= "4.1" ? generated_association_methods : generated_feature_methods
26
+
27
+ mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
28
+ def #{name}
29
+ #{([first_parent_association] + merge_scopes).join(".")}.where.not(id: id)
30
+ end
31
+ CODE
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,13 @@
1
+ module HasSiblings
2
+ class ThroughAssociationNotFoundError < StandardError
3
+ def initialize(association_name, owner_class_name)
4
+ super("Could not find the association #{association_name} in model #{owner_class_name}")
5
+ end
6
+ end
7
+
8
+ class InverseOfNotFoundError < StandardError
9
+ def initialize(association_name, owner_class_name)
10
+ super("Could not find the inverse_of for the association #{association_name} in model #{owner_class_name}")
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module HasSiblings
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ require "has_siblings/version"
2
+ require "has_siblings/class_methods"
3
+
4
+ module HasSiblings
5
+ end
6
+
7
+ if Object.const_defined?("ActiveRecord")
8
+ ActiveRecord::Base.send(:extend, HasSiblings::ClassMethods)
9
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: has_siblings
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Octavian Neamtu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-its
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: wwtd
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: " parent.children.where.not(id: self.id), extended to n parents "
126
+ email:
127
+ - octavian.neamtu@annkissam.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - Appraisals
136
+ - Gemfile
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - gemfiles/rails_4.0.gemfile
142
+ - gemfiles/rails_4.0.gemfile.lock
143
+ - gemfiles/rails_4.1.gemfile
144
+ - gemfiles/rails_4.1.gemfile.lock
145
+ - gemfiles/rails_4.2.gemfile
146
+ - gemfiles/rails_4.2.gemfile.lock
147
+ - has_siblings.gemspec
148
+ - lib/has_siblings.rb
149
+ - lib/has_siblings/class_methods.rb
150
+ - lib/has_siblings/errors.rb
151
+ - lib/has_siblings/version.rb
152
+ homepage: https://github.com/annkissam/has_siblings
153
+ licenses: []
154
+ metadata:
155
+ allowed_push_host: https://rubygems.org
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.2.3
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: Easily define a siblings method for a child model instance.
176
+ test_files: []