rubbish_code 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/CODE_OF_CONDUCT.md +84 -0
  4. data/Gemfile +13 -0
  5. data/lib/rubbish_code/version.rb +5 -0
  6. data/lib/rubbish_code.rb +10 -0
  7. data/lib/source/controllers/student_input_form/student_input_form_controller_create.rb +59 -0
  8. data/lib/source/controllers/student_input_form/student_input_form_controller_edit.rb +68 -0
  9. data/lib/source/db_config/mock_data/fill_student.sql +5 -0
  10. data/lib/source/repositories/adapters/db_source_adapter.rb +54 -0
  11. data/lib/source/repositories/adapters/file_source_adapter.rb +37 -0
  12. data/lib/source/repositories/containers/data_list.rb +74 -0
  13. data/lib/source/repositories/containers/data_list_student_short.rb +18 -0
  14. data/lib/source/repositories/containers/data_table.rb +35 -0
  15. data/lib/source/repositories/data_sources/db_data_source.rb +36 -0
  16. data/lib/source/repositories/data_sources/file_data_source.rb +75 -0
  17. data/lib/source/repositories/data_sources/transformers/data_transformer_base.rb +15 -0
  18. data/lib/source/repositories/data_sources/transformers/data_transformer_json.rb +16 -0
  19. data/lib/source/repositories/data_sources/transformers/data_transformer_yaml.rb +16 -0
  20. data/rubbish_code.gemspec +17 -0
  21. data/sig/ribbish_code.rbs +4 -0
  22. metadata +33 -12
  23. /data/{controllers → lib/source/controllers}/tab_students_controller.rb +0 -0
  24. /data/{db_config → lib/source/db_config}/config.yaml +0 -0
  25. /data/{db_config → lib/source/db_config}/migrations/001_create_table_student.sql +0 -0
  26. /data/{models → lib/source/models}/student.rb +0 -0
  27. /data/{models → lib/source/models}/student_base.rb +0 -0
  28. /data/{models → lib/source/models}/student_short.rb +0 -0
  29. /data/{models → lib/source/models}/student_test.rb +0 -0
  30. /data/{repositories → lib/source/repositories}/student_repository.rb +0 -0
  31. /data/{util → lib/source/util}/logger_holder.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2dafe2051c5e2de11d72e00a434486b1bd66b1914411ac64b216918181f7fa8b
4
- data.tar.gz: 0216bdf9531c3876cc9ee8667641e8178fb16c9f6427ee5c5f30fcc344510af5
3
+ metadata.gz: 704e3897e8f44aebbccd201679e9ecf8188969a0fa0e2e9df5e025dce7bf8cd5
4
+ data.tar.gz: 6fd1c258b63ba5079253bb0849f8ad66d689008691ac2a0b9da690abb51c95b5
5
5
  SHA512:
6
- metadata.gz: 81862c94d927737e281b8c0fb394a01f3a94ac9a496646ec24649a8cd0dc3b32b9134fbd220d5b56a2cc5027d2206ded5b443187e7f3013794451271fbf054d5
7
- data.tar.gz: 5faf849675ce3e4d28408ea9375f20ecab248e10fa7eaa780fd4cf474f55d9a5bedf97b106684fdcf614d432096005bce44d78a3ba1b983d12733e5cee2fbb71
6
+ metadata.gz: 7c4dbf4065b011aaf46803956e843295f675e6851c2f834417effaf0dd244a6b4cf3045cecb6d27d0bbbd2d632710d676f186c2fe3227ac359e581dfb8c8ba24
7
+ data.tar.gz: 953b81ec8a65ff9d03fab491b798975a1749a10fbc3b988ab13e893b1d4c7d8d0cfac1ce6bc4405762de19b767d49eea544764afb629367049ec2bddc390e13a
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-04-28
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at delta.null@vk.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mysql2"
6
+ gem "glimmer-dsl-libui",'~> 0.7.4'
7
+ gem 'win32api'
8
+ gem "minitest"
9
+ gem 'rubocop', group: 'development'
10
+ gem 'rubbish_code', '~> 0.1.3'
11
+ gem 'sinatra', '~> 3.0', '>= 3.0.6'
12
+ gem 'thin', '~> 1.8', '>= 1.8.2'
13
+ gem 'mc_delta'
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubbishCode
4
+ VERSION = "0.1.4"
5
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "rubbish_code/version"
4
+
5
+ module RubbishCode
6
+ Dir[File.dirname(__FILE__) + '/source/**/*.rb'].each { |file|
7
+ puts file
8
+ require file
9
+ }
10
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+ require './LabStudents/util/logger_holder'
3
+ require 'win32api'
4
+
5
+ class StudentInputFormControllerCreate
6
+ def initialize(parent_controller)
7
+ @parent_controller = parent_controller
8
+ LoggerHolder.instance.debug('StudentInputFormControllerCreate: initialized')
9
+ end
10
+
11
+ def set_view(view)
12
+ @view = view
13
+ LoggerHolder.instance.debug('StudentInputFormControllerCreate: view set')
14
+ end
15
+
16
+ def refresh
17
+ @parent_controller.refresh_data(1, 20)
18
+ end
19
+
20
+ def on_view_created
21
+ begin
22
+ @student_rep = StudentRepository.new(DBSourceAdapter.new)
23
+ rescue Mysql2::Error::ConnectionError => e
24
+ on_db_conn_error(e)
25
+ end
26
+ end
27
+
28
+ def process_fields(fields)
29
+ begin
30
+ last_name = fields.delete(:last_name)
31
+ first_name = fields.delete(:first_name)
32
+ father_name = fields.delete(:father_name)
33
+
34
+ return if last_name.nil? || first_name.nil? || father_name.nil?
35
+
36
+ student = Student.new(last_name, first_name, father_name, **fields)
37
+
38
+ @student_rep.add_student(student)
39
+
40
+ LoggerHolder.instance.debug('StudentInputFormControllerCreate: adding student to DB')
41
+
42
+ @view.close
43
+ rescue ArgumentError => e
44
+ LoggerHolder.instance.debug("StudentInputFormControllerCreate: wrong fields: #{e.message}")
45
+ api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
46
+ api.call(0, e.message, 'Error', 0)
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def on_db_conn_error(error)
53
+ LoggerHolder.instance.debug('StudentInputFormControllerCreate: DB connection error:')
54
+ LoggerHolder.instance.error(error.message)
55
+ api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
56
+ api.call(0, "No connection to DB говно", "Error", 0)
57
+ @view.close
58
+ end
59
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require './LabStudents/util/logger_holder'
4
+ require 'win32api'
5
+
6
+ class StudentInputFormControllerEdit
7
+ def initialize(parent_controller, existing_student_id)
8
+ @parent_controller = parent_controller
9
+ @existing_student_id = existing_student_id
10
+ LoggerHolder.instance.debug('StudentInputFormControllerEdit: initialized')
11
+ end
12
+
13
+ def set_view(view)
14
+ @view = view
15
+ LoggerHolder.instance.debug('StudentInputFormControllerEdit: view set')
16
+ end
17
+
18
+ def refresh
19
+ @parent_controller.refresh_data(1, 20)
20
+ end
21
+
22
+ def on_view_created
23
+ begin
24
+ @student_rep = StudentRepository.new(DBSourceAdapter.new)
25
+ rescue Mysql2::Error::ConnectionError => e
26
+ on_db_conn_error(e)
27
+ end
28
+ @existing_student = @student_rep.student_by_id(@existing_student_id)
29
+ @view.make_readonly(:git, :telegram, :email, :phone)
30
+ populate_fields(@existing_student)
31
+ end
32
+
33
+ def populate_fields(student)
34
+ @view.set_value(:last_name, student.last_name)
35
+ @view.set_value(:first_name, student.first_name)
36
+ @view.set_value(:father_name, student.father_name)
37
+ @view.set_value(:git, student.git)
38
+ @view.set_value(:telegram, student.telegram)
39
+ @view.set_value(:email, student.email)
40
+ @view.set_value(:phone, student.phone)
41
+ end
42
+
43
+ def process_fields(fields)
44
+ begin
45
+ new_student = Student.from_hash(fields)
46
+
47
+ LoggerHolder.instance.debug('StudentInputFormControllerEdit: replacing student in DB')
48
+
49
+ @student_rep.replace_student(@existing_student_id, new_student)
50
+
51
+ @view.close
52
+ rescue ArgumentError => e
53
+ LoggerHolder.instance.debug("StudentInputFormControllerEdit: wrong fields: #{e.message}")
54
+ api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
55
+ api.call(0, e.message, 'Error', 0)
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def on_db_conn_error(error)
62
+ LoggerHolder.instance.debug('StudentInputFormControllerEdit: DB connection error:')
63
+ LoggerHolder.instance.error(error.message)
64
+ api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
65
+ api.call(0, "No connection to DB", "Error", 0)
66
+ @view.close
67
+ end
68
+ end
@@ -0,0 +1,5 @@
1
+ insert into student(last_name, first_name, father_name, phone, telegram, email, git) values
2
+ ('Хахук', 'Рустам', 'Нальбиевич', '79186733293', 'deltanull', 'deltanull@vk.ru', 'deltanull'),
3
+ ('Гиренко', 'Даниил', 'Егеньвич', NULL, 'gir', 'ashot@mail.ru', 'ashotgit'),
4
+ ('Гиренко', 'Даниил', 'Егеньвич', NULL, 'gir', 'ashot@mail.ru', 'ashotgit'),
5
+ ('Нагалевский', 'Артем', 'Великий', '79999999999', 'jakekepps', 'jakekepps@gmail.com', 'jakekepps');
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require './LabStudents/repositories/data_sources/db_data_source'
4
+ require './LabStudents/models/student'
5
+ require './LabStudents/models/student_short'
6
+ require './LabStudents/repositories/containers/data_list_student_short'
7
+
8
+ class DBSourceAdapter
9
+ def initialize
10
+ @db = DBDataSource.instance
11
+ end
12
+
13
+ def student_by_id(student_id)
14
+ hash = @db.prepare_exec('SELECT * FROM student WHERE id = ?', student_id).first
15
+ return nil if hash.nil?
16
+
17
+ Student.from_hash(hash)
18
+ end
19
+
20
+ def paginated_short_students(page, count, existing_data_list = nil)
21
+ offset = (page - 1) * count
22
+ students = @db.prepare_exec('SELECT * FROM student LIMIT ?, ?', offset, count)
23
+ slice = students.map { |h| StudentShort.from_student(Student.from_hash(h)) }
24
+ return DataListStudentShort.new(slice) if existing_data_list.nil?
25
+
26
+ existing_data_list.replace_objects(slice)
27
+ existing_data_list
28
+ end
29
+
30
+ def add_student(student)
31
+ template = 'INSERT INTO student(last_name, first_name, father_name, phone, telegram, email, git) VALUES (?, ?, ?, ?, ?, ?, ?)'
32
+ @db.prepare_exec(template, *student_fields(student))
33
+ @db.query('SELECT LAST_INSERT_ID()').first.first[1]
34
+ end
35
+
36
+ def replace_student(student_id, student)
37
+ template = 'UPDATE student SET last_name=?, first_name=?, father_name=?, phone=?, telegram=?, email=?, git=? WHERE id=?'
38
+ @db.prepare_exec(template, *student_fields(student), student_id)
39
+ end
40
+
41
+ def remove_student(student_id)
42
+ @db.prepare_exec('DELETE FROM student WHERE id = ?', student_id)
43
+ end
44
+
45
+ def student_count
46
+ @db.query('SELECT COUNT(id) FROM student').first.first[1]
47
+ end
48
+
49
+ private
50
+
51
+ def student_fields(student)
52
+ [student.last_name, student.first_name, student.father_name, student.phone, student.telegram, student.email, student.git]
53
+ end
54
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FileSourceAdapter
4
+ def initialize(data_transformer, file_path)
5
+ @file_path = file_path
6
+ @file_source = FileDataSource.new(data_transformer)
7
+ @file_source.load_from_file(file_path)
8
+ end
9
+
10
+ def student_by_id(student_id)
11
+ @file_source.student_by_id(student_id)
12
+ end
13
+
14
+ def paginated_short_students(page, count, existing_data_list = nil)
15
+ @file_source.paginated_short_students(page, count, existing_data_list)
16
+ end
17
+
18
+ def add_student(student)
19
+ added_id = @file_source.add_student(student)
20
+ @file_source.save_to_file(@file_path)
21
+ added_id
22
+ end
23
+
24
+ def replace_student(student_id, student)
25
+ @file_source.replace_student(student_id, student)
26
+ @file_source.save_to_file(@file_path)
27
+ end
28
+
29
+ def remove_student(student_id)
30
+ @file_source.remove_student(student_id)
31
+ @file_source.save_to_file(@file_path)
32
+ end
33
+
34
+ def student_count
35
+ @file_source.student_count
36
+ end
37
+ end
@@ -0,0 +1,74 @@
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
@@ -0,0 +1,18 @@
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
@@ -0,0 +1,35 @@
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
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mysql2'
4
+
5
+ class DBDataSource
6
+ private_class_method :new
7
+ @instance_mutex = Mutex.new
8
+
9
+ def initialize
10
+ db_config = YAML.load_file('./LabStudents/db_config/config.yaml').transform_keys(&:to_sym)
11
+ @client = Mysql2::Client.new(db_config)
12
+ @client.query_options.merge!(symbolize_keys: true)
13
+ end
14
+
15
+ def self.instance
16
+ return @instance if @instance
17
+
18
+ @instance_mutex.synchronize do
19
+ @instance ||= new
20
+ end
21
+
22
+ @instance
23
+ end
24
+
25
+ def prepare_exec(statement, *params)
26
+ @client.prepare(statement).execute(*params)
27
+ end
28
+
29
+ def query(statement)
30
+ @client.query(statement)
31
+ end
32
+
33
+ def last_id
34
+ @client.last_id
35
+ end
36
+ end
@@ -0,0 +1,75 @@
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
+ class FileDataSource
8
+ attr_writer :data_transformer
9
+
10
+ def initialize(data_transformer)
11
+ self.students = []
12
+ self.seq_id = 1
13
+ self.data_transformer = data_transformer
14
+ end
15
+
16
+ def load_from_file(file_path)
17
+ hash_list = data_transformer.str_to_hash_list(File.read(file_path))
18
+ self.students = hash_list.map { |h| Student.from_hash(h) }
19
+ update_seq_id
20
+ end
21
+
22
+ def save_to_file(file_path)
23
+ hash_list = students.map(&:to_hash)
24
+ File.write(file_path, data_transformer.hash_list_to_str(hash_list))
25
+ end
26
+
27
+ def student_by_id(student_id)
28
+ students.detect { |s| s.id == student_id }
29
+ end
30
+
31
+ # Получить page по счету count элементов (страница начинается с 1)
32
+ def paginated_short_students(page, count, existing_data_list = nil)
33
+ offset = (page - 1) * count
34
+ slice = students[offset, count].map { |s| StudentShort.from_student(s) }
35
+
36
+ return DataListStudentShort.new(slice) if existing_data_list.nil?
37
+
38
+ existing_data_list.replace_objects(slice)
39
+ existing_data_list
40
+ end
41
+
42
+ def sorted
43
+ students.sort_by(&:last_name_and_initials)
44
+ end
45
+
46
+ def add_student(student)
47
+ student.id = seq_id
48
+ students << student
49
+ self.seq_id += 1
50
+ student.id
51
+ end
52
+
53
+ def replace_student(student_id, student)
54
+ idx = students.find_index { |s| s.id == student_id }
55
+ students[idx] = student
56
+ end
57
+
58
+ def remove_student(student_id)
59
+ students.reject! { |s| s.id == student_id }
60
+ end
61
+
62
+ def student_count
63
+ students.count
64
+ end
65
+
66
+ private
67
+
68
+ # Метод для актуализации seq_id
69
+ def update_seq_id
70
+ self.seq_id = students.max_by(&:id).id + 1
71
+ end
72
+
73
+ attr_reader :data_transformer
74
+ attr_accessor :students, :seq_id
75
+ end
@@ -0,0 +1,15 @@
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
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/rubbish_code/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rubbish_code"
7
+ spec.version = RubbishCode::VERSION
8
+ spec.authors = ["Jake Epps"]
9
+ spec.email = ["nullexp.team@gmail.com"]
10
+ spec.summary = "Student App"
11
+ spec.description = "А gem that allows you to get pass for patterns"
12
+ spec.homepage = "https://github.com/Jakepps/Ruby_Moment"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 3.2.0"
15
+ spec.add_dependency 'win32api'
16
+ spec.files = Dir.glob("**/*")
17
+ end
@@ -0,0 +1,4 @@
1
+ module RubbishCode
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubbish_code
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Epps
@@ -25,23 +25,44 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  description: А gem that allows you to get pass for patterns
28
- email: nullexp.team@gmail.com
28
+ email:
29
+ - nullexp.team@gmail.com
29
30
  executables: []
30
31
  extensions: []
31
32
  extra_rdoc_files: []
32
33
  files:
34
+ - CHANGELOG.md
35
+ - CODE_OF_CONDUCT.md
33
36
  - Documentation.md
37
+ - Gemfile
34
38
  - LICENSE.txt
35
39
  - README.md
36
- - controllers/tab_students_controller.rb
37
- - db_config/config.yaml
38
- - db_config/migrations/001_create_table_student.sql
39
- - models/student.rb
40
- - models/student_base.rb
41
- - models/student_short.rb
42
- - models/student_test.rb
43
- - repositories/student_repository.rb
44
- - util/logger_holder.rb
40
+ - lib/rubbish_code.rb
41
+ - lib/rubbish_code/version.rb
42
+ - lib/source/controllers/student_input_form/student_input_form_controller_create.rb
43
+ - lib/source/controllers/student_input_form/student_input_form_controller_edit.rb
44
+ - lib/source/controllers/tab_students_controller.rb
45
+ - lib/source/db_config/config.yaml
46
+ - lib/source/db_config/migrations/001_create_table_student.sql
47
+ - lib/source/db_config/mock_data/fill_student.sql
48
+ - lib/source/models/student.rb
49
+ - lib/source/models/student_base.rb
50
+ - lib/source/models/student_short.rb
51
+ - lib/source/models/student_test.rb
52
+ - lib/source/repositories/adapters/db_source_adapter.rb
53
+ - lib/source/repositories/adapters/file_source_adapter.rb
54
+ - lib/source/repositories/containers/data_list.rb
55
+ - lib/source/repositories/containers/data_list_student_short.rb
56
+ - lib/source/repositories/containers/data_table.rb
57
+ - lib/source/repositories/data_sources/db_data_source.rb
58
+ - lib/source/repositories/data_sources/file_data_source.rb
59
+ - lib/source/repositories/data_sources/transformers/data_transformer_base.rb
60
+ - lib/source/repositories/data_sources/transformers/data_transformer_json.rb
61
+ - lib/source/repositories/data_sources/transformers/data_transformer_yaml.rb
62
+ - lib/source/repositories/student_repository.rb
63
+ - lib/source/util/logger_holder.rb
64
+ - rubbish_code.gemspec
65
+ - sig/ribbish_code.rbs
45
66
  homepage: https://github.com/Jakepps/Ruby_Moment
46
67
  licenses:
47
68
  - MIT
@@ -54,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
75
  requirements:
55
76
  - - ">="
56
77
  - !ruby/object:Gem::Version
57
- version: '3.0'
78
+ version: 3.2.0
58
79
  required_rubygems_version: !ruby/object:Gem::Requirement
59
80
  requirements:
60
81
  - - ">="
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes