Class: JunglePath::Controller::Base
- Inherits:
-
Object
- Object
- JunglePath::Controller::Base
show all
- Defined in:
- lib/jungle_path/controller/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(current_identity, params, db, table_class) ⇒ Base
Returns a new instance of Base.
9
10
11
12
13
14
15
16
17
|
# File 'lib/jungle_path/controller/base.rb', line 9
def initialize(current_identity, params, db, table_class)
@current_identity = current_identity
@current_user = current_identity.user
@current_key = current_identity.key
@db = db
@table_class = table_class
@params = self.class.transform(params.to_h, table_class.columns)
end
|
Instance Attribute Details
#table_class ⇒ Object
Returns the value of attribute table_class.
8
9
10
|
# File 'lib/jungle_path/controller/base.rb', line 8
def table_class
@table_class
end
|
Instance Method Details
#create_table ⇒ Object
75
76
77
|
# File 'lib/jungle_path/controller/base.rb', line 75
def create_table
@db.schema.create_table @table_class
end
|
#delete ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/jungle_path/controller/base.rb', line 56
def delete
@db.transaction do
model = @table_class.new @params
self.class.validate_delete(model)
result = @db.delete._model(model)
end
end
|
#delete_rows ⇒ Object
64
65
66
67
68
69
|
# File 'lib/jungle_path/controller/base.rb', line 64
def delete_rows
@db.transaction do
model = @table_class.new @params
result = @db.delete._models(model, true)
end
end
|
#drop_table ⇒ Object
71
72
73
|
# File 'lib/jungle_path/controller/base.rb', line 71
def drop_table
@db.schema.drop_table @table_class
end
|
#insert(include_secure_columns: false) ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/jungle_path/controller/base.rb', line 37
def insert(include_secure_columns: false)
@db.transaction do
params = self.class.add_audit_parameter_values_for_insert(@params, @current_user, @current_key, @table_class)
model = @table_class.new params
self.class.validate_insert(model)
result = @db.insert._model(model)
result = self.class.handle_include_secure_columns_flag(result, include_secure_columns, @table_class)
end
end
|
#reset_table ⇒ Object
79
80
81
|
# File 'lib/jungle_path/controller/base.rb', line 79
def reset_table
@db.schema.reset_table @table_class
end
|
#select(include_secure_columns: false, use_only_pk_columns_to_select_if_available: true) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/jungle_path/controller/base.rb', line 19
def select(include_secure_columns: false, use_only_pk_columns_to_select_if_available: true)
@db.transaction do
if use_only_pk_columns_to_select_if_available and self.class.by_primary_key?(@params, @table_class.primary_key_columns)
pk_hash = @table_class.new(@params)._primary_key
model = @table_class.new(pk_hash)
result = @db.select._model(model) elsif self.class.by_primary_key?(@params, @table_class.primary_key_columns)
result = @db.select._model_by_any(@table_class.new(@params))
else
result = @db.select._models(@table_class.new(@params))
end
result = self.class.handle_include_secure_columns_flag(result, include_secure_columns, @table_class)
end
end
|
#update ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/jungle_path/controller/base.rb', line 47
def update
@db.transaction do
params = self.class.add_audit_parameter_values_for_update(@params, @current_user, @current_key, @table_class)
model = @table_class.new params
self.class.validate_update(model)
result = @db.update._model(model)
end
end
|