pureapi 0.1.1 → 0.2.4
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.
- checksums.yaml +4 -4
- data/lib/pureapi/model.rb +5 -0
- data/lib/pureapi/mongoid_model.rb +69 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9e9b3a5e0c3182cb226e18cab0a823d6e51007e
|
4
|
+
data.tar.gz: cebc42765564908818d3f4f31429143aa6694474
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cf9f0e4ac2dcdde53808ac20f2e675236ccfd52fae55c1cf57c4db9ace98c942ddeb9002e0c7da2f99f3c280a4664a77f60ce2e4874dccd89c20e8e2f2fe51d
|
7
|
+
data.tar.gz: e743cc09f7dc373191abc525ef1d0e7e5cc9e50746bb8547d9e621ee67e95d070c9624cfcb2d9c3e95f9b2728ff66b09b36952c766a7898abfba8b3fd65e3c06
|
data/lib/pureapi/model.rb
CHANGED
@@ -157,4 +157,9 @@ module Pureapi::Model
|
|
157
157
|
def default_onlyasjsons
|
158
158
|
self.column_names.map(&:to_sym)
|
159
159
|
end
|
160
|
+
|
161
|
+
# Require params is hash contain Integer :page, :per_page
|
162
|
+
def paginate(params)
|
163
|
+
self.limit(params[:per_page]).offset((params[:page] - 1) * params[:per_page])
|
164
|
+
end
|
160
165
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
require 'pureapi/model'
|
3
|
+
|
4
|
+
# Provide methods (override, polymorphic) for use data handling
|
5
|
+
# # => comfortable with gem mongoid
|
6
|
+
|
7
|
+
module Pureapi::MongoidModel
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
include Pureapi::Model
|
10
|
+
|
11
|
+
# Define constants
|
12
|
+
# Need upgrade with nlike operation
|
13
|
+
MONGODB_COMPARISON_OPERATORS = {
|
14
|
+
ne: '$ne',
|
15
|
+
gt: '$gt',
|
16
|
+
lt: '$lt',
|
17
|
+
gte: '$gte',
|
18
|
+
lte: '$lte',
|
19
|
+
like: '$regex',
|
20
|
+
regex: '$regex',
|
21
|
+
}
|
22
|
+
|
23
|
+
MONGODB_LOGICAL_OPERATORS = {
|
24
|
+
in: '$in'
|
25
|
+
}
|
26
|
+
|
27
|
+
def column_names
|
28
|
+
self.attribute_names
|
29
|
+
end
|
30
|
+
|
31
|
+
# Rewrite for comfortable with mongoid
|
32
|
+
# Comparsion operator conditions method
|
33
|
+
# Array +params+ contains hash = {f, o, v}
|
34
|
+
# :f is column name
|
35
|
+
# :o is comparsion operator
|
36
|
+
# :v is value
|
37
|
+
def compconds(params = [])
|
38
|
+
criterias = self
|
39
|
+
|
40
|
+
queries = {}
|
41
|
+
params.each do |param|
|
42
|
+
if param[:o] == '='
|
43
|
+
queries[param[:f]] = param[:v]
|
44
|
+
else
|
45
|
+
queries[param[:f]] = queries[param[:f]].is_a?(Hash) ? queries[param[:f]] : {}
|
46
|
+
queries[param[:f]][MONGODB_COMPARISON_OPERATORS[Pureapi::Model::COMPARISON_OPERATORS_INVERT[param[:o]]]] = param[:v]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
return criterias.where(queries)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Comparsion operator conditions method
|
54
|
+
# Array +params+ contains hash = {f, o, v}
|
55
|
+
# :f is column name
|
56
|
+
# :o is comparsion operator
|
57
|
+
# :v is value
|
58
|
+
def logicconds(params = [])
|
59
|
+
criterias = self
|
60
|
+
|
61
|
+
params.each do |param|
|
62
|
+
if param[:o] == Pureapi::Model::LOGICAL_OPERATORS[:in]
|
63
|
+
criterias = criterias.in(param[:f] => param[:v])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
return criterias.where({})
|
68
|
+
end
|
69
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pureapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dieu Pham
|
@@ -9,7 +9,21 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2017-08-10 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
13
27
|
description: A simple concern in model & controller for api
|
14
28
|
email: dieupv@topica.edu.vn
|
15
29
|
executables:
|
@@ -21,6 +35,7 @@ files:
|
|
21
35
|
- lib/pureapi.rb
|
22
36
|
- lib/pureapi/controller.rb
|
23
37
|
- lib/pureapi/model.rb
|
38
|
+
- lib/pureapi/mongoid_model.rb
|
24
39
|
homepage: http://rubygems.org/gems/pureapi
|
25
40
|
licenses:
|
26
41
|
- MIT
|