acts-as-joinable 0.1.4 → 0.1.5

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/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/gempackagetask'
5
5
  spec = Gem::Specification.new do |s|
6
6
  s.name = "acts-as-joinable"
7
7
  s.authors = ["Lance Pollard"]
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
  s.summary = "ActsAsJoinable: DRYing up Many-to-Many Relationships in ActiveRecord"
10
10
  s.homepage = "http://github.com/viatropos/acts-as-joinable"
11
11
  s.email = "lancejpollard@gmail.com"
@@ -79,7 +79,6 @@ module ActiveRecord
79
79
 
80
80
  # Construct attributes for associate pointing to owner.
81
81
  def construct_owner_attributes(reflection)
82
- puts "construct_owner_attributes #{@owner.class.name}"
83
82
  if as = reflection.options[:as]
84
83
  { "#{as}_id" => @owner.id,
85
84
  "#{as}_type" => @owner.class.name.to_s }
@@ -121,7 +120,6 @@ module ActiveRecord
121
120
  reflection_primary_key = @reflection.klass.primary_key
122
121
  source_primary_key = @reflection.source_reflection.primary_key_name
123
122
  if @reflection.options[:source_type]
124
- puts "@reflection.options[:source_type]"
125
123
  polymorphic_join = construct_polymorphic_sql(
126
124
  @reflection.through_reflection.quoted_table_name,
127
125
  "#{@reflection.source_reflection.options[:foreign_type]}",
@@ -149,8 +147,6 @@ module ActiveRecord
149
147
  polymorphic_join
150
148
  ]
151
149
 
152
- puts "RESULT #{result}"
153
-
154
150
  result
155
151
  end
156
152
  end
@@ -181,7 +177,6 @@ module ActiveRecord
181
177
  @finder_sql << " AND (#{polymorphic_conditions})"
182
178
  @finder_sql << " AND (#{conditions})" if conditions
183
179
  else
184
- puts "PRIMARY #{@reflection.quoted_table_name}.#{@reflection.primary_key_name}"
185
180
  @finder_sql = "#{@reflection.quoted_table_name}.#{@reflection.primary_key_name} = #{owner_quoted_id}"
186
181
  @finder_sql << " AND (#{conditions})" if conditions
187
182
  end
@@ -178,7 +178,7 @@ module ActsAsJoinable
178
178
  send(plural_type).last
179
179
  end
180
180
  define_method "#{singular_type}=" do |value|
181
- send(relationship_with_context).delete_all
181
+ #send(relationship_with_context).delete_all
182
182
  send(plural_type) << value
183
183
  end
184
184
  define_method "#{singular_type}_id" do
@@ -223,6 +223,25 @@ module ActsAsJoinable
223
223
  conditions = %Q|(`relationships`.parent_type IN ("#{self.class.name}","#{self.class.base_class.name}") AND `relationships`.parent_id = #{self.id}) OR (`relationships`.child_type IN ("#{self.class.name}","#{self.class.base_class.name}") AND `relationships`.child_id = #{self.id})|
224
224
  ActsAsJoinable::Relationship.delete_all(conditions)
225
225
  end
226
+
227
+ def relationship_matches?(relationship, conditions)
228
+ return false if conditions[:parent_type] && !Array(conditions[:parent_type]).include?(relationship.parent_type)
229
+ return false if conditions[:child_type] && !Array(conditions[:child_type]).include?(relationship.child_type)
230
+ return false if conditions[:context] && !Array(conditions[:context]).include?(relationship.context)
231
+ true
232
+ end
233
+
234
+ def parent_relationships_for(conditions = {})
235
+ parent_relationships.select do |relationship|
236
+ relationship_matches?(relationship, conditions)
237
+ end
238
+ end
239
+
240
+ def child_relationships_for(conditions = {})
241
+ child_relationships.select do |relationship|
242
+ relationship_matches?(relationship, conditions)
243
+ end
244
+ end
226
245
  end
227
246
  end
228
247
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts-as-joinable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Lance Pollard
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-22 00:00:00 -05:00
18
+ date: 2010-09-29 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies: []
21
21