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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c61b012dfc9cccbae90d2061d52e8a4d688890c
4
- data.tar.gz: 79b90af685032fb41cd27a4908c52a72a1782a32
3
+ metadata.gz: 81b5c788930e7f1eb49c7dabf748020bb49551b1
4
+ data.tar.gz: 28707829eb2eeda2982a270f082966972df3701c
5
5
  SHA512:
6
- metadata.gz: 13d1aee432f57aa4cc02c9403341defd8617a9934c0f7e84f2b3c706aa69ab5aa518dd87ece694310e4537762cacde4804753054ba85c0f8ddf1dde1c4b2e89e
7
- data.tar.gz: 36e9379fdc0c6f6c265e34aa924b40bcd7e893509389c143c00a2590c87de1e27854bac6269d3ad73016aa40f5c4f4bda24061d192ad078c7c7615faf972f39c
6
+ metadata.gz: b945c8d58e369547feea8724af0c273058999ddfaeda20c602df4437e8a2203ae88c6a9059ca644f6b161923f9ee7e792f1de71b0950b7361b8581850db8e39f
7
+ data.tar.gz: 3d35f1926f11995b97c655d52593187ce60aa2cefccc9cbcbf7dab053aa05e2ba39eee167eba938ec1192c7522b7adc00a21c637210c9cea76e60c3d3d9b000d
@@ -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
@@ -1,3 +1,3 @@
1
1
  module DbAccessor
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -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)
@@ -1,6 +1,7 @@
1
1
  class CreateEngines < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :engines do |e|
4
+ e.string :name
4
5
  e.column :engine_conf, :json
5
6
  e.integer :application_id
6
7
  e.timestamps
@@ -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
- validates_presence_of :engine_conf
8
- has_one :engine_data
9
- belongs_to :application
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: {5 => {engine_conf: {name: 'name', similarity_metric: 'similarity_metric',reco_algo: 'reco_algo',neighborhood: 'neighborhood'}.to_json} } }
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: {engine_conf: {name: 'engine'+nb.to_s,action: ['LIKE','SHARE'],score: [2,5],algorithm: 'Person',type: 'UserBased', neighborhood: 5 }.to_json ,application_id: 2}} }
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.5
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-07 00:00:00.000000000 Z
11
+ date: 2014-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler