has-relationship 0.0.4 → 0.0.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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -26,8 +26,10 @@ module HasRelationship
26
26
  end
27
27
 
28
28
  relationship = options[:relationship] if options[:relationship]
29
- relationship = [relationship] unless relationship.kind_of?(Array)
30
- relationship_through = options[:singular] ? "relationship_through_#{relationship.join("_").to_s.tableize.singularize}".to_sym : "relationship_through_#{relationship.join("_").to_s.tableize}".to_sym
29
+
30
+ relationships = relationship.kind_of?(Array) ? relationship : [relationship]
31
+
32
+ relationship_through = options[:singular] ? "relationship_through_#{relationships.join("_").to_s.tableize.singularize}".to_sym : "relationship_through_#{relationships.join("_").to_s.tableize}".to_sym
31
33
 
32
34
  HasRelationship::Relationship.class_eval do
33
35
  belongs_to "relation2_#{class_name.downcase}".to_sym, :class_name => class_name, :foreign_key => "relation2_id"
@@ -40,10 +42,10 @@ module HasRelationship
40
42
  class_eval do
41
43
  if options[:singular]
42
44
  has_one relationship_through, :as => :relation1, :dependent => :destroy, :class_name => "HasRelationship::Relationship", :conditions => {:relationship => relationship}
43
- has_one resource_name, :through => relationship_through, :class_name => class_name, :source => "relation2_#{class_name.downcase}".to_s, :conditions => ["relationships.relation2_type = ? and relationships.relationship in (?)", class_name, relationship], :select => options[:select]
45
+ has_one resource_name, :through => relationship_through, :class_name => class_name, :source => "relation2_#{class_name.downcase}".to_s, :conditions => ["relationships.relation2_type = ? and relationships.relationship in (?)", class_name, relationships], :select => options[:select]
44
46
  else
45
47
  has_many relationship_through, :as => :relation1, :dependent => :destroy, :class_name => "HasRelationship::Relationship", :conditions => {:relationship => relationship}
46
- has_many resource_name, :through => relationship_through, :class_name => class_name, :source => "relation2_#{class_name.downcase}".to_sym, :conditions => ["relationships.relation2_type = ? and relationships.relationship in (?)", class_name, relationship], :select => options[:select]
48
+ has_many resource_name, :through => relationship_through, :class_name => class_name, :source => "relation2_#{class_name.downcase}".to_sym, :conditions => ["relationships.relation2_type = ? and relationships.relationship in (?)", class_name, relationships], :select => options[:select]
47
49
  end
48
50
  end
49
51
  end
@@ -74,9 +76,10 @@ module HasRelationship
74
76
  end
75
77
 
76
78
  relationship = options[:relationship] if options[:relationship]
77
- relationship = [relationship] unless relationship.kind_of?(Array)
78
79
 
79
- relationship_through = options[:singular] ? "inverse_relationship_through_#{relationship.join("_").to_s.tableize.singularize}".to_sym : "inverse_relationship_through_#{relationship.join("_").to_s.tableize}".to_sym
80
+ relationships = relationship.kind_of?(Array) ? relationship : [relationship]
81
+
82
+ relationship_through = options[:singular] ? "inverse_relationship_through_#{relationships.join("_").to_s.tableize.singularize}".to_sym : "inverse_relationship_through_#{relationships.join("_").to_s.tableize}".to_sym
80
83
 
81
84
  HasRelationship::Relationship.class_eval do
82
85
  belongs_to "relation1_#{class_name.downcase}".to_sym, :class_name => class_name, :foreign_key => "relation1_id"
@@ -89,10 +92,10 @@ module HasRelationship
89
92
  class_eval do
90
93
  if options[:singular]
91
94
  has_one relationship_through, :as => :relation2, :dependent => :destroy, :class_name => "HasRelationship::Relationship", :conditions => {:relationship => relationship}
92
- has_one resource_name, :through => relationship_through, :class_name => class_name, :source => "relation1_#{class_name.downcase}".to_sym, :conditions => ["relationships.relation1_type = ? and relationships.relationship in (?)", class_name, relationship], :select => options[:select]
95
+ has_one resource_name, :through => relationship_through, :class_name => class_name, :source => "relation1_#{class_name.downcase}".to_sym, :conditions => ["relationships.relation1_type = ? and relationships.relationship in (?)", class_name, relationships], :select => options[:select]
93
96
  else
94
97
  has_many relationship_through, :as => :relation2, :dependent => :destroy, :class_name => "HasRelationship::Relationship", :conditions => {:relationship => relationship}
95
- has_many resource_name, :through => relationship_through, :class_name => class_name, :source => "relation1_#{class_name.downcase}".to_sym, :conditions => ["relationships.relation1_type = ? and relationships.relationship in (?)", class_name, relationship], :select => options[:select]
98
+ has_many resource_name, :through => relationship_through, :class_name => class_name, :source => "relation1_#{class_name.downcase}".to_sym, :conditions => ["relationships.relation1_type = ? and relationships.relationship in (?)", class_name, relationships], :select => options[:select]
96
99
  end
97
100
  end
98
101
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has-relationship
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew Hunter