arel_search 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ArelSearch
2
2
 
3
- TODO: Write a gem description
3
+ Work in progress, use at your own risk but feel free to contribute :)
4
4
 
5
5
  ## Installation
6
6
 
@@ -44,15 +44,18 @@ module ArelSearch
44
44
  end
45
45
 
46
46
  class SearchField
47
- attr_reader :name, :value, :association, :arel_predication, :split, :base_model
47
+
48
+ NAMESPACE_SYMBOL = '::'
49
+
50
+ attr_reader :name, :value, :association, :namespace, :arel_predication, :split, :base_model
48
51
 
49
52
  def initialize(key, v, b_model)
50
- @base_model = b_model
53
+ @base_model = b_model
51
54
  split_key(key)
52
- @association = self.split[0]
53
- self.name = self.split[1]
54
- self.arel_predication = self.split[2]
55
- @value = v
55
+ @association, @namespace = set_association_and_namespace(self.split[0])
56
+ self.name = self.split[1]
57
+ self.arel_predication = self.split[2]
58
+ @value = v
56
59
  end
57
60
 
58
61
  def scopify(scope, default_arel_table)
@@ -77,7 +80,7 @@ module ArelSearch
77
80
  end
78
81
 
79
82
  def model
80
- self.association.camelize.singularize.constantize
83
+ "#{namespace}#{NAMESPACE_SYMBOL}#{association.camelize.singularize}".constantize
81
84
  end
82
85
 
83
86
  private
@@ -109,6 +112,18 @@ module ArelSearch
109
112
  @@arel_predications ||= Arel::Predications.instance_methods.map(&:to_s)
110
113
  end
111
114
 
115
+ def set_association_and_namespace(association_namespaced)
116
+ split = association_namespaced.split(NAMESPACE_SYMBOL)
117
+ if split.size > 1
118
+ namespace = split[0]
119
+ association = split[1]
120
+ else
121
+ namespace = ''
122
+ association = association_namespaced
123
+ end
124
+ return association, namespace
125
+ end
126
+
112
127
  end
113
128
 
114
129
  end
@@ -1,3 +1,3 @@
1
1
  module ArelSearch
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arel_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-27 00:00:00.000000000 Z
12
+ date: 2013-08-28 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Arel based search gem
15
15
  email: