action_query 0.5.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/action_query.rb +1 -0
- data/lib/action_query/route.rb +10 -4
- data/lib/action_query/version.rb +1 -1
- data/lib/assets/javascripts/action_query/base.coffee +1 -0
- data/lib/assets/javascripts/action_query/class_methods.coffee +15 -2
- data/lib/assets/javascripts/action_query/collection.coffee +10 -0
- data/lib/generators/action_query/install.rb +7 -0
- data/lib/generators/action_query/templates/initializer.rb +8 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37d956fa1ce6a3a8534af0c372eb7ad16b1d375c
|
4
|
+
data.tar.gz: 8ca67e6c45455ebdce3cf3c11c315e239ac965bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b002ef261e2681bf900edbd3854496c4f12bc68c277b3a46a22402d30b04dccd4dc1e0ec780ae7d706da4c0c0c202d174d890bc511b627bcdb58d762da7aff8
|
7
|
+
data.tar.gz: 26e6002a5a0d21ca43314885f2e270781e8190b597f61713496e244df7cd59042e5d14c31705368b1773f8d9aa8dd6b89920135573e2730d2eba7484518e2ff6
|
data/README.md
CHANGED
@@ -18,6 +18,12 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
$ gem install action_query
|
20
20
|
|
21
|
+
Install the action_query config if you have non standard custom routes
|
22
|
+
|
23
|
+
$ rails g action_query:install
|
24
|
+
|
25
|
+
And then edit the file config/initializers/action_query.rb to declare which routes return array's vs members
|
26
|
+
|
21
27
|
## Usage
|
22
28
|
|
23
29
|
Javascript classes with the ActionQuery name space will be created. These classes will coincide with models that have routes in the routes.rb.
|
data/lib/action_query.rb
CHANGED
data/lib/action_query/route.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module ActionQuery
|
2
2
|
module Route
|
3
3
|
def self.result
|
4
|
+
variances = HashWithIndifferentAccess.new(::Rails.application.config.action_query) rescue {}
|
4
5
|
controllers = HashWithIndifferentAccess.new
|
5
6
|
::Rails.application.routes.routes.each do |route|
|
6
7
|
next unless route.defaults[:controller]
|
@@ -11,12 +12,17 @@ module ActionQuery
|
|
11
12
|
obj = obj[name.classify()]
|
12
13
|
end
|
13
14
|
obj[route.defaults[:action]] ||= []
|
15
|
+
notArray = !!route.path.spec.to_s.match(/\:id/) || ['CREATE','NEW'].include?(route.defaults[:action].upcase)
|
16
|
+
if (variance = HashWithIndifferentAccess.new(variances[route.defaults[:controller]])).present?
|
17
|
+
notArray = !variance[route.defaults[:action]][:array] unless variance[route.defaults[:action]].nil?
|
18
|
+
end
|
14
19
|
path = {
|
15
|
-
parts:
|
16
|
-
path:
|
17
|
-
verb:
|
20
|
+
parts: route.parts.map(&:to_s),
|
21
|
+
path: route.path.spec.to_s,
|
22
|
+
verb: route.verb,
|
18
23
|
requirements: route.required_parts.map(&:to_s),
|
19
|
-
method:
|
24
|
+
method: route.defaults[:action],
|
25
|
+
array: !notArray
|
20
26
|
}
|
21
27
|
obj[route.defaults[:action]] << path
|
22
28
|
end
|
data/lib/action_query/version.rb
CHANGED
@@ -18,10 +18,23 @@ class @ActionQuery.$ClassMethods
|
|
18
18
|
path = path.replace /\(.*\)/, (match) ->
|
19
19
|
return '' if match.indexOf(':') >= 0
|
20
20
|
return match[1..-2]
|
21
|
-
paths.push(weight: route.requirements.length, path: path, verb: route.verb)
|
21
|
+
paths.push(weight: route.requirements.length, path: path, verb: route.verb, method: route.method, array: route.array)
|
22
22
|
weight = paths.pluck('weight').max()
|
23
23
|
path = (paths.filter (path) -> path.weight == weight).first()
|
24
|
-
|
24
|
+
if path.array
|
25
|
+
@_fetchCollection(path,params)
|
26
|
+
else
|
27
|
+
@_sendRequest(path,params)
|
28
|
+
|
29
|
+
_fetchCollection: (details,params) ->
|
30
|
+
data = {}
|
31
|
+
data[@name.underscore()] = params
|
32
|
+
promise = $.ajax(
|
33
|
+
url: details.path
|
34
|
+
method: details.verb
|
35
|
+
data: data
|
36
|
+
)
|
37
|
+
return new ActionQuery.$Collection(@,promise)
|
25
38
|
|
26
39
|
_sendRequest: (details,params) ->
|
27
40
|
data = {}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
@ActionQuery ?= {}
|
2
|
+
class @ActionQuery.$Collection extends Array
|
3
|
+
constructor: (@klass,@$promise) ->
|
4
|
+
@$promise.then @__initializeRecords__.bind(@)
|
5
|
+
__initializeRecords__: (records) ->
|
6
|
+
for record in records
|
7
|
+
rec = new @klass
|
8
|
+
rec.$promise = @$promise
|
9
|
+
rec.__processResponse__(record)
|
10
|
+
@push(rec)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Moody
|
@@ -90,10 +90,13 @@ files:
|
|
90
90
|
- lib/assets/javascripts/action_query/base.coffee
|
91
91
|
- lib/assets/javascripts/action_query/class_methods.coffee
|
92
92
|
- lib/assets/javascripts/action_query/classes.coffee.erb
|
93
|
+
- lib/assets/javascripts/action_query/collection.coffee
|
93
94
|
- lib/assets/javascripts/action_query/extensions/array.coffee
|
94
95
|
- lib/assets/javascripts/action_query/extensions/inflection.js
|
95
96
|
- lib/assets/javascripts/action_query/extensions/module.coffee
|
96
97
|
- lib/assets/javascripts/action_query/private_methods.coffee
|
98
|
+
- lib/generators/action_query/install.rb
|
99
|
+
- lib/generators/action_query/templates/initializer.rb
|
97
100
|
homepage: https://github.com/cmoodyEIT/action_query
|
98
101
|
licenses:
|
99
102
|
- MIT
|