Class: ZodRails::Introspection::ModelInspector
- Inherits:
-
Object
- Object
- ZodRails::Introspection::ModelInspector
- Defined in:
- lib/zod_rails/introspection/model_inspector.rb
Instance Attribute Summary collapse
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
Instance Method Summary collapse
- #columns ⇒ Object
- #enums ⇒ Object
-
#initialize(model_class) ⇒ ModelInspector
constructor
A new instance of ModelInspector.
- #model_name ⇒ Object
- #validations_for(attribute) ⇒ Object
Constructor Details
#initialize(model_class) ⇒ ModelInspector
Returns a new instance of ModelInspector.
8 9 10 |
# File 'lib/zod_rails/introspection/model_inspector.rb', line 8 def initialize(model_class) @model_class = model_class end |
Instance Attribute Details
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
6 7 8 |
# File 'lib/zod_rails/introspection/model_inspector.rb', line 6 def model_class @model_class end |
Instance Method Details
#columns ⇒ Object
12 13 14 |
# File 'lib/zod_rails/introspection/model_inspector.rb', line 12 def columns @columns ||= model_class.columns.map { |col| ColumnInfo.from_column(col) } end |
#enums ⇒ Object
25 26 27 |
# File 'lib/zod_rails/introspection/model_inspector.rb', line 25 def enums @enums ||= model_class.defined_enums end |
#model_name ⇒ Object
29 30 31 |
# File 'lib/zod_rails/introspection/model_inspector.rb', line 29 def model_name model_class.name end |
#validations_for(attribute) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/zod_rails/introspection/model_inspector.rb', line 16 def validations_for(attribute) attr_sym = attribute.to_sym model_class.validators.each_with_object([]) do |validator, result| next unless validator.attributes.include?(attr_sym) result << ValidationInfo.from_validator(validator, attribute) end end |