Class: SourceMonitor::Configuration::ModelDefinition
- Inherits:
-
Object
- Object
- SourceMonitor::Configuration::ModelDefinition
- Defined in:
- lib/source_monitor/configuration/model_definition.rb
Defined Under Namespace
Classes: ConcernDefinition
Instance Attribute Summary collapse
-
#validations ⇒ Object
readonly
Returns the value of attribute validations.
Instance Method Summary collapse
- #each_concern ⇒ Object
- #include_concern(concern = nil, &block) ⇒ Object
-
#initialize ⇒ ModelDefinition
constructor
A new instance of ModelDefinition.
- #validate(handler = nil, **options, &block) ⇒ Object
Constructor Details
#initialize ⇒ ModelDefinition
Returns a new instance of ModelDefinition.
8 9 10 11 |
# File 'lib/source_monitor/configuration/model_definition.rb', line 8 def initialize @concern_definitions = [] @validations = [] end |
Instance Attribute Details
#validations ⇒ Object (readonly)
Returns the value of attribute validations.
6 7 8 |
# File 'lib/source_monitor/configuration/model_definition.rb', line 6 def validations @validations end |
Instance Method Details
#each_concern ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/source_monitor/configuration/model_definition.rb', line 22 def each_concern return enum_for(:each_concern) unless block_given? @concern_definitions.each do |definition| yield definition.signature, definition.resolve end end |
#include_concern(concern = nil, &block) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/source_monitor/configuration/model_definition.rb', line 13 def include_concern(concern = nil, &block) definition = ConcernDefinition.new(concern, block) unless @concern_definitions.any? { |existing| existing.signature == definition.signature } @concern_definitions << definition end definition.return_value end |
#validate(handler = nil, **options, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/source_monitor/configuration/model_definition.rb', line 30 def validate(handler = nil, **, &block) callable = if block block elsif handler.respond_to?(:call) && !handler.is_a?(Symbol) && !handler.is_a?(String) handler elsif handler.is_a?(Symbol) || handler.is_a?(String) handler.to_sym else raise ArgumentError, "Invalid validation handler #{handler.inspect}" end validation = ValidationDefinition.new(callable, ) @validations << validation validation end |