Module: Stannum::Entities::Constraints
- Included in:
- Stannum::Entity, Struct
- Defined in:
- lib/stannum/entities/constraints.rb
Overview
Methods for defining and accessing entity constraints.
Defined Under Namespace
Modules: AttributesMethods, ClassMethods
Class Method Summary collapse
-
.apply(other) ⇒ Object
Generates a Contract for the class.
Class Method Details
.apply(other) ⇒ Object
Generates a Contract for the class.
Creates a new Stannum::Contract and sets it as the class’s :Contract constant. If the superclass is an entity class (and already defines its own Contract, concatenates the superclass Contract into the class Contract).
144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/stannum/entities/constraints.rb', line 144 def apply(other) return unless other.is_a?(Class) return if entity_class?(other) contract = Stannum::Contract.new other.const_set(:Contract, contract) return unless entity_class?(other.superclass) contract.concat(other.superclass::Contract) end |