dbAccessor 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dbAccessor/base.rb +1 -1
- data/lib/dbAccessor/deleter/deleter.rb +8 -8
- data/lib/dbAccessor/version.rb +1 -1
- data/lib/dbAccessor/writer/writer.rb +1 -1
- data/spec/feed/dbTest/migration/create_table_engines.rb +1 -0
- data/spec/feed/dbTest/model/application.rb +7 -6
- data/spec/feed/dbTest/model/engine.rb +4 -3
- data/spec/updater_spec.rb +1 -1
- data/spec/writer_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81b5c788930e7f1eb49c7dabf748020bb49551b1
|
4
|
+
data.tar.gz: 28707829eb2eeda2982a270f082966972df3701c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b945c8d58e369547feea8724af0c273058999ddfaeda20c602df4437e8a2203ae88c6a9059ca644f6b161923f9ee7e792f1de71b0950b7361b8581850db8e39f
|
7
|
+
data.tar.gz: 3d35f1926f11995b97c655d52593187ce60aa2cefccc9cbcbf7dab053aa05e2ba39eee167eba938ec1192c7522b7adc00a21c637210c9cea76e60c3d3d9b000d
|
data/lib/dbAccessor/base.rb
CHANGED
@@ -59,7 +59,7 @@ module Db_Accessor
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def self.valid_object_columns?(model_name,content)
|
62
|
-
engine_columns = [:id,:engine_conf,:application_id]
|
62
|
+
engine_columns = [:id,:name,:engine_conf,:application_id]
|
63
63
|
engine_data_columns = [:id,:customer_id,:item_id,:preference,:engine_id]
|
64
64
|
app_columns = [:id,:name,:api_key,:url,:user_id]
|
65
65
|
user_columns = [:id,:login,:password,:firstname,:lastname,:gender,:email]
|
@@ -4,20 +4,20 @@ require_relative '../base'
|
|
4
4
|
|
5
5
|
class DbAccessor::Deleter < Db_Accessor::Base
|
6
6
|
|
7
|
-
|
7
|
+
|
8
8
|
def self.delete_all(given_object)
|
9
9
|
waited_keys = [:model_name,:condition]
|
10
10
|
if validate(given_object,waited_keys) && valid_condition?(given_object)
|
11
11
|
model = get_model_name(given_object)
|
12
12
|
condition = given_object[:condition]
|
13
|
-
condition == {} ? model.update_all("deleted = true") : model.where(condition).update_all("deleted = true")
|
13
|
+
condition == {} ? model.update_all("deleted = true") : model.where(condition).update_all("deleted = true")
|
14
14
|
return_response(200,"success")
|
15
15
|
else
|
16
16
|
return_response(400,"Not deleted")
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
|
21
21
|
def self.delete_by_id(given_param)
|
22
22
|
waited_keys = [:model_name,:id]
|
23
23
|
if validate(given_param,waited_keys) && validate_id(given_param[:id])
|
@@ -34,7 +34,7 @@ class DbAccessor::Deleter < Db_Accessor::Base
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def self.validate(param,waited_keys)
|
37
|
-
param.is_a?(Hash) && valid_keys?(param,waited_keys) && !validate_argument(param) && is_model?(param[:model_name])
|
37
|
+
param.is_a?(Hash) && valid_keys?(param,waited_keys) && !validate_argument(param) && is_model?(param[:model_name])
|
38
38
|
end
|
39
39
|
|
40
40
|
def self.validate_id(param)
|
@@ -50,15 +50,15 @@ class DbAccessor::Deleter < Db_Accessor::Base
|
|
50
50
|
end
|
51
51
|
return true
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def self.valid_condition?(param)
|
55
55
|
condition = param[:condition]
|
56
56
|
model_name = param[:model_name]
|
57
57
|
if condition.is_a?(Hash)
|
58
|
-
if !(condition.empty?)
|
58
|
+
if !(condition.empty?)
|
59
59
|
keys = condition.keys
|
60
60
|
values = condition.values
|
61
|
-
if !(valid_object_columns?(model_name,condition)) || validate_argument(condition) || !(valid_attributes_values?(condition))
|
61
|
+
if !(valid_object_columns?(model_name,condition)) || validate_argument(condition) || !(valid_attributes_values?(condition))
|
62
62
|
return false
|
63
63
|
end
|
64
64
|
else
|
@@ -69,5 +69,5 @@ class DbAccessor::Deleter < Db_Accessor::Base
|
|
69
69
|
end
|
70
70
|
return true
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
end
|
data/lib/dbAccessor/version.rb
CHANGED
@@ -40,7 +40,7 @@ private ######################################################################
|
|
40
40
|
content[:name].is_a?(String) && content[:api_key].is_a?(String) && content[:url].is_a?(String)
|
41
41
|
|
42
42
|
elsif model_name == ENGINE_MODEL
|
43
|
-
content[:engine_conf].is_a?(String) && content[:application_id].is_a?(Fixnum)
|
43
|
+
content[:name].is_a?(String) && content[:engine_conf].is_a?(String) && content[:application_id].is_a?(Fixnum)
|
44
44
|
|
45
45
|
elsif model_name == ENGINE_DATA_MODEL
|
46
46
|
content[:customer_id].is_a?(Fixnum) && content[:item_id].is_a?(Fixnum) && content[:preference].is_a?(Fixnum) && content[:engine_id].is_a?(Fixnum)
|
@@ -8,19 +8,20 @@ require_relative 'config'
|
|
8
8
|
|
9
9
|
class Application < ActiveRecord::Base
|
10
10
|
attr_accessor :api_key_to_update
|
11
|
-
|
11
|
+
|
12
12
|
|
13
13
|
validates_presence_of :name, :api_key, :url
|
14
14
|
validates_uniqueness_of :api_key, :url
|
15
|
+
validates_uniqueness_of :name, :scope => :user_id
|
15
16
|
has_many :engines
|
16
17
|
belongs_to :user
|
17
|
-
|
18
|
+
|
18
19
|
|
19
20
|
after_save :save_app
|
20
21
|
# before_update :save_status
|
21
22
|
# after_update :update_app
|
22
23
|
|
23
|
-
private
|
24
|
+
private
|
24
25
|
|
25
26
|
def save_status
|
26
27
|
@api_key_to_update = api_key
|
@@ -29,7 +30,7 @@ class Application < ActiveRecord::Base
|
|
29
30
|
def save_app
|
30
31
|
option = {user: false,app: true}
|
31
32
|
to_save = {api_key: api_key}.to_json
|
32
|
-
RestClient.post("#{AUTH_MANAGER_URI}auth_manager/adder/save",{object: to_save,option: option})
|
33
|
+
RestClient.post("#{AUTH_MANAGER_URI}auth_manager/adder/save",{object: to_save,option: option})
|
33
34
|
end
|
34
35
|
|
35
36
|
def update_app
|
@@ -37,9 +38,9 @@ class Application < ActiveRecord::Base
|
|
37
38
|
old_obj = {api_key: @api_key_to_update}.to_json
|
38
39
|
to_update = {api_key: api_key}.to_json
|
39
40
|
if deleted == false
|
40
|
-
RestClient.put("#{AUTH_MANAGER_URI}auth_manager/updater/update",{object: to_update,old_object: old_obj,option: option})
|
41
|
+
RestClient.put("#{AUTH_MANAGER_URI}auth_manager/updater/update",{object: to_update,old_object: old_obj,option: option})
|
41
42
|
else
|
42
|
-
RestClient.delete("#{AUTH_MANAGER_URI}auth_manager/deleter/delete",{object: to_update,option: option})
|
43
|
+
RestClient.delete("#{AUTH_MANAGER_URI}auth_manager/deleter/delete",{object: to_update,option: option})
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
@@ -4,8 +4,9 @@ require_relative 'application'
|
|
4
4
|
|
5
5
|
class Engine < ActiveRecord::Base
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
validates_uniqueness_of :name , :scope => :application_id
|
8
|
+
validates_presence_of :engine_conf,:name
|
9
|
+
has_one :engine_data
|
10
|
+
belongs_to :application
|
10
11
|
|
11
12
|
end
|
data/spec/updater_spec.rb
CHANGED
@@ -17,7 +17,7 @@ describe DbAccessor::Updater do
|
|
17
17
|
param = {model_name: "Application",attributes: {15 => {api_key: UUID.new.generate}} }
|
18
18
|
it {expect((DbAccessor::Updater.update_by_id(param))[:code]).to eq 200 }
|
19
19
|
|
20
|
-
param = {model_name: "Engine",attributes: {
|
20
|
+
param = {model_name: "Engine",attributes: {1 => {engine_conf: {similarity_metric: 'similarity_metric',reco_algo: 'reco_algo',neighborhood: 'neighborhood'}.to_json} } }
|
21
21
|
it {expect((DbAccessor::Updater.update_by_id(param))[:code]).to eq 200 }
|
22
22
|
end
|
23
23
|
|
data/spec/writer_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe DbAccessor::Writer do
|
|
10
10
|
|
11
11
|
let(:app) { {model_name: 'Application',content: {name: 'desert'+nb.to_s,api_key: api_key,url: 'http://www.desert'+nb.to_s+'.com',user_id: 2}} }
|
12
12
|
|
13
|
-
let(:engine) { {model_name: 'Engine',content: {
|
13
|
+
let(:engine) { {model_name: 'Engine',content: {name: 'engine'+nb.to_s,engine_conf: {action: ['LIKE','SHARE'],score: [2,5],algorithm: 'Person',type: 'UserBased', neighborhood: 5 }.to_json ,application_id: 2}} }
|
14
14
|
|
15
15
|
describe".write_object" do
|
16
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbAccessor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fabira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|