easy_model_selects 0.9.0 → 0.9.9.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0a36ff90a8806ad65ab9bfce0b74483fac7644f
4
- data.tar.gz: 5c96a69b2d284507d05e77561a1540ea0c6b31b9
3
+ metadata.gz: a818e8c19d1a52a71e1b1fccfa322149a5e313f8
4
+ data.tar.gz: 7f2a9832f1a1c9ee099a4fefaf1442af5c998d46
5
5
  SHA512:
6
- metadata.gz: 4ced771948aa4698d89f0d3a05d0000f92f7b3bf13a87c545c14558cdad4b53c4d760e7eedeb1beac72c82e9af3185cdfdd44d04ebc5c096d90fe217c9e7118a
7
- data.tar.gz: 3d4904dace53c3040e671c8f3c24687af87a095fa96263f9e3d8ea7c6b59c07a68f479a750182bc0235471d596a1253e0c098d6b90f28fe667cf305976aeacb8
6
+ metadata.gz: 09ef4e403148bf8d0808a360ab2400ae08137a9cd494e87064b53544066eee042091230a58eae478baad3f9cbc25af385060e015b26bd81a89be1449d5a75137
7
+ data.tar.gz: 35b3f637b2f4eb35ed4d0d23c55aa63748f1695ff092810d0196a4fd99938a9618d2a309aab46655dd9d053e935169c7edf4e4f108d36bdc65bdce531af7e6ae
data/README.md CHANGED
@@ -22,7 +22,11 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ #!!!start api settings
26
+ ressource_name = "Appointment" #capitalized makes it a bit faster, but it does not need to be done // you need to have a controller, model and an entity in place with this name
27
+ #right down what you want, ressource_method or all
28
+ operations = "all"
29
+ EasyApiOperations.set_up_api(self, ressource_name, operations)
26
30
 
27
31
  ## Development
28
32
 
@@ -1,78 +1,144 @@
1
1
  require "easy_model_selects/version"
2
2
 
3
3
  module EasyModelSelects
4
-
5
- def self.get_where_statement_from_param(params)
6
- #prepare where statemant out of names and values in an array
7
- where_condition = []
8
- params.each do |param_name, param_value|
9
- where_condition = get_where_statement(param_name, param_value, where_condition)
10
- end
11
- where_condition[0] = delete_last_and(where_condition[0])
12
- where_condition
13
- end
4
+ @@modifiers = [{">>"=> ">","<<"=> "<","=="=> "=","<="=> "<=",">="=> ">=", "$N" => "!=", "$L"=> "LIKE", "$I"=> "IN"},
5
+ {">>"=> "$gt","<<"=> "$lt","=="=> "$eq","<="=> "$lte",">="=> "$gte", "$N"=> "$ne", "$I"=> "$in", "Value splitting for Array for $in"=>"$/"}]
6
+ #0 => sql
7
+ #1 => mongodb
8
+ #$/ to split arrays for $I
9
+ @@operators = [{"$and"=>"and","$xor"=>"or"},
10
+ {"$and"=>"$and","$xor"=>"$or"}]
14
11
 
15
- def self.get_where_statement(param_name, param_value, where_condition)
16
- #some stuff to prepare everything
17
- modifiers = {">>"=> ">","<<"=> "<","=="=> "=","<="=> "<=",">="=> ">=", "LK"=> "LIKE", "IN"=> "IN"}
18
- operators = {"!and!"=>"and","!xor!"=>"or"}
19
-
20
- #care for easy writing
21
- param_name = "updated_at" if param_name == "modified_since"
22
-
23
- #care for operator staff
24
- if param_value.include? operators.keys.first#each element recommendet, but not necessary at the moment
25
- operatorkey = operators.keys.first
26
- else
27
- if param_value.include? operators.keys.last
28
- operatorkey = operators.keys.last
29
- else
30
- operatorkey = "!and!"
12
+ #better gem functionality
13
+ def self.set_configurations(options = {})
14
+ changed = 0
15
+ if options.include?(:db)
16
+ if options[:db] == :mongodb
17
+ @@db = 1
18
+ else
19
+ @@db = 0
20
+ end
21
+ changed = changed + 1
31
22
  end
23
+ "#{changed} #{changed > 1 ? "Configurations" : "Configuration"} changed."
32
24
  end
33
-
34
- param_value.split(operatorkey).each do |param_value_sep|
35
- if param_value_sep == param_value.split(operatorkey).last
36
- #operator to next statement needs to be and not or, or can just be between a condition for one attribute
37
- operatorkey = "!and!"
25
+
26
+ def self.modifiers(options = {})
27
+ if options.include?(:db)
28
+ db = options[:db] == :mongodb ? 1 : 0
29
+ else
30
+ db = 0
38
31
  end
39
-
40
- #care for modifiers
41
- if modifiers.key? param_value_sep[0..1]
42
- modifier = modifiers[param_value_sep[0..1]]
43
- param_value_sep = param_value_sep[2..param_value_sep.length]
32
+ @@modifiers[db]
33
+ end
34
+ def self.operators(options = {})
35
+ if options.include?(:db)
36
+ db = options[:db] == :mongodb ? 1 : 0
44
37
  else
45
- modifier = "="
38
+ db = 0
46
39
  end
47
-
48
- where_condition = get_where_condition(param_name, param_value_sep, where_condition, modifier, operators[operatorkey])
40
+ @@operators[db]
49
41
  end
50
42
 
51
- #care for array staff
52
- #if array param_value, the staff should be selected in more optimized way: (selecting every given possibility instead of just one)
53
- if param_value.include? "{" and param_value.include? "}"
54
- array_to_be_found = param_value.clone
55
- array_to_be_found.remove!("{","}")
43
+ #actual key funtions
44
+ def self.get_where_statement_from_param(params, options = {})
45
+ #options handling
46
+ if options.include?(:db)
47
+ @@db = options[:db] == :mongodb ? 1 : 0
48
+ else
49
+ @@db = 0
50
+ end
51
+
52
+ #prepare where statemant out of names and values in an array
53
+ @@db == 0 ? where_condition = [] : where_condition = {}
54
+ params.each do |param_name, param_value|
55
+ where_condition = get_where_statement(param_name, param_value, where_condition)
56
+ end
57
+ #delete last connection in sql queries
58
+ if @@db == 0
59
+ where_condition[0] = delete_last_and(where_condition[0])
60
+ end
61
+ where_condition
62
+ end
63
+
64
+ def self.get_where_statement(param_name, param_value, where_condition)
65
+
66
+ #care for easy writing
67
+ param_name = "updated_at" if param_name == "modified_since"
68
+
69
+ #care for operator staff
70
+ operatorkey = "$and"
71
+ modifier = @@modifiers[@@db]["=="]
72
+ if (defined? param_value.include?) == nil #fixnum and integer do not have include function
73
+ param_value = [param_value]
74
+ end
75
+
76
+ if param_value.include? @@operators[@@db].keys.last#each element recommendet, but not necessary at the moment
77
+ operatorkey = @@operators[@@db].keys.last
78
+ end
79
+
80
+ param_size = param_value.split(operatorkey).size
81
+ param_value.split(operatorkey).each_with_index do |param_value_sep, index|
82
+ if @@db == 0 and index == param_size - 1
83
+ #operator to next statement needs to be and not or, or can just be between a condition for one attribute
84
+ operatorkey = "$and"
85
+ end
86
+
87
+ #care for modifiers
88
+ if @@modifiers[@@db].key? param_value_sep[0..1]
89
+ modifier = @@modifiers[@@db][param_value_sep[0..1]]
90
+ param_value_sep = param_value_sep[2..param_value_sep.length]
91
+ end
56
92
 
57
- if !where_condition[0].nil?
58
- where_condition[0] = delete_last_and(where_condition[0])
59
- where_condition[0] = "#{where_condition[0]} or "
93
+ where_condition = get_where_condition(param_name, param_value_sep, where_condition, modifier, @@operators[@@db][operatorkey])
60
94
  end
95
+
96
+ #care for array staff
97
+ #if array param_value, the staff should be selected in more optimized way: (selecting every given possibility instead of just one)
98
+ if @@db == 0
99
+ if param_value.include? "{" and param_value.include? "}"
100
+ array_to_be_found = param_value.clone
101
+ array_to_be_found.remove!("{","}")
61
102
 
62
- array_to_be_found.split(",").each do |array_value|
63
- where_condition[0] = "#{where_condition[0]}(?) = ANY (#{param_name}) or "#question
64
- where_condition.push "#{array_value}" #values
103
+ if !where_condition[0].nil?
104
+ where_condition[0] = delete_last_and(where_condition[0])
105
+ where_condition[0] = "#{where_condition[0]} or "
106
+ end
107
+
108
+ array_to_be_found.split(",").each do |array_value|
109
+ where_condition[0] = "#{where_condition[0]}(?) = ANY (#{param_name}) or "#question
110
+ where_condition.push "#{array_value}" #values
111
+ end
112
+ end
113
+ else
114
+ #no mongodb array support yet
65
115
  end
116
+ #return
117
+ where_condition
118
+ end
119
+ def self.get_where_condition(param_name, param_value, where_condition, modifier, operator)
120
+ if @@db == 0
121
+ where_condition[0] = "#{where_condition[0]}#{param_name} #{modifier} (?) #{operator} "#question
122
+ where_condition.push (modifier != "IN" ? "#{param_value}" : param_value.split("$/") )
123
+ else
124
+ where_condition["#{operator}"] = [] unless where_condition.include?("#{operator}")
125
+ where_condition["#{operator}"] << {}
126
+ where_condition["#{operator}"][where_condition["#{operator}"].size - 1]["#{param_name}"] = {}
127
+ where_condition["#{operator}"][where_condition["#{operator}"].size - 1]["#{param_name}"]["#{modifier}"] = (modifier != "$in" ? "#{param_value}" : param_value.split("$/") )
128
+ end
129
+ #return
130
+ where_condition
131
+ end
132
+
133
+ # db.inventory.where( {
134
+ # $and : [
135
+ # { $or : [ { price : 0.99 }, { price : 1.99 } ] },
136
+ # { $or : [ { sale : true }, { qty : { $lt : 20 } } ] }
137
+ # ]
138
+ # } )
139
+ # db.inventory.find( { qty: { $in: [ 5, 15 ] } } )
140
+
141
+ def self.delete_last_and(wrong_and_at_the_end)
142
+ no_and_at_the_end = wrong_and_at_the_end.from(0).to(wrong_and_at_the_end.length - 5)
66
143
  end
67
-
68
- #return
69
- where_condition
70
- end
71
- def self.get_where_condition(param_name, param_value, where_condition, modifier, operator)
72
- where_condition[0] = "#{where_condition[0]}#{param_name} #{modifier} (?) #{operator} "#question
73
- where_condition.push "#{param_value}" #values
74
- end
75
- def self.delete_last_and(wrong_and_at_the_end)
76
- no_and_at_the_end = wrong_and_at_the_end.from(0).to(wrong_and_at_the_end.length - 5)
77
- end
78
144
  end
@@ -1,3 +1,3 @@
1
1
  module EasyModelSelects
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.9.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_model_selects
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bjoern Moeller / Christian Hentke
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-06 00:00:00.000000000 Z
11
+ date: 2016-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler