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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96917fcf22ad5aa27ddcbf7f87e6883b3c6bd23b
4
- data.tar.gz: fe95850d9a5896d34f3b9bc87be8f226d1a83067
3
+ metadata.gz: 37d956fa1ce6a3a8534af0c372eb7ad16b1d375c
4
+ data.tar.gz: 8ca67e6c45455ebdce3cf3c11c315e239ac965bb
5
5
  SHA512:
6
- metadata.gz: 6f13ad6bb35ea05f661e16ea6349c221b65db8e94a82e416e1950b76fc709daeab929b369de1119e6c517b3f968b3ad351f13e3be69f4103b36f8e71851221ae
7
- data.tar.gz: b95f69ee1117ee95fdf546cc53c1a282d50d13fec2bd466bd97df77f395913b995482957fa50c635ac533f9d657fe89b8396574049473067ac41506d2462185e
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.
@@ -1,5 +1,6 @@
1
1
  require "action_query/version"
2
2
  require "action_query/route"
3
+ require "generators/action_query/install"
3
4
 
4
5
  module ActionQuery
5
6
  module Rails
@@ -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: route.parts.map(&:to_s),
16
- path: route.path.spec.to_s,
17
- verb: route.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: route.defaults[:action]
24
+ method: route.defaults[:action],
25
+ array: !notArray
20
26
  }
21
27
  obj[route.defaults[:action]] << path
22
28
  end
@@ -1,3 +1,3 @@
1
1
  module ActionQuery
2
- VERSION = "0.5.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  # //= require_tree ./extensions
2
2
  # //= require action_query/class_methods
3
3
  # //= require action_query/private_methods
4
+ # //= require action_query/collection
4
5
  @ActionQuery ?= {}
5
6
  class ActionQuery.$Base extends Module
6
7
  @extend(ActionQuery.$ClassMethods)
@@ -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
- @_sendRequest(path,params)
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)
@@ -0,0 +1,7 @@
1
+ class ActionQuery::InstallGenerator < Rails::Generators::Base
2
+ source_root File.join(File.dirname(__FILE__), 'templates')
3
+
4
+ def copy_initializer
5
+ template "initializer.rb", "config/initializers/action_query.rb"
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ Rails.application.configure do
2
+ config.action_query = {
3
+ # controller: {
4
+ # collection_method: {array: true},
5
+ # member_method: {array: false}
6
+ # }
7
+ }
8
+ end
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.5.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