philosophal 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -1
  3. data/README.md +39 -0
  4. data/lib/philosophal/convertor.rb +9 -12
  5. data/lib/philosophal/loaders/json_loader.rb +4 -9
  6. data/lib/philosophal/properties/instance_methods.rb +76 -0
  7. data/lib/philosophal/properties/schema.rb +48 -0
  8. data/lib/philosophal/properties.rb +66 -88
  9. data/lib/philosophal/property.rb +162 -53
  10. data/lib/philosophal/transform.rb +8 -6
  11. data/lib/philosophal/types/array_of_type.rb +4 -3
  12. data/lib/philosophal/types/boolean_type.rb +1 -1
  13. data/lib/philosophal/types/hash_of_type.rb +8 -6
  14. data/lib/philosophal.rb +15 -17
  15. data/sig/manifest.yaml +5 -0
  16. data/sig/philosophal/convertor.rbs +35 -0
  17. data/sig/philosophal/errors/argument_error.rbs +4 -0
  18. data/sig/philosophal/errors/type_error.rbs +4 -0
  19. data/sig/philosophal/loaders/errors.rbs +6 -0
  20. data/sig/philosophal/loaders/json_loader.rbs +29 -0
  21. data/sig/philosophal/loaders.rbs +4 -0
  22. data/sig/philosophal/properties/instance_methods.rbs +26 -0
  23. data/sig/philosophal/properties/schema.rbs +47 -0
  24. data/sig/philosophal/properties.rbs +59 -0
  25. data/sig/philosophal/property.rbs +98 -0
  26. data/sig/philosophal/transform.rbs +7 -0
  27. data/sig/philosophal/types/any_type.rbs +9 -0
  28. data/sig/philosophal/types/array_of_type.rbs +23 -0
  29. data/sig/philosophal/types/boolean_type.rbs +11 -0
  30. data/sig/philosophal/types/hash_of_type.rbs +25 -0
  31. data/sig/philosophal/types.rbs +11 -0
  32. data/sig/philosophal.rbs +12 -0
  33. metadata +43 -14
  34. data/.rubocop.yml +0 -12
  35. data/.ruby-version +0 -1
  36. data/.tool-versions +0 -1
  37. data/Rakefile +0 -12
  38. data/VERSION +0 -1
@@ -0,0 +1,98 @@
1
+ module Philosophal
2
+ class Property
3
+ @writer_method_name: Symbol
4
+ @constant_name: Symbol
5
+ @boolean_method_name: Symbol
6
+ @description_method_name: Symbol
7
+ @was_method_name: Symbol
8
+ @changed_method_name: Symbol
9
+ @variable_name: Symbol
10
+ @was_variable_name: Symbol
11
+ @convert_method: Symbol | [Symbol?, untyped] | nil
12
+
13
+ def initialize: (
14
+ name: Symbol,
15
+ type: type_spec,
16
+ default: untyped,
17
+ transform: transform?,
18
+ immutable: bool,
19
+ description: String?,
20
+ json: bool | Symbol,
21
+ override: bool,
22
+ ?track_changes: bool
23
+ ) -> void
24
+
25
+ attr_reader name: Symbol
26
+
27
+ attr_reader type: type_spec
28
+
29
+ attr_reader default: untyped
30
+
31
+ attr_reader transform: transform?
32
+
33
+ attr_reader immutable: bool
34
+
35
+ attr_reader description: String?
36
+
37
+ attr_reader json: bool | Symbol
38
+
39
+ attr_reader override: bool
40
+
41
+ attr_reader track_changes: bool
42
+
43
+ def json_name: () -> Symbol
44
+
45
+ def default?: () -> bool
46
+
47
+ def default_value: () -> untyped
48
+
49
+ def transform?: () -> bool
50
+
51
+ def override?: () -> bool
52
+
53
+ def track_changes?: () -> bool
54
+
55
+ def check_conversion: (untyped value) -> untyped
56
+
57
+ def convert_method: () -> (Symbol | [Symbol?, untyped] | nil)
58
+
59
+ # Maps each method name to define to the generator that writes its code.
60
+ def method_generators: () -> Hash[Symbol, Symbol]
61
+
62
+ def change_tracking_generators: () -> Hash[Symbol, Symbol]
63
+
64
+ def constant_name: () -> Symbol
65
+
66
+ def writer_method_name: () -> Symbol
67
+
68
+ def generate_writer_method: (String buffer) -> String
69
+
70
+ def generate_immutable_writer_method: (String buffer) -> String
71
+
72
+ def reader_method_name: () -> Symbol
73
+
74
+ def variable_name: () -> Symbol
75
+
76
+ def generate_plain_reader_method: (String buffer) -> String
77
+
78
+ def generate_reader_method: (String buffer) -> String
79
+
80
+ def boolean_method_name: () -> Symbol
81
+
82
+ def generate_boolean_method: (String buffer) -> String
83
+
84
+ def description_method_name: () -> Symbol
85
+
86
+ def generate_description_method: (String buffer) -> String
87
+
88
+ def was_method_name: () -> Symbol
89
+
90
+ def was_variable_name: () -> Symbol
91
+
92
+ def generate_was_method: (String buffer) -> String
93
+
94
+ def changed_method_name: () -> Symbol
95
+
96
+ def generate_changed_method: (String buffer) -> String
97
+ end
98
+ end
@@ -0,0 +1,7 @@
1
+ module Philosophal
2
+ class Transform
3
+ def self.make: (transform method, untyped value) -> untyped
4
+
5
+ def self.self_method?: (Symbol method) -> bool
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module Philosophal
2
+ module Types
3
+ class AnyType
4
+ Instance: AnyType
5
+
6
+ def ===: (untyped _value) -> true
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ module Philosophal
2
+ module Types
3
+ class ArrayOfType
4
+ self.@memorization: Hash[Module, ArrayOfType]
5
+
6
+ def self.instance: (Module subtype) -> ArrayOfType
7
+
8
+ def self.memorization: () -> Hash[Module, ArrayOfType]
9
+
10
+ private
11
+
12
+ def self.new: (Module subtype) -> ArrayOfType
13
+
14
+ public
15
+
16
+ attr_reader subtype: Module
17
+
18
+ def initialize: (Module subtype) -> void
19
+
20
+ def ===: (untyped array) -> bool
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ module Philosophal
2
+ module Types
3
+ class BooleanType
4
+ Instance: BooleanType
5
+
6
+ TRUE_FALSE_SET: Set[bool]
7
+
8
+ def ===: (untyped value) -> bool
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ module Philosophal
2
+ module Types
3
+ class HashOfType
4
+ type subtype = { key_type: Module, value_type: Module }
5
+
6
+ self.@memorization: Hash[[Module, Module], HashOfType]
7
+
8
+ def self.instance: (Module key_type, Module value_type) -> HashOfType
9
+
10
+ def self.memorization: () -> Hash[[Module, Module], HashOfType]
11
+
12
+ private
13
+
14
+ def self.new: (subtype subtype) -> HashOfType
15
+
16
+ public
17
+
18
+ attr_reader subtype: subtype
19
+
20
+ def initialize: (subtype subtype) -> void
21
+
22
+ def ===: (untyped hash) -> bool
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ module Philosophal
2
+ module Types
3
+ def _Any: () -> AnyType
4
+
5
+ def _Boolean: () -> BooleanType
6
+
7
+ def _ArrayOf: (Module subtype) -> ArrayOfType
8
+
9
+ def _HashOf: (Module key_type, Module value_type) -> HashOfType
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module Philosophal
2
+ # A type accepted by cprop: a class (String, Integer, ...) or one of the Philosophal::Types helpers.
3
+ type type_spec = Module | Types::AnyType | Types::BooleanType | Types::ArrayOfType | Types::HashOfType
4
+
5
+ type transform = Symbol | ^(untyped) -> untyped
6
+
7
+ def self.convert: (Property property, untyped value) -> untyped
8
+
9
+ private
10
+
11
+ def self.convert_to_type: (Property property, untyped value) -> untyped
12
+ end
metadata CHANGED
@@ -1,30 +1,40 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philosophal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxime Désécot
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2026-06-29 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Auto convert value on setter method call
11
+ date: 2026-11-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ description: 'Declare typed attributes with cprop: values are converted, transformed,
28
+ defaulted or frozen on assignment, with JSON import/export.'
14
29
  email:
15
30
  - maxime.desecot@gmail.com
16
31
  executables: []
17
32
  extensions: []
18
33
  extra_rdoc_files: []
19
34
  files:
20
- - ".rubocop.yml"
21
- - ".ruby-version"
22
- - ".tool-versions"
23
35
  - CHANGELOG.md
24
36
  - LICENSE
25
37
  - README.md
26
- - Rakefile
27
- - VERSION
28
38
  - lib/philosophal.rb
29
39
  - lib/philosophal/convertor.rb
30
40
  - lib/philosophal/errors/argument_error.rb
@@ -33,6 +43,7 @@ files:
33
43
  - lib/philosophal/loaders/errors.rb
34
44
  - lib/philosophal/loaders/json_loader.rb
35
45
  - lib/philosophal/properties.rb
46
+ - lib/philosophal/properties/instance_methods.rb
36
47
  - lib/philosophal/properties/schema.rb
37
48
  - lib/philosophal/property.rb
38
49
  - lib/philosophal/transform.rb
@@ -41,12 +52,30 @@ files:
41
52
  - lib/philosophal/types/array_of_type.rb
42
53
  - lib/philosophal/types/boolean_type.rb
43
54
  - lib/philosophal/types/hash_of_type.rb
55
+ - sig/manifest.yaml
56
+ - sig/philosophal.rbs
57
+ - sig/philosophal/convertor.rbs
58
+ - sig/philosophal/errors/argument_error.rbs
59
+ - sig/philosophal/errors/type_error.rbs
60
+ - sig/philosophal/loaders.rbs
61
+ - sig/philosophal/loaders/errors.rbs
62
+ - sig/philosophal/loaders/json_loader.rbs
63
+ - sig/philosophal/properties.rbs
64
+ - sig/philosophal/properties/instance_methods.rbs
65
+ - sig/philosophal/properties/schema.rbs
66
+ - sig/philosophal/property.rbs
67
+ - sig/philosophal/transform.rbs
68
+ - sig/philosophal/types.rbs
69
+ - sig/philosophal/types/any_type.rbs
70
+ - sig/philosophal/types/array_of_type.rbs
71
+ - sig/philosophal/types/boolean_type.rbs
72
+ - sig/philosophal/types/hash_of_type.rbs
44
73
  homepage: https://github.com/RaoH37/philosophal
45
74
  licenses:
46
75
  - GPL-3.0-only
47
76
  metadata:
48
77
  homepage_uri: https://github.com/RaoH37/philosophal
49
- source_code_uri: https://github.com/RaoH37/philosophal
78
+ bug_tracker_uri: https://github.com/RaoH37/philosophal/issues
50
79
  changelog_uri: https://github.com/RaoH37/philosophal/blob/main/CHANGELOG.md
51
80
  rubygems_mfa_required: 'true'
52
81
  post_install_message:
@@ -57,15 +86,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
86
  requirements:
58
87
  - - ">="
59
88
  - !ruby/object:Gem::Version
60
- version: '3.1'
89
+ version: '3.3'
61
90
  required_rubygems_version: !ruby/object:Gem::Requirement
62
91
  requirements:
63
92
  - - ">="
64
93
  - !ruby/object:Gem::Version
65
94
  version: '0'
66
95
  requirements: []
67
- rubygems_version: 3.3.27
96
+ rubygems_version: 3.5.22
68
97
  signing_key:
69
98
  specification_version: 4
70
- summary: Philosophal setter convertor
99
+ summary: Typed, auto-converting properties for Ruby classes
71
100
  test_files: []
data/.rubocop.yml DELETED
@@ -1,12 +0,0 @@
1
- require:
2
- - rubocop-minitest
3
- - rubocop-packaging
4
- - rubocop-performance
5
- - rubocop-md
6
-
7
- AllCops:
8
- TargetRubyVersion: 3.1
9
- NewCops: enable
10
-
11
- Style/Documentation:
12
- Enabled: false
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 3.1.7
data/.tool-versions DELETED
@@ -1 +0,0 @@
1
- ruby 3.1.7
data/Rakefile DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'minitest/test_task'
5
-
6
- Minitest::TestTask.create
7
-
8
- require 'rubocop/rake_task'
9
-
10
- RuboCop::RakeTask.new
11
-
12
- task default: %i[test rubocop]
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.2.0