Module: Otoroshi::Sanctuary::ClassMethods
- Defined in:
- lib/otoroshi/sanctuary.rb
Overview
Class methods extended for the base class
Instance Method Summary collapse
-
#collection?(type) ⇒ true, false
Checks the type is an array.
-
#properties ⇒ Hash
Returns the class properties.
-
#property(name, type = Object, one_of: nil, assert: ->(_) { true }, allow_nil: false, default: nil) ⇒ void
Adds a new “property” to the class.
Instance Method Details
#collection?(type) ⇒ true, false
Checks the type is an array
68 69 70 |
# File 'lib/otoroshi/sanctuary.rb', line 68 def collection?(type) type == Array || type.is_a?(Array) end |
#properties ⇒ Hash
Note:
this method will be updated by #add_to_properties
Returns the class properties
77 78 79 |
# File 'lib/otoroshi/sanctuary.rb', line 77 def properties {} end |
#property(name, type = Object, one_of: nil, assert: ->(_) { true }, allow_nil: false, default: nil) ⇒ void
This method returns an undefined value.
Adds a new “property” to the class
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/otoroshi/sanctuary.rb', line 46 def property( # rubocop:disable Metrics/ParameterLists name, type = Object, one_of: nil, assert: ->(_) { true }, allow_nil: false, default: nil ) add_to_properties(name, type, one_of, assert, allow_nil, default) define_validate_type!(name, type, allow_nil) define_validate_inclusion!(name, type, one_of, allow_nil) define_validate_assertion!(name, type, assert, allow_nil) define_getter(name) define_setter(name) redefine_initialize end |