shnaider_code 1.1.5 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/shnaider_code/version.rb +1 -1
- data/lib/source/attr_limited_regex_accessor.rb +43 -0
- data/lib/source/controllers/create_student_controller.rb +8 -0
- data/lib/source/controllers/edit_student_controller.rb +10 -0
- data/lib/source/controllers/view_controller.rb +106 -0
- data/lib/source/data_construct_pattern/data_construct_pattarn.rb +25 -0
- data/lib/source/data_list.rb +59 -0
- data/lib/source/data_list_student_short.rb +28 -0
- data/lib/source/data_table.rb +21 -0
- data/lib/source/database/scripts/create_table.sql +10 -0
- data/lib/source/database/scripts/fill_data.sql +14 -0
- data/lib/source/database/students_db.rb +78 -0
- data/lib/source/database/students_list_db.rb +36 -0
- data/lib/source/student/abstract_student.rb +26 -0
- data/lib/source/student/student.rb +120 -0
- data/lib/source/student/student_short.rb +59 -0
- data/lib/source/student_list_format.rb +50 -0
- data/lib/source/students_list.rb +43 -0
- data/lib/source/students_list_adapter.rb +89 -0
- data/lib/source/students_list_format_strategy.rb +59 -0
- data/lib/source/students_tests.rb +72 -0
- data/shnaider_code.gemspec +4 -6
- metadata +25 -33
- data/CHANGELOG.md +0 -5
- data/CODE_OF_CONDUCT.md +0 -84
- data/Documentation.md +0 -33
- data/Gemfile +0 -13
- data/Gemfile.lock +0 -92
- data/lib/source/controllers/student_input_form/student_input_form_controller_create.rb +0 -68
- data/lib/source/controllers/student_input_form/student_input_form_controller_edit.rb +0 -78
- data/lib/source/controllers/tab_students_controller.rb +0 -104
- data/lib/source/db_config/config.example.yaml +0 -5
- data/lib/source/db_config/migrations/001_create_table_student.sql +0 -12
- data/lib/source/db_config/mock_data/fill_student.sql +0 -6
- data/lib/source/models/student.rb +0 -125
- data/lib/source/models/student_base.rb +0 -128
- data/lib/source/models/student_short.rb +0 -58
- data/lib/source/repositories/adapters/db_source_adapter.rb +0 -54
- data/lib/source/repositories/adapters/file_source_adapter.rb +0 -37
- data/lib/source/repositories/containers/data_list.rb +0 -74
- data/lib/source/repositories/containers/data_list_student_short.rb +0 -18
- data/lib/source/repositories/containers/data_table.rb +0 -35
- data/lib/source/repositories/data_sources/db_data_source.rb +0 -35
- data/lib/source/repositories/data_sources/file_data_source.rb +0 -77
- data/lib/source/repositories/data_sources/transformers/data_transformer_base.rb +0 -15
- data/lib/source/repositories/data_sources/transformers/data_transformer_json.rb +0 -16
- data/lib/source/repositories/data_sources/transformers/data_transformer_yaml.rb +0 -16
- data/lib/source/repositories/student_repository.rb +0 -37
- data/lib/source/util/logger_holder.rb +0 -29
- data/shnaider_code-1.1.4.gem +0 -0
- data/sig/shnaider_code.rbs +0 -4
@@ -1,74 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require './LabStudents/repositories/containers/data_table'
|
4
|
-
|
5
|
-
class DataList
|
6
|
-
# Это "абстрактный" класс
|
7
|
-
private_class_method :new
|
8
|
-
|
9
|
-
attr_writer :objects
|
10
|
-
|
11
|
-
# Конструктор, принимает массив любых объектов
|
12
|
-
def initialize(objects)
|
13
|
-
self.objects = objects
|
14
|
-
@listeners = []
|
15
|
-
end
|
16
|
-
|
17
|
-
def add_listener(listener)
|
18
|
-
@listeners << listener
|
19
|
-
end
|
20
|
-
|
21
|
-
def remove_listener(listener)
|
22
|
-
@listeners.delete(listener)
|
23
|
-
end
|
24
|
-
|
25
|
-
def notify
|
26
|
-
@listeners.each { |lst| lst.on_datalist_changed(data_table) }
|
27
|
-
end
|
28
|
-
|
29
|
-
# Выбрать элемент по номеру
|
30
|
-
def select_element(number)
|
31
|
-
self.selected_num = number < objects.size ? number : nil
|
32
|
-
end
|
33
|
-
|
34
|
-
def selected_id
|
35
|
-
objects[selected_num].id
|
36
|
-
end
|
37
|
-
|
38
|
-
# Получить DataTable со всеми элементами.
|
39
|
-
def data_table
|
40
|
-
result = []
|
41
|
-
counter = 0
|
42
|
-
objects.each do |obj|
|
43
|
-
row = []
|
44
|
-
row << counter
|
45
|
-
row.push(*table_fields(obj))
|
46
|
-
result << row
|
47
|
-
counter += 1
|
48
|
-
end
|
49
|
-
DataTable.new(result)
|
50
|
-
end
|
51
|
-
|
52
|
-
# Добавить элементы в конец списка
|
53
|
-
def replace_objects(objects)
|
54
|
-
self.objects = objects.dup
|
55
|
-
notify
|
56
|
-
end
|
57
|
-
|
58
|
-
protected
|
59
|
-
|
60
|
-
# Список значений полей для DataTable. Переопределить в наследниках
|
61
|
-
def table_fields(_obj)
|
62
|
-
[]
|
63
|
-
end
|
64
|
-
|
65
|
-
# Имена атрибутов объектов по порядку. Переопределить в наследниках
|
66
|
-
def column_names
|
67
|
-
[]
|
68
|
-
end
|
69
|
-
|
70
|
-
private
|
71
|
-
|
72
|
-
attr_reader :objects
|
73
|
-
attr_accessor :selected_num
|
74
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'data_list'
|
4
|
-
|
5
|
-
class DataListStudentShort < DataList
|
6
|
-
# Делаем приватный new предка публичным
|
7
|
-
public_class_method :new
|
8
|
-
|
9
|
-
def column_names
|
10
|
-
['Фамилия И. О.', 'Гит', 'Контакт']
|
11
|
-
end
|
12
|
-
|
13
|
-
protected
|
14
|
-
|
15
|
-
def table_fields(obj)
|
16
|
-
[obj.last_name_and_initials, obj.git, obj.contact]
|
17
|
-
end
|
18
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class DataTable
|
4
|
-
attr_reader :rows_count, :cols_count
|
5
|
-
|
6
|
-
# Конструктор, принимает 2D Array
|
7
|
-
def initialize(table)
|
8
|
-
self.rows_count = table.size
|
9
|
-
max_cols = 0
|
10
|
-
table.each { |row| max_cols = row.size if row.size > max_cols }
|
11
|
-
self.cols_count = max_cols
|
12
|
-
self.table = table
|
13
|
-
end
|
14
|
-
|
15
|
-
# Получить значение в ячейке [row, col]
|
16
|
-
def get_item(row, col)
|
17
|
-
return nil if row >= rows_count
|
18
|
-
return nil if col >= cols_count
|
19
|
-
|
20
|
-
table[row][col].dup
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_2d_array
|
24
|
-
table.dup
|
25
|
-
end
|
26
|
-
|
27
|
-
def to_s
|
28
|
-
"DataTable (#{rows_count}x#{cols_count})"
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
attr_accessor :table
|
34
|
-
attr_writer :rows_count, :cols_count
|
35
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'mysql2'
|
4
|
-
|
5
|
-
##
|
6
|
-
# Источник данных из БД
|
7
|
-
|
8
|
-
class DBDataSource
|
9
|
-
private_class_method :new
|
10
|
-
@instance_mutex = Mutex.new
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
db_config = YAML.load_file('./LabStudents/db_config/config.example.yaml').transform_keys(&:to_sym)
|
14
|
-
@client = Mysql2::Client.new(db_config)
|
15
|
-
@client.query_options.merge!(symbolize_keys: true)
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.instance
|
19
|
-
return @instance if @instance
|
20
|
-
|
21
|
-
@instance_mutex.synchronize do
|
22
|
-
@instance ||= new
|
23
|
-
end
|
24
|
-
|
25
|
-
@instance
|
26
|
-
end
|
27
|
-
|
28
|
-
def prepare_exec(statement, *params)
|
29
|
-
@client.prepare(statement).execute(*params)
|
30
|
-
end
|
31
|
-
|
32
|
-
def query(statement)
|
33
|
-
@client.query(statement)
|
34
|
-
end
|
35
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require './LabStudents/models/student'
|
4
|
-
require './LabStudents/models/student_short'
|
5
|
-
require './LabStudents/repositories/containers/data_list_student_short'
|
6
|
-
|
7
|
-
##
|
8
|
-
# Источник данных из файла
|
9
|
-
|
10
|
-
class FileDataSource
|
11
|
-
attr_writer :data_transformer
|
12
|
-
|
13
|
-
def initialize(data_transformer)
|
14
|
-
self.students = []
|
15
|
-
self.seq_id = 1
|
16
|
-
self.data_transformer = data_transformer
|
17
|
-
end
|
18
|
-
|
19
|
-
def load_from_file(file_path)
|
20
|
-
hash_list = data_transformer.str_to_hash_list(File.read(file_path))
|
21
|
-
self.students = hash_list.map { |h| Student.from_hash(h) }
|
22
|
-
update_seq_id
|
23
|
-
end
|
24
|
-
|
25
|
-
def save_to_file(file_path)
|
26
|
-
hash_list = students.map(&:to_hash)
|
27
|
-
File.write(file_path, data_transformer.hash_list_to_str(hash_list))
|
28
|
-
end
|
29
|
-
|
30
|
-
def student_by_id(student_id)
|
31
|
-
students.detect { |s| s.id == student_id }
|
32
|
-
end
|
33
|
-
|
34
|
-
def paginated_short_students(page, count, existing_data_list = nil)
|
35
|
-
offset = (page - 1) * count
|
36
|
-
slice = students[offset, count].map { |s| StudentShort.from_student(s) }
|
37
|
-
|
38
|
-
return DataListStudentShort.new(slice) if existing_data_list.nil?
|
39
|
-
|
40
|
-
existing_data_list.replace_objects(slice)
|
41
|
-
existing_data_list
|
42
|
-
end
|
43
|
-
|
44
|
-
def sorted
|
45
|
-
students.sort_by(&:last_name_and_initials)
|
46
|
-
end
|
47
|
-
|
48
|
-
def add_student(student)
|
49
|
-
student.id = seq_id
|
50
|
-
students << student
|
51
|
-
self.seq_id += 1
|
52
|
-
student.id
|
53
|
-
end
|
54
|
-
|
55
|
-
def replace_student(student_id, student)
|
56
|
-
idx = students.find_index { |s| s.id == student_id }
|
57
|
-
students[idx] = student
|
58
|
-
end
|
59
|
-
|
60
|
-
def remove_student(student_id)
|
61
|
-
students.reject! { |s| s.id == student_id }
|
62
|
-
end
|
63
|
-
|
64
|
-
def student_count
|
65
|
-
students.count
|
66
|
-
end
|
67
|
-
|
68
|
-
private
|
69
|
-
|
70
|
-
# Метод для актуализации seq_id
|
71
|
-
def update_seq_id
|
72
|
-
self.seq_id = students.max_by(&:id).id + 1
|
73
|
-
end
|
74
|
-
|
75
|
-
attr_reader :data_transformer
|
76
|
-
attr_accessor :students, :seq_id
|
77
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class DataTransformerBase
|
4
|
-
private_class_method :new
|
5
|
-
|
6
|
-
protected
|
7
|
-
|
8
|
-
def str_to_hash_list(str)
|
9
|
-
raise NotImplementedError('Should be implemented in child')
|
10
|
-
end
|
11
|
-
|
12
|
-
def hash_list_to_str(hash_list)
|
13
|
-
raise NotImplementedError('Should be implemented in child')
|
14
|
-
end
|
15
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'data_transformer_base'
|
4
|
-
require 'json'
|
5
|
-
|
6
|
-
class DataTransformerJSON < DataTransformerBase
|
7
|
-
public_class_method :new
|
8
|
-
|
9
|
-
def str_to_hash_list(str)
|
10
|
-
JSON.parse(str, { symbolize_names: true })
|
11
|
-
end
|
12
|
-
|
13
|
-
def hash_list_to_str(hash_list)
|
14
|
-
JSON.pretty_generate(hash_list)
|
15
|
-
end
|
16
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'data_transformer_base'
|
4
|
-
require 'yaml'
|
5
|
-
|
6
|
-
class DataTransformerYAML < DataTransformerBase
|
7
|
-
public_class_method :new
|
8
|
-
|
9
|
-
def str_to_hash_list(str)
|
10
|
-
YAML.safe_load(str).map { |h| h.transform_keys(&:to_sym) }
|
11
|
-
end
|
12
|
-
|
13
|
-
def hash_list_to_str(hash_list)
|
14
|
-
hash_list.map { |h| h.transform_keys(&:to_s) }.to_yaml
|
15
|
-
end
|
16
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
##
|
4
|
-
# Репозиторий студентов с CRUD операциями.
|
5
|
-
|
6
|
-
class StudentRepository
|
7
|
-
def initialize(data_source_adapter)
|
8
|
-
@data_source_adapter = data_source_adapter
|
9
|
-
end
|
10
|
-
|
11
|
-
def student_by_id(student_id)
|
12
|
-
@data_source_adapter.student_by_id(student_id)
|
13
|
-
end
|
14
|
-
|
15
|
-
##
|
16
|
-
# Получить page по счету count элементов (страница начинается с 1)
|
17
|
-
|
18
|
-
def paginated_short_students(page, count, existing_data_list = nil)
|
19
|
-
@data_source_adapter.paginated_short_students(page, count, existing_data_list)
|
20
|
-
end
|
21
|
-
|
22
|
-
def add_student(student)
|
23
|
-
@data_source_adapter.add_student(student)
|
24
|
-
end
|
25
|
-
|
26
|
-
def replace_student(student_id, student)
|
27
|
-
@data_source_adapter.replace_student(student_id, student)
|
28
|
-
end
|
29
|
-
|
30
|
-
def remove_student(student_id)
|
31
|
-
@data_source_adapter.remove_student(student_id)
|
32
|
-
end
|
33
|
-
|
34
|
-
def student_count
|
35
|
-
@data_source_adapter.student_count
|
36
|
-
end
|
37
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'logger'
|
4
|
-
|
5
|
-
##
|
6
|
-
# Обертка для хранения объекта Logger
|
7
|
-
|
8
|
-
class LoggerHolder
|
9
|
-
private_class_method :new
|
10
|
-
@instance_mutex = Mutex.new
|
11
|
-
|
12
|
-
attr_reader :logger
|
13
|
-
|
14
|
-
def initialize
|
15
|
-
@logger = Logger.new('log.txt')
|
16
|
-
|
17
|
-
# @logger = Logger.new(STDOUT)
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.instance
|
21
|
-
return @instance.logger if @instance
|
22
|
-
|
23
|
-
@instance_mutex.synchronize do
|
24
|
-
@instance ||= new
|
25
|
-
end
|
26
|
-
|
27
|
-
@instance.logger
|
28
|
-
end
|
29
|
-
end
|
data/shnaider_code-1.1.4.gem
DELETED
Binary file
|
data/sig/shnaider_code.rbs
DELETED