acts-as-joinable 0.1.7.7 → 0.1.7.8

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.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/lib/acts_as_joinable/core.rb +19 -10
  3. metadata +3 -3
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.7.7"
8
+ s.version = "0.1.7.8"
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"
@@ -66,8 +66,8 @@ module ActsAsJoinable
66
66
  class_name = opts[:class_name] || nil
67
67
  sti = (opts[:subclasses] || []).map { |i| i.to_s.camelize.constantize }
68
68
  # contexts defining the relationship between self and target
69
- contexts = [opts[:context] || []].flatten
70
- context = contexts.first
69
+ contexts = [opts[:context] || []].flatten.map(&:to_s)
70
+ context = contexts#.first
71
71
  # possible values of the context
72
72
  values = [opts[:values] || opts[:value] || []].flatten.compact
73
73
  value = values.first
@@ -100,7 +100,7 @@ module ActsAsJoinable
100
100
  end
101
101
  class_name = opts[:class_name] || type.to_s.classify
102
102
 
103
- join_context = (context || singular_type).to_s
103
+ join_context = (context.blank? ? [singular_type] : Array(context)).map(&:to_s)
104
104
 
105
105
  options = {
106
106
  :through => :relationships,
@@ -131,18 +131,20 @@ module ActsAsJoinable
131
131
  #if join_context == class_name.underscore
132
132
 
133
133
  # condition_string << "(#{relationship_table}.#{relationship}_type IN (?))"
134
- if join_context == class_name.underscore# && opposite_for(relationship).to_sym != :child
134
+ if join_context.include?(class_name.underscore)# && opposite_for(relationship).to_sym != :child
135
135
  #conditions = [condition_string, [class_name]]
136
136
  # if join_value
137
137
  # condition_string << "(#{relationship_table}.value = ?)"
138
138
  # conditions = [condition_string, join_value.to_s]
139
139
  # end
140
140
  else
141
- condition_string << "(#{relationship_table}.context IN (?))"
142
- condition_string << " AND (#{relationship_table}.value = ?)" if join_value
143
- join_contexts = [join_context]#[join_context, class_name.underscore].uniq
144
- conditions = [condition_string, join_contexts]
145
- conditions << join_value.to_s if join_value
141
+ conditions = {:context => join_context.dup}
142
+ conditions[:value] = join_value unless join_value.blank?
143
+ # condition_string << "(#{relationship_table}.context IN (?))"
144
+ # condition_string << " AND (#{relationship_table}.value = ?)" if join_value
145
+ # join_contexts = join_context.dup#[join_context, class_name.underscore].uniq
146
+ # conditions = [condition_string, join_contexts]
147
+ # conditions << join_value.to_s if join_value
146
148
  end
147
149
 
148
150
  through_options = {
@@ -159,6 +161,13 @@ module ActsAsJoinable
159
161
  through_options[:uniq] = true
160
162
  end
161
163
 
164
+ if join_context.length > 1
165
+ through_options[:readonly] = true
166
+ options[:readonly] = true
167
+ else
168
+ through_options.delete(:readonly)
169
+ options.delete(:readonly)
170
+ end
162
171
 
163
172
  unless has_association?(through_relationship)
164
173
  has_many through_relationship, through_options
@@ -295,7 +304,7 @@ module ActsAsJoinable
295
304
 
296
305
  def add_association(relationship, plural_type, options, join_context, join_value, &block)
297
306
  eval_options = {}
298
- eval_options[:context] = join_context unless join_context.to_s == options[:class_name].to_s.underscore.singularize
307
+ eval_options[:context] = join_context.to_s unless join_context.to_s == options[:class_name].to_s.underscore.singularize
299
308
 
300
309
  eval_options[:value] = join_value unless join_value.blank?
301
310
  # has_many :users, :through => :child_relationships
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts-as-joinable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 85
4
+ hash: 75
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
9
  - 7
10
- - 7
11
- version: 0.1.7.7
10
+ - 8
11
+ version: 0.1.7.8
12
12
  platform: ruby
13
13
  authors:
14
14
  - Lance Pollard