Web_rubbish_code 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +19 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Web_rubbish_code.gemspec +16 -0
- data/lib/Web_rubbish_code.rb +10 -0
- data/lib/rubbish_code/version.rb +5 -0
- data/lib/rubbish_code.rb +10 -0
- 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 +20 -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/sig/rubbish_code.rbs +4 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8415f9d866fd8b502a3ff42b039d303b38654bfb1765a815c87d0f4d886768e3
|
4
|
+
data.tar.gz: 78f60e0252199ed3c7523f47b402dea35a34cd72aefbd2b02876d0e6a8026294
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ea28af017e4cd0b259f3b3c59c774b1f67697628d0d1caf71b5c8e64cdea6aab44c902f7c6ad774e14ffa1f6fce7fb4f876d106502a9220298f0f4513130dd27
|
7
|
+
data.tar.gz: 75dd6d2a7fe91ae781fe64d3453d4933862746e1d3645308b95bb04dbcf8bd0dc6f1a9d20febc79a3259a65927b40ce2f11c007265fd32fb44344fbefc7b52e5
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -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
data/Gemfile.lock
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Null_Delta
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# McDelta
|
2
|
+
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
4
|
+
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mc_delta`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
14
|
+
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mc_delta. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/mc_delta/blob/main/CODE_OF_CONDUCT.md).
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
36
|
+
|
37
|
+
## Code of Conduct
|
38
|
+
|
39
|
+
Everyone interacting in the McDelta project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/mc_delta/blob/main/CODE_OF_CONDUCT.md).
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/rubbish_code/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "Web_rubbish_code"
|
7
|
+
spec.version = RubbishCode::VERSION
|
8
|
+
spec.authors = ["Jake Epps"]
|
9
|
+
spec.email = ["nullexp.team@gmail.com"]
|
10
|
+
spec.summary = "Gem with rubbish code"
|
11
|
+
spec.description = "Gem with rubbish code"
|
12
|
+
spec.homepage = "https://rubygems.org/gems/model_gem"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = ">= 3.2.0"
|
15
|
+
spec.files = Dir.glob("**/*")
|
16
|
+
end
|
data/lib/rubbish_code.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
def attr_limited_regex_accessor(symbol, regex)
|
2
|
+
class_eval %{
|
3
|
+
def #{symbol}
|
4
|
+
@#{symbol}
|
5
|
+
end
|
6
|
+
|
7
|
+
def #{symbol}=(new_value)
|
8
|
+
if new_value != nil && new_value !~ #{regex}
|
9
|
+
raise "invalid #{symbol} format"
|
10
|
+
end
|
11
|
+
|
12
|
+
@#{symbol} = new_value
|
13
|
+
end
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def attr_private_limited_regex_accessor(symbol, regex)
|
18
|
+
class_eval %{
|
19
|
+
def #{symbol}
|
20
|
+
@#{symbol}
|
21
|
+
end
|
22
|
+
|
23
|
+
private def #{symbol}=(new_value)
|
24
|
+
if new_value != nil && new_value !~ #{regex}
|
25
|
+
raise "invalid #{symbol} format"
|
26
|
+
end
|
27
|
+
|
28
|
+
@#{symbol} = new_value
|
29
|
+
end
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def attr_private_accessor(symbol)
|
34
|
+
class_eval %{
|
35
|
+
private def #{symbol}
|
36
|
+
@#{symbol}
|
37
|
+
end
|
38
|
+
|
39
|
+
private def #{symbol}=(new_value)
|
40
|
+
@#{symbol} = new_value
|
41
|
+
end
|
42
|
+
}
|
43
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'source/data_construct_pattern/data_construct_pattarn.rb'
|
2
|
+
require 'source/controllers/create_student_controller.rb'
|
3
|
+
require 'source/controllers/edit_student_controller.rb'
|
4
|
+
require 'source/attr_limited_regex_accessor.rb'
|
5
|
+
require 'logger'
|
6
|
+
|
7
|
+
module RubbishCode
|
8
|
+
class ViewController
|
9
|
+
attr_private_accessor :model
|
10
|
+
attr_accessor :data_list
|
11
|
+
|
12
|
+
attr_accessor :selected_page
|
13
|
+
|
14
|
+
attr_accessor :on_update_data
|
15
|
+
|
16
|
+
attr_accessor :on_add_student_clicked
|
17
|
+
attr_accessor :on_edit_student_clicked
|
18
|
+
|
19
|
+
attr_private_accessor :logger
|
20
|
+
|
21
|
+
def initialize(model, &on_update_data)
|
22
|
+
self.model = model
|
23
|
+
self.on_update_data = on_update_data
|
24
|
+
|
25
|
+
self.selected_page = 0
|
26
|
+
|
27
|
+
self.data_list = DataListStudentShort.new(list: [], data_constructor: DefaultDataConstructPattern.new())
|
28
|
+
self.model.get_students(0, 10, self.data_list)
|
29
|
+
|
30
|
+
self.logger = Logger.new('controller.log')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
# StudentsListViewDelegate
|
36
|
+
class ViewController
|
37
|
+
def pages_count
|
38
|
+
(model.count / 10.0).ceil
|
39
|
+
end
|
40
|
+
|
41
|
+
def table_columns
|
42
|
+
self.data_list.get_names
|
43
|
+
end
|
44
|
+
|
45
|
+
def next_page
|
46
|
+
if self.selected_page != self.pages_count - 1
|
47
|
+
self.selected_page += 1
|
48
|
+
end
|
49
|
+
|
50
|
+
puts self.selected_page
|
51
|
+
|
52
|
+
update_table()
|
53
|
+
end
|
54
|
+
|
55
|
+
def last_page
|
56
|
+
if self.selected_page != 0
|
57
|
+
self.selected_page -= 1
|
58
|
+
end
|
59
|
+
|
60
|
+
puts self.selected_page
|
61
|
+
|
62
|
+
|
63
|
+
update_table()
|
64
|
+
end
|
65
|
+
|
66
|
+
def update_table
|
67
|
+
begin
|
68
|
+
model.get_students(self.selected_page * 10, (self.selected_page + 1) * 10, self.data_list)
|
69
|
+
rescue
|
70
|
+
logger.error('error in db connection')
|
71
|
+
end
|
72
|
+
self.on_update_data.call()
|
73
|
+
end
|
74
|
+
|
75
|
+
def open_student_creation_window()
|
76
|
+
self.logger.info('creating student window open')
|
77
|
+
on_add_student_clicked.call()
|
78
|
+
end
|
79
|
+
|
80
|
+
def open_student_editing_window(id)
|
81
|
+
self.logger.info('editing student window open')
|
82
|
+
on_edit_student_clicked.call(id)
|
83
|
+
end
|
84
|
+
|
85
|
+
def remove_student(id)
|
86
|
+
self.logger.info("student with id #{id} deleted")
|
87
|
+
model.remove_student(id)
|
88
|
+
update_table()
|
89
|
+
end
|
90
|
+
|
91
|
+
def add_student(student)
|
92
|
+
self.logger.info("new student added")
|
93
|
+
model.add_student(student)
|
94
|
+
puts model.count
|
95
|
+
end
|
96
|
+
|
97
|
+
def get_student(id)
|
98
|
+
model.get_student(id)
|
99
|
+
end
|
100
|
+
|
101
|
+
def replace_student(id, student)
|
102
|
+
self.logger.info("student with id #{id} updated")
|
103
|
+
model.replace_student(id, student)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RubbishCode
|
2
|
+
class DataConstructPattern
|
3
|
+
def execute(values, attrs)
|
4
|
+
raise 'Метод не реализован'
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class DefaultDataConstructPattern
|
9
|
+
def execute(values, attrs)
|
10
|
+
(0...values.size).map { |item_index|
|
11
|
+
[
|
12
|
+
values[item_index].id,
|
13
|
+
values[item_index].lastname,
|
14
|
+
values[item_index].firstname,
|
15
|
+
values[item_index].patronymic,
|
16
|
+
values[item_index].git,
|
17
|
+
values[item_index].telegram,
|
18
|
+
values[item_index].phone,
|
19
|
+
values[item_index].email
|
20
|
+
]
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module RubbishCode
|
2
|
+
module DataListObserver
|
3
|
+
def notify(data)
|
4
|
+
raise 'not implemented'
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
module DataListNotifier
|
9
|
+
attr_accessor :data_list_observers
|
10
|
+
|
11
|
+
def notify
|
12
|
+
raise 'not implemented'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class DataList
|
17
|
+
attr_accessor :list
|
18
|
+
attr_private_accessor :selected_objects
|
19
|
+
def initialize(list:)
|
20
|
+
self.data_list_observers = []
|
21
|
+
self.list = list
|
22
|
+
end
|
23
|
+
|
24
|
+
def select(index)
|
25
|
+
selected_objects << index
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_selected_objects
|
29
|
+
(0...list.size)
|
30
|
+
.filter { |x| selected_objects.include? x }
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_names
|
34
|
+
raise "Метод не реализован"
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_data
|
38
|
+
raise "Метод не реализован"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class DataList
|
43
|
+
include DataListNotifier
|
44
|
+
|
45
|
+
def notify
|
46
|
+
data_list_observers.each { |observer|
|
47
|
+
observer.notify(self.get_data)
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def add_observer(observer)
|
52
|
+
self.data_list_observers << observer
|
53
|
+
end
|
54
|
+
|
55
|
+
def remove_observer(observer)
|
56
|
+
self.data_list_observers.delete(observer)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'source/data_list.rb'
|
2
|
+
require 'source/data_table.rb'
|
3
|
+
|
4
|
+
module RubbishCode
|
5
|
+
class DataListStudentShort < DataList
|
6
|
+
|
7
|
+
attr_private_accessor :data_constructor
|
8
|
+
|
9
|
+
def initialize(list:, data_constructor:)
|
10
|
+
self.data_constructor = data_constructor
|
11
|
+
|
12
|
+
super(list: list)
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_names
|
16
|
+
["ID", "Фамилия", "Имя", "Отчество", "Гит", "Телега", "Телефон", "Почта"]
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_data
|
20
|
+
self.data_constructor.execute(list, get_names)
|
21
|
+
end
|
22
|
+
|
23
|
+
def list=(new_list)
|
24
|
+
@list = new_list
|
25
|
+
notify()
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module RubbishCode
|
2
|
+
class DataTable
|
3
|
+
attr_private_accessor :data
|
4
|
+
|
5
|
+
def initialize(data:)
|
6
|
+
self.data = data
|
7
|
+
end
|
8
|
+
|
9
|
+
def element(row:, column:)
|
10
|
+
data[row][column]
|
11
|
+
end
|
12
|
+
|
13
|
+
def columnsCount
|
14
|
+
data[0].size
|
15
|
+
end
|
16
|
+
|
17
|
+
def rowsCount
|
18
|
+
data.size
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
INSERT INTO student (lastname, firstname, patronymic, git, phone, email, telegram) VALUES
|
2
|
+
ROW("Хахук", "Рустам", "Нальбиевич", "@zed_null", NULL,"jakepps@gmail.com", NULL),
|
3
|
+
ROW("Нагалевский", "Артем", "Михайлович", "@jakepps", "+7-800-555-35-35", "jakepps@gmail.com", NULL),
|
4
|
+
ROW("Гиренко", "Даниил", "Евгениевич", "@iamgirya", NULL, "iamgirya@yandex.ru", NULL),
|
5
|
+
ROW("Прозоров", "Максим", "Сергеевич", "@starproxima", NULL, "star@yandex.ru", NULL),
|
6
|
+
ROW("Иванов", "Александр", "Петрович", "@ivanov_alex", NULL, "ivanov_alex@gmail.com", NULL),
|
7
|
+
ROW("Петров", "Дмитрий", "Андреевич", "@petrov_dmitry", "+7-800-555-35-35", "petrov_dmitry@mail.ru", NULL),
|
8
|
+
ROW("Сидоров", "Игорь", "Владимирович", "@sidorov_igor", NULL, "sidorov_igor@yandex.ru", NULL),
|
9
|
+
ROW("Кузнецова", "Елена", "Александровна", "@kuznetsova_elena", NULL, "kuznetsova_elena@mail.ru", NULL),
|
10
|
+
ROW("Смирнов", "Андрей", "Викторович", "@smirnov_andrey", "+7-800-555-35-35", "smirnov_andrey@yandex.ru", NULL),
|
11
|
+
ROW("Новикова", "Ольга", "Анатольевна", "@novikova_olga", NULL, "novikova_olga@gmail.com", NULL),
|
12
|
+
ROW("Козлов", "Владимир", "Дмитриевич", "@kozlov_vladimir","+7-800-555-35-35", "kozlov_vladimir@yandex.ru", NULL),
|
13
|
+
ROW("Морозова", "Татьяна", "Сергеевна", "@morozova_tatiana", NULL, "morozova_tatiana@mail.ru", NULL),
|
14
|
+
ROW("Попов", "Антон", "Николаевич", "@popov_anton", NULL, "popov_anton@gmail.com", NULL),
|
15
|
+
ROW("Федоров", "Сергей", "Александрович", "@fedorov_sergey", "+7-800-555-35-35", "fedorov_sergey@yandex.ru", NULL),
|
16
|
+
ROW("Васильева", "Анастасия", "Дмитриевна", "@vasilieva_anastasia", NULL, "vasilieva_anastasia@mail.ru", NULL),
|
17
|
+
ROW("Ковалев", "Алексей", "Петрович", "@kovalev_aleksey", NULL, "kovalev_aleksey@gmail.com", NULL),
|
18
|
+
ROW("Богданов", "Максим", "Игоревич", "@bogdanov_maxim", NULL, "bogdanov_maxim@yandex.ru", NULL),
|
19
|
+
ROW("Попов", "Антон", "Николаевич", "@popov_anton", NULL, "popov_anton@gmail.com", NULL),
|
20
|
+
ROW("Федоров", "Сергей", "Александрович", "@fedorov_sergey", "+7-800-555-35-35", "fedorov_sergey@yandex.ru", NULL)
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'mysql2'
|
2
|
+
|
3
|
+
module RubbishCode
|
4
|
+
|
5
|
+
class StudentsDB
|
6
|
+
attr_private_accessor :db_connection
|
7
|
+
|
8
|
+
def initialize()
|
9
|
+
self.db_connection = Mysql2::Client.new(:host => "localhost", :username => "root", :password => "1234")
|
10
|
+
self.db_connection.query('CREATE DATABASE IF NOT EXISTS my_db')
|
11
|
+
self.db_connection.query('USE my_db')
|
12
|
+
self.db_connection.query('DROP TABLE IF EXISTS student')
|
13
|
+
self.db_connection.query(File.read(File.dirname(__FILE__) + '/scripts/create_table.sql'))
|
14
|
+
self.fill_data()
|
15
|
+
end
|
16
|
+
|
17
|
+
private def fill_data()
|
18
|
+
db_connection.query(File.read(File.dirname(__FILE__) + '/scripts/fill_data.sql'))
|
19
|
+
end
|
20
|
+
|
21
|
+
def select_by_id(id)
|
22
|
+
db_connection.query("SELECT * FROM student WHERE id = #{id}").map { |x| x }[0]
|
23
|
+
end
|
24
|
+
|
25
|
+
def remove_by_id(id)
|
26
|
+
db_connection.query("DELETE FROM student WHERE id = #{id}")
|
27
|
+
end
|
28
|
+
|
29
|
+
def replace_by_id(id, student_json)
|
30
|
+
db_connection.query("DELETE FROM student WHERE id = #{id}")
|
31
|
+
db_connection.query("""
|
32
|
+
INSERT INTO student (id, lastname, firstname, patronymic, git, phone, email, telegram) VALUES
|
33
|
+
ROW(
|
34
|
+
\"#{id}\",
|
35
|
+
\"#{attr_or_null(student_json[:lastname])}\",
|
36
|
+
\"#{attr_or_null(student_json[:firstname])}\",
|
37
|
+
\"#{attr_or_null(student_json[:patronymic])}\",
|
38
|
+
\"#{attr_or_null(student_json[:git])}\",
|
39
|
+
\"#{attr_or_null(student_json[:phone])}\",
|
40
|
+
\"#{attr_or_null(student_json[:email])}\",
|
41
|
+
\"#{attr_or_null(student_json[:telegram])}\"
|
42
|
+
)
|
43
|
+
""")
|
44
|
+
end
|
45
|
+
|
46
|
+
def add_student(student_json)
|
47
|
+
puts student_json[:lastname]
|
48
|
+
db_connection.query("""
|
49
|
+
INSERT INTO student (lastname, firstname, patronymic, git, phone, email, telegram) VALUES
|
50
|
+
ROW(
|
51
|
+
\"#{attr_or_null(student_json[:lastname])}\",
|
52
|
+
\"#{attr_or_null(student_json[:firstname])}\",
|
53
|
+
\"#{attr_or_null(student_json[:patronymic])}\",
|
54
|
+
\"#{attr_or_null(student_json[:git])}\",
|
55
|
+
\"#{attr_or_null(student_json[:phone])}\",
|
56
|
+
\"#{attr_or_null(student_json[:email])}\",
|
57
|
+
\"#{attr_or_null(student_json[:telegram])}\"
|
58
|
+
)
|
59
|
+
""")
|
60
|
+
end
|
61
|
+
|
62
|
+
def select_students(from, to)
|
63
|
+
db_connection.query("SELECT * FROM student LIMIT #{from}, #{to}")
|
64
|
+
end
|
65
|
+
|
66
|
+
def count()
|
67
|
+
db_connection.query("SELECT * FROM student").count
|
68
|
+
end
|
69
|
+
|
70
|
+
private def attr_or_null(attr)
|
71
|
+
if attr == nil
|
72
|
+
"NULL"
|
73
|
+
else
|
74
|
+
attr
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'source/database/students_db.rb'
|
2
|
+
|
3
|
+
module RubbishCode
|
4
|
+
class StudentsListDB
|
5
|
+
private_class_method :new
|
6
|
+
|
7
|
+
def self.get_student(id)
|
8
|
+
Student.from_json(StudentsListDB.database.select_by_id(id))
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.remove_student(id)
|
12
|
+
StudentsListDB.database.remove_by_id(id)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.replace_student(id, student)
|
16
|
+
StudentsListDB.database.replace_by_id(id, student.as_json)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.add_student(student)
|
20
|
+
StudentsListDB.database.add_student(student.as_json)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.get_students_slice(from, to)
|
24
|
+
StudentsListDB.database.select_students(from, to).map { |x| Student.from_json(x) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.count()
|
28
|
+
StudentsListDB.database.count()
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.database
|
32
|
+
@database ||= StudentsDB.new()
|
33
|
+
@database
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module RubbishCode
|
2
|
+
class AbstractStudent
|
3
|
+
private_class_method :new
|
4
|
+
attr_accessor :lastname, :firstname, :patronymic, :id
|
5
|
+
|
6
|
+
def get_info
|
7
|
+
raise "method not implemented"
|
8
|
+
end
|
9
|
+
|
10
|
+
def fio_info
|
11
|
+
raise "method not implemented"
|
12
|
+
end
|
13
|
+
|
14
|
+
def contacts_info
|
15
|
+
raise "method not implemented"
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
get_info
|
20
|
+
end
|
21
|
+
|
22
|
+
def as_json
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require "source/attr_limited_regex_accessor.rb"
|
2
|
+
require "source/student/abstract_student.rb"
|
3
|
+
|
4
|
+
module RubbishCode
|
5
|
+
class Student < AbstractStudent
|
6
|
+
attr_limited_regex_accessor :phone, '/\d-\d{3}-\d{3}-\d{2}-\d{2}/'
|
7
|
+
attr_limited_regex_accessor :email, '/\w*@\w*.\w{2,3}/'
|
8
|
+
attr_limited_regex_accessor :telegram, '/@\w*/'
|
9
|
+
attr_limited_regex_accessor :git, '/@\w*/'
|
10
|
+
|
11
|
+
public_class_method :new
|
12
|
+
|
13
|
+
def initialize(
|
14
|
+
lastname:,
|
15
|
+
firstname:,
|
16
|
+
patronymic:,
|
17
|
+
params: {}
|
18
|
+
)
|
19
|
+
self.lastname = lastname
|
20
|
+
self.firstname = firstname
|
21
|
+
self.patronymic = patronymic
|
22
|
+
self.id = params[:id]
|
23
|
+
|
24
|
+
self.phone = params[:phone]
|
25
|
+
self.telegram = params[:telegram]
|
26
|
+
self.email = params[:email]
|
27
|
+
self.git = params[:git]
|
28
|
+
|
29
|
+
validate()
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.from_json(json)
|
33
|
+
params = json.map { |v|
|
34
|
+
[v[0].to_sym, v[1]]
|
35
|
+
}.filter { |v|
|
36
|
+
v[1] != "NULL"
|
37
|
+
}.to_h
|
38
|
+
|
39
|
+
Student.new(
|
40
|
+
lastname: json["lastname"],
|
41
|
+
firstname: json["firstname"],
|
42
|
+
patronymic: json["patronymic"],
|
43
|
+
params: params
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.from_string(str)
|
48
|
+
params = str
|
49
|
+
.split(";")
|
50
|
+
.map { |x| x.split(":") }
|
51
|
+
.map { |x| [x[0].to_sym, x[1]] }
|
52
|
+
.to_h
|
53
|
+
|
54
|
+
if params[:fio] == nil
|
55
|
+
raise "invalid string representation"
|
56
|
+
end
|
57
|
+
|
58
|
+
fio_components = params[:fio].split(" ")
|
59
|
+
|
60
|
+
Student.new(
|
61
|
+
lastname: fio_components[0],
|
62
|
+
firstname: fio_components[1],
|
63
|
+
patronymic: fio_components[2],
|
64
|
+
params: params
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
def have_any_contact
|
69
|
+
phone != nil || telegram != nil || email != nil || git != nil
|
70
|
+
end
|
71
|
+
|
72
|
+
def validate
|
73
|
+
if !have_any_contact
|
74
|
+
raise "Not finded git or any contact"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def set_contacts(phone: nil, email: nil, git: nil, telegram: nil)
|
79
|
+
if phone != nil then self.phone = phone end
|
80
|
+
if email != nil then self.email = email end
|
81
|
+
if git != nil then self.git = git end
|
82
|
+
if telegram != nil then self.telegram = telegram end
|
83
|
+
end
|
84
|
+
|
85
|
+
def contacts_info
|
86
|
+
contacts = ""
|
87
|
+
if git != nil then contacts << "git:#{git};" end
|
88
|
+
if phone != nil then contacts << "phone:#{phone};" end
|
89
|
+
if email != nil then contacts << "email:#{email};" end
|
90
|
+
if telegram != nil then contacts << "telegram:#{telegram};" end
|
91
|
+
|
92
|
+
contacts
|
93
|
+
end
|
94
|
+
|
95
|
+
def get_info
|
96
|
+
if id != nil
|
97
|
+
"id:#{id};#{fio_info};#{contacts_info}"
|
98
|
+
else
|
99
|
+
"#{fio_info};#{contacts_info}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def fio_info
|
104
|
+
"fio:#{lastname} #{firstname} #{patronymic}"
|
105
|
+
end
|
106
|
+
|
107
|
+
def as_json
|
108
|
+
{
|
109
|
+
lastname: lastname,
|
110
|
+
firstname: firstname,
|
111
|
+
patronymic: patronymic,
|
112
|
+
id: id,
|
113
|
+
phone: phone,
|
114
|
+
email: email,
|
115
|
+
git: git,
|
116
|
+
telegram: telegram
|
117
|
+
}
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "source/attr_limited_regex_accessor.rb"
|
2
|
+
require "source/student/abstract_student.rb"
|
3
|
+
|
4
|
+
module RubbishCode
|
5
|
+
class StudentShort < AbstractStudent
|
6
|
+
attr_private_limited_regex_accessor :git, '/@\w*/'
|
7
|
+
attr_private_limited_regex_accessor :email, '/\w*@\w*.\w{2,3}/'
|
8
|
+
|
9
|
+
public_class_method :new
|
10
|
+
|
11
|
+
def initialize(id:, fio:, git:, email:)
|
12
|
+
fio_components = fio.split(" ")
|
13
|
+
|
14
|
+
self.id = id
|
15
|
+
self.firstname = fio_components[0]
|
16
|
+
self.lastname = fio_components[1]
|
17
|
+
self.patronymic = fio_components[2]
|
18
|
+
|
19
|
+
self.git = git
|
20
|
+
self.email = email
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.from_student(student)
|
24
|
+
StudentShort.new(
|
25
|
+
id: student.id,
|
26
|
+
fio: "#{student.firstname} #{student.lastname} #{student.patronymic}",
|
27
|
+
git: student.git,
|
28
|
+
email: student.email
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.from_string(id, info)
|
33
|
+
params = info
|
34
|
+
.split(";")
|
35
|
+
.map { |x| x.split(":") }
|
36
|
+
.map { |x| [x[0].to_sym, x[1]] }
|
37
|
+
.to_h
|
38
|
+
|
39
|
+
StudentShort.new(
|
40
|
+
id: id,
|
41
|
+
fio: params[:fio],
|
42
|
+
git: params[:git],
|
43
|
+
email: params[:email]
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def fio_info
|
48
|
+
"fio:#{firstname} #{lastname.upcase[0]} #{patronymic.upcase[0]}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def contacts_info
|
52
|
+
"git:#{git};email:#{email}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_info
|
56
|
+
[fio_info, contacts_info].join(";")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module RubbishCode
|
2
|
+
class StudentListFormat
|
3
|
+
attr_private_accessor :students
|
4
|
+
attr_accessor :formater
|
5
|
+
|
6
|
+
def initialize(formater)
|
7
|
+
self.formater = formater
|
8
|
+
end
|
9
|
+
|
10
|
+
def read_from(filename)
|
11
|
+
self.students = formater.read_from(filename)
|
12
|
+
end
|
13
|
+
|
14
|
+
def write_to(filename)
|
15
|
+
formater.write_to(filename, self.students)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_student(id)
|
19
|
+
self.students.detect { |x|
|
20
|
+
x.id == id .to_s
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_student(student)
|
25
|
+
self.students << student
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete_student(id)
|
29
|
+
index = students.index(students.detect { |x| x.id == id.to_s })
|
30
|
+
self.students.delete_at(index)
|
31
|
+
end
|
32
|
+
|
33
|
+
def replace_student(id, student)
|
34
|
+
self.students.map! { |x| x.id == id.to_s ? student : x }
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_students_slice(k, count)
|
38
|
+
from = [k * count, self.students.count].min
|
39
|
+
to = [self.students.count, from + count].min
|
40
|
+
end
|
41
|
+
|
42
|
+
def count()
|
43
|
+
self.students.count
|
44
|
+
end
|
45
|
+
|
46
|
+
def sort()
|
47
|
+
self.students.sort_by(&:fio_info)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "source/attr_limited_regex_accessor.rb"
|
2
|
+
|
3
|
+
module RubbishCode
|
4
|
+
class StudentsList
|
5
|
+
attr_private_accessor :students_list_adapter
|
6
|
+
|
7
|
+
def initialize(adapter)
|
8
|
+
self.students_list_adapter = adapter
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_student(id)
|
12
|
+
students_list_adapter.get_student(id)
|
13
|
+
end
|
14
|
+
|
15
|
+
def remove_student(id)
|
16
|
+
students_list_adapter.remove_student(id)
|
17
|
+
end
|
18
|
+
|
19
|
+
def replace_student(id, student)
|
20
|
+
students_list_adapter.replace_student(id, student)
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_students(from, to, data)
|
24
|
+
values = students_list_adapter.get_students(from, to)
|
25
|
+
|
26
|
+
if data == nil
|
27
|
+
data = DataList.new(list: values)
|
28
|
+
else
|
29
|
+
data.list = values
|
30
|
+
end
|
31
|
+
|
32
|
+
data.list
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_student(student)
|
36
|
+
students_list_adapter.add_student(student)
|
37
|
+
end
|
38
|
+
|
39
|
+
def count
|
40
|
+
students_list_adapter.count()
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module RubbishCode
|
2
|
+
class StudentsListAdapter
|
3
|
+
def get_student(id)
|
4
|
+
end
|
5
|
+
|
6
|
+
def remove_student(id)
|
7
|
+
end
|
8
|
+
|
9
|
+
def replace_student(id, student, data)
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_students(from, to, data)
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_student(student)
|
16
|
+
end
|
17
|
+
|
18
|
+
def count
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class StudentsListDBAdapter < StudentsListAdapter
|
23
|
+
attr_private_accessor :database_list
|
24
|
+
|
25
|
+
def initialize(database_list)
|
26
|
+
self.database_list = database_list
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_student(id)
|
30
|
+
database_list.get_student(id)
|
31
|
+
end
|
32
|
+
|
33
|
+
def remove_student(id)
|
34
|
+
database_list.remove_student(id)
|
35
|
+
end
|
36
|
+
|
37
|
+
def replace_student(id, student)
|
38
|
+
database_list.replace_student(id, student)
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_students(from, to)
|
42
|
+
database_list.get_students_slice(from, to)
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_student(student)
|
46
|
+
database_list.add_student(student)
|
47
|
+
end
|
48
|
+
|
49
|
+
def count
|
50
|
+
database_list.count()
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class StudentsListFormatterAdapter < StudentsListAdapter
|
55
|
+
attr_private_accessor :formatter
|
56
|
+
|
57
|
+
def initialize(formatter, filename)
|
58
|
+
self.formatter = formatter
|
59
|
+
formatter.read_from(filename)
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_student(id)
|
63
|
+
formatter.get_student(id)
|
64
|
+
end
|
65
|
+
|
66
|
+
def remove_student(id)
|
67
|
+
formatter.delete_student(id)
|
68
|
+
end
|
69
|
+
|
70
|
+
def replace_student(id, student)
|
71
|
+
formatter.replace_student(id, student)
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_students(from, to)
|
75
|
+
count = to - from
|
76
|
+
k = from / count
|
77
|
+
|
78
|
+
formatter.get_students_slice(k, count)
|
79
|
+
end
|
80
|
+
|
81
|
+
def add_student(student)
|
82
|
+
formatter.add_student(student)
|
83
|
+
end
|
84
|
+
|
85
|
+
def count
|
86
|
+
formatter.count()
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module RubbishCode
|
5
|
+
class StudentsListFormatStrategy
|
6
|
+
def read_from(filename)
|
7
|
+
require 'method not implemented'
|
8
|
+
end
|
9
|
+
|
10
|
+
def write_to(filename, students)
|
11
|
+
require 'method not implemented'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class TxtStudentsListFormatStrategy < StudentsListFormatStrategy
|
16
|
+
def read_from(filename)
|
17
|
+
File.read(filename)
|
18
|
+
.split("\n")
|
19
|
+
.map { |v| Student.from_string(v) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def write_to(filename, students)
|
23
|
+
File.open(filename, 'w') { |file|
|
24
|
+
file.write(
|
25
|
+
students.map { |student|
|
26
|
+
student.get_info
|
27
|
+
}
|
28
|
+
.join("\n")
|
29
|
+
)
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class JsonStudentsListFormatStrategy < StudentsListFormatStrategy
|
35
|
+
def read_from(filename)
|
36
|
+
file = File.read(filename)
|
37
|
+
json = JSON.parse(file)
|
38
|
+
json.map { |x| Student.from_json(x) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def write_to(filename, students)
|
42
|
+
File.open(filename, 'w') do |f|
|
43
|
+
f.write(JSON.generate(students.map { |x| x.as_json }))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class YamlStudentsListFormatStrategy < StudentsListFormatStrategy
|
49
|
+
def read_from(filename)
|
50
|
+
YAML.load_file(filename)
|
51
|
+
end
|
52
|
+
|
53
|
+
def write_to(filename, students)
|
54
|
+
File.open(filename, 'w') do |file|
|
55
|
+
file.write(students.to_yaml)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "source/students_list.rb"
|
3
|
+
require "source/attr_limited_regex_accessor.rb"
|
4
|
+
require "source/students_list_adapter.rb"
|
5
|
+
require "source/database/students_list_db.rb"
|
6
|
+
require "source/student/student.rb"
|
7
|
+
require "source/data_list.rb"
|
8
|
+
|
9
|
+
module RubbishCode
|
10
|
+
class StudentsTests < Test::Unit::TestCase
|
11
|
+
def test_add
|
12
|
+
@students = StudentsList.new(
|
13
|
+
StudentsListDBAdapter.new(
|
14
|
+
StudentsListDB
|
15
|
+
)
|
16
|
+
)
|
17
|
+
|
18
|
+
@start_count = @students.count
|
19
|
+
|
20
|
+
@students.add_student(
|
21
|
+
Student.new(
|
22
|
+
lastname: "AAA",
|
23
|
+
firstname: "BBB",
|
24
|
+
patronymic: "CCC",
|
25
|
+
params: {
|
26
|
+
email: "test@email.com"
|
27
|
+
}
|
28
|
+
)
|
29
|
+
)
|
30
|
+
|
31
|
+
assert_equal(1, @students.count - @start_count)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_delete
|
35
|
+
@students = StudentsList.new(
|
36
|
+
StudentsListDBAdapter.new(
|
37
|
+
StudentsListDB
|
38
|
+
)
|
39
|
+
)
|
40
|
+
|
41
|
+
@students.add_student(
|
42
|
+
Student.new(
|
43
|
+
lastname: "AAA",
|
44
|
+
firstname: "BBB",
|
45
|
+
patronymic: "CCC",
|
46
|
+
params: {
|
47
|
+
email: "test@email.com"
|
48
|
+
}
|
49
|
+
)
|
50
|
+
)
|
51
|
+
|
52
|
+
@students.add_student(
|
53
|
+
Student.new(
|
54
|
+
lastname: "AAA",
|
55
|
+
firstname: "BBB",
|
56
|
+
patronymic: "CCC",
|
57
|
+
params: {
|
58
|
+
email: "test@email.com"
|
59
|
+
}
|
60
|
+
)
|
61
|
+
)
|
62
|
+
|
63
|
+
@current_count = @students.count
|
64
|
+
|
65
|
+
@students_list = @students.get_students(0, 10, nil)
|
66
|
+
|
67
|
+
@students.remove_student(@students_list[0].id)
|
68
|
+
|
69
|
+
assert_equal(1, @current_count - @students.count)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Web_rubbish_code
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jake Epps
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-05-09 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Gem with rubbish code
|
14
|
+
email:
|
15
|
+
- nullexp.team@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- CODE_OF_CONDUCT.md
|
21
|
+
- Gemfile
|
22
|
+
- Gemfile.lock
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Web_rubbish_code.gemspec
|
26
|
+
- lib/Web_rubbish_code.rb
|
27
|
+
- lib/rubbish_code.rb
|
28
|
+
- lib/rubbish_code/version.rb
|
29
|
+
- lib/source/attr_limited_regex_accessor.rb
|
30
|
+
- lib/source/controllers/create_student_controller.rb
|
31
|
+
- lib/source/controllers/edit_student_controller.rb
|
32
|
+
- lib/source/controllers/view_controller.rb
|
33
|
+
- lib/source/data_construct_pattern/data_construct_pattarn.rb
|
34
|
+
- lib/source/data_list.rb
|
35
|
+
- lib/source/data_list_student_short.rb
|
36
|
+
- lib/source/data_table.rb
|
37
|
+
- lib/source/database/scripts/create_table.sql
|
38
|
+
- lib/source/database/scripts/fill_data.sql
|
39
|
+
- lib/source/database/students_db.rb
|
40
|
+
- lib/source/database/students_list_db.rb
|
41
|
+
- lib/source/student/abstract_student.rb
|
42
|
+
- lib/source/student/student.rb
|
43
|
+
- lib/source/student/student_short.rb
|
44
|
+
- lib/source/student_list_format.rb
|
45
|
+
- lib/source/students_list.rb
|
46
|
+
- lib/source/students_list_adapter.rb
|
47
|
+
- lib/source/students_list_format_strategy.rb
|
48
|
+
- lib/source/students_tests.rb
|
49
|
+
- sig/rubbish_code.rbs
|
50
|
+
homepage: https://rubygems.org/gems/model_gem
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata: {}
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 3.2.0
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubygems_version: 3.4.10
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Gem with rubbish code
|
73
|
+
test_files: []
|