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
- #cprop(name, type, default: nil, transform: nil, immutable: false) ⇒ Object
- #philosophal_properties ⇒ Object
Methods included from Types
#_Any, #_ArrayOf, #_Boolean, #_HashOf
Instance Method Details
#cprop(name, type, default: nil, transform: nil, immutable: false) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/philosophal/properties.rb', line 9 def cprop(name, type, default: nil, transform: nil, immutable: false) 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 property = __philosophal_property_class__.new(name:, type:, default:, transform:, immutable:) philosophal_properties << property __define_philosophal_methods__(property) include(__philosophal_extension__) end |
#philosophal_properties ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/philosophal/properties.rb', line 27 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 |