literal 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +100 -54
  3. data/lib/literal/data.rb +24 -11
  4. data/lib/literal/data_property.rb +16 -0
  5. data/lib/literal/data_structure.rb +60 -0
  6. data/lib/literal/enum.rb +176 -0
  7. data/lib/literal/errors/argument_error.rb +5 -0
  8. data/lib/literal/errors/error.rb +4 -0
  9. data/lib/literal/errors/type_error.rb +10 -0
  10. data/lib/literal/null.rb +9 -0
  11. data/lib/literal/object.rb +5 -0
  12. data/lib/literal/properties/data_schema.rb +9 -0
  13. data/lib/literal/properties/schema.rb +118 -0
  14. data/lib/literal/properties.rb +91 -0
  15. data/lib/literal/property.rb +196 -0
  16. data/lib/literal/struct.rb +8 -34
  17. data/lib/literal/types/any_type.rb +10 -3
  18. data/lib/literal/types/array_type.rb +10 -9
  19. data/lib/literal/types/boolean_type.rb +18 -1
  20. data/lib/literal/types/callable_type.rb +12 -0
  21. data/lib/literal/types/class_type.rb +10 -9
  22. data/lib/literal/types/constraint_type.rb +16 -0
  23. data/lib/literal/types/descendant_type.rb +13 -0
  24. data/lib/literal/types/enumerable_type.rb +10 -9
  25. data/lib/literal/types/falsy_type.rb +12 -0
  26. data/lib/literal/types/float_type.rb +7 -10
  27. data/lib/literal/types/frozen_type.rb +14 -0
  28. data/lib/literal/types/hash_type.rb +11 -10
  29. data/lib/literal/types/integer_type.rb +7 -10
  30. data/lib/literal/types/interface_type.rb +11 -9
  31. data/lib/literal/types/intersection_type.rb +20 -0
  32. data/lib/literal/types/json_data_type.rb +21 -0
  33. data/lib/literal/types/lambda_type.rb +12 -0
  34. data/lib/literal/types/map_type.rb +16 -0
  35. data/lib/literal/types/never_type.rb +12 -0
  36. data/lib/literal/types/nilable_type.rb +14 -0
  37. data/lib/literal/types/not_type.rb +14 -0
  38. data/lib/literal/types/procable_type.rb +12 -0
  39. data/lib/literal/types/range_type.rb +20 -0
  40. data/lib/literal/types/set_type.rb +10 -9
  41. data/lib/literal/types/string_type.rb +10 -0
  42. data/lib/literal/types/symbol_type.rb +10 -0
  43. data/lib/literal/types/truthy_type.rb +12 -0
  44. data/lib/literal/types/tuple_type.rb +12 -9
  45. data/lib/literal/types/union_type.rb +43 -9
  46. data/lib/literal/types/void_type.rb +12 -0
  47. data/lib/literal/types.rb +195 -54
  48. data/lib/literal/version.rb +1 -1
  49. data/lib/literal.rb +28 -10
  50. data/lib/literal.test.rb +5 -0
  51. metadata +41 -19
  52. data/CHANGELOG.md +0 -5
  53. data/CODE_OF_CONDUCT.md +0 -84
  54. data/Gemfile +0 -9
  55. data/Gemfile.lock +0 -29
  56. data/Rakefile +0 -12
  57. data/lib/literal/attributes.rb +0 -33
  58. data/lib/literal/initializer.rb +0 -11
  59. data/lib/literal/model.rb +0 -22
  60. data/literal.gemspec +0 -37
data/CODE_OF_CONDUCT.md DELETED
@@ -1,84 +0,0 @@
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 joel@drapper.me. 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 DELETED
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in strict_attributes.gemspec
6
- gemspec
7
-
8
- gem "zeitwerk"
9
- gem "green_dots", git: "https://github.com/joeldrapper/green_dots.git"
data/Gemfile.lock DELETED
@@ -1,29 +0,0 @@
1
- GIT
2
- remote: https://github.com/joeldrapper/green_dots.git
3
- revision: 776745d38c9523e403b445eeef8b374ffb130f8b
4
- specs:
5
- green_dots (0.1.0)
6
- concurrent-ruby
7
- zeitwerk
8
-
9
- PATH
10
- remote: .
11
- specs:
12
- literal (0.1.0)
13
-
14
- GEM
15
- remote: https://rubygems.org/
16
- specs:
17
- concurrent-ruby (1.2.2)
18
- zeitwerk (2.6.8)
19
-
20
- PLATFORMS
21
- arm64-darwin-22
22
-
23
- DEPENDENCIES
24
- green_dots!
25
- literal!
26
- zeitwerk
27
-
28
- BUNDLED WITH
29
- 2.4.12
data/Rakefile DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
5
-
6
- Rake::TestTask.new(:test) do |t|
7
- t.libs << "test"
8
- t.libs << "lib"
9
- t.test_files = FileList["test/**/test_*.rb"]
10
- end
11
-
12
- task default: :test
@@ -1,33 +0,0 @@
1
- module Literal::Attributes
2
- extend Literal::Types
3
-
4
- def attribute(name, type, reader: false, writer: :private)
5
- __attributes__ << name
6
-
7
- writer_name = :"#{name}="
8
- ivar_name = :"@#{name}"
9
-
10
- define_method writer_name do |value|
11
- raise Literal::TypeError, "Expected `#{value.inspect}` to be a `#{type.inspect}`." unless type === value
12
- instance_variable_set(ivar_name, value)
13
- end
14
-
15
- private writer_name unless writer == :public
16
-
17
- if reader
18
- attr_reader name
19
- private name unless reader == :public
20
- end
21
-
22
- name
23
- end
24
-
25
- def __attributes__
26
- return @__attributes__ if defined?(@__attributes__)
27
- @__attributes__ = superclass.is_a?(self) ? superclass.__attributes__.dup : []
28
- end
29
-
30
- def self.extended(base)
31
- base.include(Literal::Initializer)
32
- end
33
- end
@@ -1,11 +0,0 @@
1
- module Literal::Initializer
2
- def initialize(**attributes)
3
- self.class.__attributes__.each do |name|
4
- attributes[name] ||= nil
5
- end
6
-
7
- attributes.each do |name, value|
8
- send("#{name}=", value)
9
- end
10
- end
11
- end
data/lib/literal/model.rb DELETED
@@ -1,22 +0,0 @@
1
- class Literal::Model
2
- extend Literal::Types
3
- include Literal::Initializer
4
-
5
- def self.__attributes__
6
- return @required_attributes if defined?(@required_attributes)
7
- @required_attributes = superclass.is_a?(self) ? superclass.required_attributes.dup : []
8
- end
9
-
10
- def self.attribute(name, type)
11
- __attributes__ << name
12
-
13
- writer_name = :"#{name}="
14
-
15
- define_method writer_name do |value|
16
- raise Literal::TypeError, "Expected #{name}: `#{value.inspect}` to be: `#{type.inspect}`." unless type === value
17
- super(value)
18
- end
19
-
20
- name
21
- end
22
- end
data/literal.gemspec DELETED
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/literal/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "literal"
7
- spec.version = Literal::VERSION
8
- spec.authors = ["Joel Drapper"]
9
- spec.email = ["joel@drapper.me"]
10
-
11
- spec.summary = "Strict Attributes is a gem that allows you to define strict attributes on your models."
12
- spec.description = "Strict Attributes is a gem that allows you to define strict attributes on your models."
13
- spec.homepage = "https://github.com/joeldrapper/literal"
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/joeldrapper/literal"
19
- spec.metadata["changelog_uri"] = "https://github.com/joeldrapper/literal/blob/master/CHANGELOG.md"
20
-
21
- # Specify which files should be added to the gem when it is released.
22
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
- spec.files = Dir.chdir(__dir__) do
24
- `git ls-files -z`.split("\x0").reject do |f|
25
- (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
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
-
35
- # For more information and examples about making a new gem, check out our
36
- # guide at: https://bundler.io/guides/creating_gem.html
37
- end