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_user, current_key, params, db, table_class) ⇒ Base
Returns a new instance of Base.
9
10
11
12
13
14
15
16
|
# File 'lib/jungle_path/controller/base.rb', line 9
def initialize(current_user, current_key, params, db, table_class)
@current_user = current_user
@current_key = current_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
74
75
76
|
# File 'lib/jungle_path/controller/base.rb', line 74
def create_table
@db.schema.create_table @table_class
end
|
#delete ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/jungle_path/controller/base.rb', line 55
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
63
64
65
66
67
68
|
# File 'lib/jungle_path/controller/base.rb', line 63
def delete_rows
@db.transaction do
model = @table_class.new @params
result = @db.delete._models(model, true)
end
end
|
#drop_table ⇒ Object
70
71
72
|
# File 'lib/jungle_path/controller/base.rb', line 70
def drop_table
@db.schema.drop_table @table_class
end
|
#insert(include_secure_columns: false) ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/jungle_path/controller/base.rb', line 36
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
78
79
80
|
# File 'lib/jungle_path/controller/base.rb', line 78
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
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/jungle_path/controller/base.rb', line 18
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
46
47
48
49
50
51
52
53
|
# File 'lib/jungle_path/controller/base.rb', line 46
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
|