Class: Typelizer::ModelPlugins::ActiveRecord
- Inherits:
-
Object
- Object
- Typelizer::ModelPlugins::ActiveRecord
- Defined in:
- lib/typelizer/model_plugins/active_record.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
Instance Method Summary collapse
- #comment_for(prop) ⇒ Object
- #enum_for(prop) ⇒ Object
- #infer_types(prop) ⇒ Object
-
#initialize(model_class:, config:) ⇒ ActiveRecord
constructor
A new instance of ActiveRecord.
Constructor Details
#initialize(model_class:, config:) ⇒ ActiveRecord
Returns a new instance of ActiveRecord.
4 5 6 7 |
# File 'lib/typelizer/model_plugins/active_record.rb', line 4 def initialize(model_class:, config:) @model_class = model_class @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/typelizer/model_plugins/active_record.rb', line 9 def config @config end |
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
9 10 11 |
# File 'lib/typelizer/model_plugins/active_record.rb', line 9 def model_class @model_class end |
Instance Method Details
#comment_for(prop) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/typelizer/model_plugins/active_record.rb', line 21 def comment_for(prop) column = columns_hash&.dig(prop.column_name.to_s) return nil unless column prop.comment = column.comment end |
#enum_for(prop) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/typelizer/model_plugins/active_record.rb', line 28 def enum_for(prop) return unless model_class&.defined_enums&.key?(prop.column_name.to_s) prop.enum = model_class.defined_enums[prop.column_name.to_s].keys prop.enum_type_name = "#{model_class.name.demodulize}#{prop.column_name.to_s.camelize}" prop.enum end |
#infer_types(prop) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/typelizer/model_plugins/active_record.rb', line 11 def infer_types(prop) infer_types_for_association(prop) || infer_types_for_column(prop) || infer_types_for_association_ids(prop) || infer_types_for_delegate(prop) || infer_types_for_attribute(prop) prop end |