Module: Philosophal::Properties
- Includes:
- Types
- Defined in:
- lib/philosophal/properties.rb,
lib/philosophal/properties/schema.rb
Defined Under Namespace
Classes: Schema
Instance Method Summary
collapse
Methods included from Types
#_Any, #_ArrayOf, #_Boolean, #_HashOf
Instance Method Details
#cprop(name, type, default: nil, transform: nil, immutable: false, description: nil) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/philosophal/properties.rb', line 9
def cprop(name, type, default: nil, transform: nil, immutable: false, description: nil)
default.freeze if default && !(default.is_a?(Proc) || default.frozen?)
if transform && !(transform.is_a?(Proc) || transform.is_a?(Symbol))
raise Philosophal::ArgumentError, "transform param must be a Symbol object or a Proc (#{name})."
end
unless Philosophal::Types::BooleanType::TRUE_FALSE_SET.include?(immutable)
raise Philosophal::ArgumentError, 'immutable param must be true or false.'
end
if description
raise Philosophal::ArgumentError, 'description param must be a string.' unless description.is_a?(String)
description.freeze unless description.frozen?
end
property = __philosophal_property_class__.new(name:, type:, default:, transform:, immutable:, description:)
philosophal_properties << property
__define_philosophal_methods__(property)
include(__philosophal_extension__)
end
|
#philosophal_descriptions ⇒ Object
Also known as:
cprop_descriptions
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/philosophal/properties.rb', line 43
def philosophal_descriptions
return @philosophal_descriptions if defined?(@philosophal_descriptions)
@philosophal_descriptions = philosophal_properties.properties_index.values.select(&:description).to_h do |property|
[
property.name,
property.description
]
end
end
|
#philosophal_properties ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/philosophal/properties.rb', line 33
def philosophal_properties
return @philosophal_properties if defined?(@philosophal_properties)
@philosophal_properties = if defined?(superclass) && superclass.is_a?(Philosophal::Properties)
superclass.philosophal_properties.dup
else
Philosophal::Properties::Schema.new
end
end
|