day_offs 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5ad83ba16e97952c923bf7ace9c5f8d4e32d7778305fd1e4232c1a3f02a52bb0
4
+ data.tar.gz: 8cc866eade67a07e6b4948cdd7bda73dbc004c4cda7e030cdf03d84439330417
5
+ SHA512:
6
+ metadata.gz: ca75a686f2e85833565ddd15edc3e0285b518be498d8d91f30a2ec8dac0c01a44a9730dbd500ed5173442eba36708a2f42df35f94e636010b700531795c46223
7
+ data.tar.gz: 9f541d4cd5034e014606dbe81edf82f324a2507417209e7c2c933c2c675a99fefaa959e97ccce0e141493395c12f1a003142c02d5da6b68eb99b68fa83f4f9b7
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
@@ -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 Nekitonich4@yandex.ru. 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/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Kroched
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,70 @@
1
+ <div align="center">
2
+ <h1>DayOffs</h1>
3
+ <div><a href='https://coveralls.io/github/Kroch4ka/day_offs?branch=main'><img src='https://coveralls.io/repos/github/Kroch4ka/day_offs/badge.svg?branch=main' alt='Coverage Status' /></a>
4
+ <a href="https://codeclimate.com/github/Kroch4ka/day_offs/maintainability"><img src="https://api.codeclimate.com/v1/badges/119af1d7fc0a499d9388/maintainability" /></a></div>
5
+ Add day offs sources for different countries in a standardized manner
6
+ <br /><br />
7
+ </div>
8
+
9
+ DayOffs is a plugin system that allows you to easy create and register various sources about days off and use them in a standardized manner
10
+
11
+ ---
12
+
13
+ ## Add own sources
14
+
15
+ When you subclass ```DayOffs::Sources::Base```, you get helpful methods defined and all you need to do is to override the call method
16
+
17
+ ```ruby
18
+ module DayOffs::Sources
19
+ class MySource < Base
20
+ with_countries :RU, :BY # define supported countries
21
+ with_years 2023, 2024 # define supported years
22
+ with_name :super_source # define source name
23
+
24
+ def call
25
+ [
26
+ DayOffs::DayOff.new(country, Date.civil(year))
27
+ ] # you can access to target instance variables
28
+ end
29
+ end
30
+
31
+ class MyAnotherSource < Base
32
+ with_countries :BY
33
+ with_years 2023, 2024
34
+ with_name :another_source
35
+
36
+ def call
37
+ [
38
+ DayOffs::DayOff.new(country, Date.civil(year))
39
+ ]
40
+ end
41
+ end
42
+ end
43
+ ```
44
+
45
+ Sources should return an array of objects ``DayOffs::DayOff`` it`s simple struct ``Struct.new(:country, :date)``
46
+
47
+ ## Configuration
48
+
49
+ Add this line to your application's Gemfile:
50
+
51
+ ```ruby
52
+ gem 'day_offs'
53
+ ```
54
+
55
+ Add source:
56
+
57
+ ```ruby
58
+ DayOffs.configure do |c|
59
+ c.use_sources :super_source
60
+ end
61
+ ```
62
+
63
+ ## Usage
64
+
65
+ Adding a class and inheriting from `DayOffs::Sources::Base` will allow you to interact with the chosen sources:
66
+
67
+ ```ruby
68
+ DayOffs::RU.fetch(2023)
69
+ DayOffs::BY.fetch(2023, :another_source)
70
+ ```
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/day_offs.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/day_offs/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "day_offs"
7
+ spec.version = DayOffs::VERSION
8
+ spec.authors = ["Kroched"]
9
+ spec.email = ["Nekitonich4@yandex.ru"]
10
+
11
+ spec.summary = "Plugin system for support day offs sources"
12
+ spec.description = "Add day offs sources for different countries in a standardized manner"
13
+ spec.homepage = "https://github.com/Kroch4ka/day_offs"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/Kroch4ka/day_offs"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(__dir__) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (File.expand_path(f) == __FILE__) ||
25
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ # spec.add_dependency "example-gem", "~> 1.0"
34
+ spec.add_dependency "zeitwerk", "~> 2.6"
35
+
36
+ # For more information and examples about making a new gem, check out our
37
+ # guide at: https://bundler.io/guides/creating_gem.html
38
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DayOffs::Configuration
4
+ class UndefinedSourceError < StandardError; end
5
+
6
+ def use_sources(*sources)
7
+ sources.each { |source| use_source(source) }
8
+ end
9
+
10
+ private
11
+
12
+ def use_source(source)
13
+ source_klass = DayOffs.registered_sources.find { |src| src.source_name == source } if source.is_a?(Symbol)
14
+ source_klass ||= source if source.respond_to?(:ancestors) && source.ancestors.include?(DayOffs::Sources::Base)
15
+
16
+ raise UndefinedSourceError unless source_klass
17
+
18
+ add_source_klass(source_klass)
19
+ end
20
+
21
+ def add_source_klass(source_klass)
22
+ source_klass.countries.each do |country|
23
+ source_klass.years.each do |year|
24
+ DayOffs.used_sources[country] ||= {}
25
+ DayOffs.used_sources[country][year] ||= []
26
+ DayOffs.used_sources[country][year] << source_klass
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DayOffs::Core
4
+ class << self
5
+ def objectize_sources
6
+ DayOffs.used_sources.each do |country, year_sources_hash|
7
+ DayOffs.const_set(country, Class.new).instance_eval do
8
+ @sources = year_sources_hash
9
+ @country = country
10
+
11
+ def fetch(year, source = nil)
12
+ raise DayOffs::Errors::UnsupportedYearError unless @sources[year]
13
+
14
+ source = @sources[year].find { |s| s.source_name == source } || @sources[year].first
15
+ source.call(year, @country)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DayOffs::Errors
4
+ class UnsupportedYearError < StandardError; end
5
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DayOffs::Sources::Base
4
+ attr_reader :country, :year
5
+
6
+ def initialize(year, country)
7
+ @year = year
8
+ @country = country
9
+ end
10
+
11
+ def call
12
+ raise DayOffs::Sources::Errors::UnimplementedMethodError
13
+ end
14
+
15
+ class << self
16
+ def call(year, country)
17
+ new(year, country).call
18
+ end
19
+
20
+ private
21
+
22
+ def inherited(subclass)
23
+ super
24
+ DayOffs.registered_sources << subclass
25
+ subclass.instance_exec do
26
+ extend DayOffs::Sources::DSL
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DayOffs::Sources::DSL
4
+
5
+ def self.extended(klass)
6
+ super
7
+ klass.instance_exec do
8
+ @countries = []
9
+ @years = []
10
+ end
11
+ klass.singleton_class.instance_exec do
12
+ attr_accessor :countries, :years, :source_name
13
+ end
14
+ end
15
+
16
+ def with_countries(*countries_alpha2)
17
+ verified_countries = countries_alpha2.map do |country|
18
+ DayOffs::Sources::Validator.validate_country(country.upcase)
19
+ country.upcase
20
+ end
21
+
22
+ self.countries = countries + verified_countries
23
+ end
24
+
25
+ def with_name(source_name)
26
+ self.source_name = source_name
27
+ end
28
+
29
+ def with_years(*years)
30
+ years.each { |year| DayOffs::Sources::Validator.validate_year(year.to_s) }
31
+ self.years = self.years + years
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DayOffs::Sources::Errors
4
+ class IncorrectAlpha2CountryError < StandardError; end
5
+ class IncorrectYearError < StandardError; end
6
+ class UnimplementedMethodError < StandardError; end
7
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DayOffs::Sources::Utils
4
+ class << self
5
+ def valid_country_alpha2_code?(country_code)
6
+ !!(country_code =~ /^[A-Z]{2}$/)
7
+ end
8
+
9
+ def valid_year?(year)
10
+ !!(year.to_s =~ /^[0-9]{4}$/)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DayOffs::Sources::Validator
4
+ class << self
5
+ def validate_country(country)
6
+ unless DayOffs::Sources::Utils.valid_country_alpha2_code?(country)
7
+ raise DayOffs::Sources::Errors::IncorrectAlpha2CountryError
8
+ end
9
+ end
10
+
11
+ def validate_year(year)
12
+ unless DayOffs::Sources::Utils.valid_year?(year)
13
+ raise DayOffs::Sources::Errors::IncorrectYearError
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DayOffs
4
+ VERSION = "0.1.0"
5
+ end
data/lib/day_offs.rb ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "day_offs/version"
4
+ require "zeitwerk"
5
+
6
+ loader = Zeitwerk::Loader.for_gem
7
+ loader.inflector.inflect(
8
+ "dsl" => "DSL"
9
+ )
10
+ loader.setup
11
+
12
+ module DayOffs
13
+ @registered_sources = []
14
+ @used_sources = {}
15
+
16
+ DayOff = Struct.new(:country, :date) do
17
+ def ==(other)
18
+ country == other.country && date == other.date
19
+ end
20
+ end
21
+
22
+ class << self
23
+ attr_reader :configuration
24
+ attr_accessor :registered_sources, :used_sources
25
+
26
+ def configure
27
+ @configuration = yield(Configuration.new)
28
+ DayOffs::Core.objectize_sources
29
+ end
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: day_offs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kroched
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-11-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: zeitwerk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.6'
27
+ description: Add day offs sources for different countries in a standardized manner
28
+ email:
29
+ - Nekitonich4@yandex.ru
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - ".rubocop.yml"
36
+ - CODE_OF_CONDUCT.md
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - day_offs.gemspec
41
+ - lib/day_offs.rb
42
+ - lib/day_offs/configuration.rb
43
+ - lib/day_offs/core.rb
44
+ - lib/day_offs/errors.rb
45
+ - lib/day_offs/sources/base.rb
46
+ - lib/day_offs/sources/dsl.rb
47
+ - lib/day_offs/sources/errors.rb
48
+ - lib/day_offs/sources/utils.rb
49
+ - lib/day_offs/sources/validator.rb
50
+ - lib/day_offs/version.rb
51
+ homepage: https://github.com/Kroch4ka/day_offs
52
+ licenses:
53
+ - MIT
54
+ metadata:
55
+ homepage_uri: https://github.com/Kroch4ka/day_offs
56
+ source_code_uri: https://github.com/Kroch4ka/day_offs
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 2.6.0
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.0.1
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Plugin system for support day offs sources
76
+ test_files: []