philosophal 1.0.1 → 1.1.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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.tool-versions +1 -1
- data/README.md +3 -3
- data/VERSION +1 -1
- data/lib/philosophal/properties.rb +23 -2
- data/lib/philosophal/property.rb +12 -2
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d09ac65f9fd7fa000c82fa1d9e77c85e22866d2a9a1ffdfa1a63e19b36cb909b
|
|
4
|
+
data.tar.gz: bdf93344392beabea229e214b1403e88749fd51839e68c9e675fb9566fad5e52
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f729b3f0a820e25d39e9de2eecd47cc7cd7bc12fa32cdc6306c81b02418f98507a3d814582f638822834dc3f9cae055b00db909a3cc66c3112c7ccb8118aaf90
|
|
7
|
+
data.tar.gz: a1ab12ea326c278c6d7eab6b555605642f0ce34d30d27782efe4a6991cbd3fc3b63917cbef00a8b21133b47e096056b2ba34234b40017239d556880960fa67f0
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.1.
|
|
1
|
+
3.1.7
|
data/.tool-versions
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
ruby 3.1.
|
|
1
|
+
ruby 3.1.7
|
data/README.md
CHANGED
|
@@ -22,9 +22,9 @@ class Person
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
maxime = Person.new
|
|
25
|
-
maxime.first_name =
|
|
26
|
-
maxime.last_name =
|
|
27
|
-
maxime.age =
|
|
25
|
+
maxime.first_name = 'Maxime'
|
|
26
|
+
maxime.last_name = 'Désécot'
|
|
27
|
+
maxime.age = '40'
|
|
28
28
|
puts maxime.inspect
|
|
29
29
|
#<Person:0x00007da7088eed88 @first_name="maxime", @last_name="DÉSÉCOT", @age=40>
|
|
30
30
|
````
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.0
|
|
1
|
+
1.1.0
|
|
@@ -6,7 +6,7 @@ module Philosophal
|
|
|
6
6
|
|
|
7
7
|
include Philosophal::Types
|
|
8
8
|
|
|
9
|
-
def cprop(name, type, default: nil, transform: nil, immutable: false)
|
|
9
|
+
def cprop(name, type, default: nil, transform: nil, immutable: false, description: nil)
|
|
10
10
|
default.freeze if default && !(default.is_a?(Proc) || default.frozen?)
|
|
11
11
|
|
|
12
12
|
if transform && !(transform.is_a?(Proc) || transform.is_a?(Symbol))
|
|
@@ -17,7 +17,13 @@ module Philosophal
|
|
|
17
17
|
raise Philosophal::ArgumentError, 'immutable param must be true or false.'
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
if description
|
|
21
|
+
raise Philosophal::ArgumentError, 'description param must be a string.' unless description.is_a?(String)
|
|
22
|
+
|
|
23
|
+
description.freeze unless description.frozen?
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
property = __philosophal_property_class__.new(name:, type:, default:, transform:, immutable:, description:)
|
|
21
27
|
|
|
22
28
|
philosophal_properties << property
|
|
23
29
|
__define_philosophal_methods__(property)
|
|
@@ -34,6 +40,18 @@ module Philosophal
|
|
|
34
40
|
end
|
|
35
41
|
end
|
|
36
42
|
|
|
43
|
+
def philosophal_descriptions
|
|
44
|
+
return @philosophal_descriptions if defined?(@philosophal_descriptions)
|
|
45
|
+
|
|
46
|
+
@philosophal_descriptions = philosophal_properties.properties_index.values.select(&:description).to_h do |property|
|
|
47
|
+
[
|
|
48
|
+
property.name,
|
|
49
|
+
property.description
|
|
50
|
+
]
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
alias cprop_descriptions philosophal_descriptions
|
|
54
|
+
|
|
37
55
|
private
|
|
38
56
|
|
|
39
57
|
def __philosophal_property_class__
|
|
@@ -94,8 +112,11 @@ module Philosophal
|
|
|
94
112
|
end
|
|
95
113
|
|
|
96
114
|
new_property.generate_reader_method(buffer)
|
|
115
|
+
|
|
97
116
|
new_property.generate_boolean_method(buffer) if new_property.type == Philosophal::Types::BooleanType::Instance
|
|
98
117
|
|
|
118
|
+
new_property.generate_description_method(buffer) if new_property.description
|
|
119
|
+
|
|
99
120
|
# puts buffer
|
|
100
121
|
|
|
101
122
|
buffer
|
data/lib/philosophal/property.rb
CHANGED
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
module Philosophal
|
|
4
4
|
class Property
|
|
5
|
-
def initialize(name:, type:, default:, transform:, immutable:)
|
|
5
|
+
def initialize(name:, type:, default:, transform:, immutable:, description:)
|
|
6
6
|
@name = name
|
|
7
7
|
@type = type
|
|
8
8
|
@default = default
|
|
9
9
|
@transform = transform
|
|
10
10
|
@immutable = immutable
|
|
11
|
+
@description = description
|
|
11
12
|
end
|
|
12
13
|
|
|
13
|
-
attr_reader :name, :type, :default, :transform, :immutable
|
|
14
|
+
attr_reader :name, :type, :default, :transform, :immutable, :description
|
|
14
15
|
|
|
15
16
|
def default?
|
|
16
17
|
@default != nil
|
|
@@ -74,5 +75,14 @@ module Philosophal
|
|
|
74
75
|
'!!@' << @name.name <<
|
|
75
76
|
"\nend\n"
|
|
76
77
|
end
|
|
78
|
+
|
|
79
|
+
def generate_description_method(buffer = +'')
|
|
80
|
+
buffer <<
|
|
81
|
+
' def ' <<
|
|
82
|
+
@name.name <<
|
|
83
|
+
"_description\n " \
|
|
84
|
+
'%(' << @description << ')' \
|
|
85
|
+
"\nend\n"
|
|
86
|
+
end
|
|
77
87
|
end
|
|
78
88
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philosophal
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Maxime Désécot
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-06-
|
|
11
|
+
date: 2026-06-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Auto convert value on setter method call
|
|
14
14
|
email:
|
|
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
61
61
|
- !ruby/object:Gem::Version
|
|
62
62
|
version: '0'
|
|
63
63
|
requirements: []
|
|
64
|
-
rubygems_version: 3.3.
|
|
64
|
+
rubygems_version: 3.3.27
|
|
65
65
|
signing_key:
|
|
66
66
|
specification_version: 4
|
|
67
67
|
summary: Philosophal setter convertor
|