Class: RailsConsolePro::IntrospectResult
- Inherits:
-
Object
- Object
- RailsConsolePro::IntrospectResult
- Defined in:
- lib/rails_console_pro/introspect_result.rb
Overview
Value object for model introspection results
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
readonly
Returns the value of attribute callbacks.
-
#concerns ⇒ Object
readonly
Returns the value of attribute concerns.
-
#enums ⇒ Object
readonly
Returns the value of attribute enums.
-
#lifecycle_hooks ⇒ Object
readonly
Returns the value of attribute lifecycle_hooks.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#scopes ⇒ Object
readonly
Returns the value of attribute scopes.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#validations ⇒ Object
readonly
Returns the value of attribute validations.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#callbacks_by_type(type) ⇒ Object
Get callbacks by type.
-
#enum_values(enum_name) ⇒ Object
Get enum values.
-
#export_to_file(file_path, format: nil) ⇒ Object
Export to file.
-
#has_callbacks? ⇒ Boolean
Query methods.
- #has_concerns? ⇒ Boolean
- #has_enums? ⇒ Boolean
- #has_scopes? ⇒ Boolean
- #has_validations? ⇒ Boolean
-
#initialize(model:, callbacks: {}, enums: {}, concerns: [], scopes: {}, validations: [], lifecycle_hooks: {}, timestamp: Time.current) ⇒ IntrospectResult
constructor
A new instance of IntrospectResult.
-
#method_source(method_name) ⇒ Object
Get method source location.
-
#scope_sql(scope_name) ⇒ Object
Get scope SQL.
-
#to_html(style: :default) ⇒ Object
Export to HTML.
-
#to_json(pretty: true) ⇒ Object
Export to JSON.
-
#to_yaml ⇒ Object
Export to YAML.
-
#validations_for(attribute) ⇒ Object
Get validations for attribute.
Constructor Details
#initialize(model:, callbacks: {}, enums: {}, concerns: [], scopes: {}, validations: [], lifecycle_hooks: {}, timestamp: Time.current) ⇒ IntrospectResult
Returns a new instance of IntrospectResult.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rails_console_pro/introspect_result.rb', line 9 def initialize(model:, callbacks: {}, enums: {}, concerns: [], scopes: {}, validations: [], lifecycle_hooks: {}, timestamp: Time.current) @model = model @callbacks = callbacks @enums = enums @concerns = concerns @scopes = scopes @validations = validations @lifecycle_hooks = lifecycle_hooks @timestamp = validate_model! end |
Instance Attribute Details
#callbacks ⇒ Object (readonly)
Returns the value of attribute callbacks.
6 7 8 |
# File 'lib/rails_console_pro/introspect_result.rb', line 6 def callbacks @callbacks end |
#concerns ⇒ Object (readonly)
Returns the value of attribute concerns.
6 7 8 |
# File 'lib/rails_console_pro/introspect_result.rb', line 6 def concerns @concerns end |
#enums ⇒ Object (readonly)
Returns the value of attribute enums.
6 7 8 |
# File 'lib/rails_console_pro/introspect_result.rb', line 6 def enums @enums end |
#lifecycle_hooks ⇒ Object (readonly)
Returns the value of attribute lifecycle_hooks.
6 7 8 |
# File 'lib/rails_console_pro/introspect_result.rb', line 6 def lifecycle_hooks @lifecycle_hooks end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
6 7 8 |
# File 'lib/rails_console_pro/introspect_result.rb', line 6 def model @model end |
#scopes ⇒ Object (readonly)
Returns the value of attribute scopes.
6 7 8 |
# File 'lib/rails_console_pro/introspect_result.rb', line 6 def scopes @scopes end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
6 7 8 |
# File 'lib/rails_console_pro/introspect_result.rb', line 6 def @timestamp end |
#validations ⇒ Object (readonly)
Returns the value of attribute validations.
6 7 8 |
# File 'lib/rails_console_pro/introspect_result.rb', line 6 def validations @validations end |
Instance Method Details
#==(other) ⇒ Object
23 24 25 |
# File 'lib/rails_console_pro/introspect_result.rb', line 23 def ==(other) other.is_a?(self.class) && other.model == model && other. == end |
#callbacks_by_type(type) ⇒ Object
Get callbacks by type
49 50 51 |
# File 'lib/rails_console_pro/introspect_result.rb', line 49 def callbacks_by_type(type) callbacks[type] || [] end |
#enum_values(enum_name) ⇒ Object
Get enum values
59 60 61 |
# File 'lib/rails_console_pro/introspect_result.rb', line 59 def enum_values(enum_name) enums.dig(enum_name.to_s, :values) || [] end |
#export_to_file(file_path, format: nil) ⇒ Object
Export to file
90 91 92 |
# File 'lib/rails_console_pro/introspect_result.rb', line 90 def export_to_file(file_path, format: nil) FormatExporter.export_to_file(self, file_path, format: format) end |
#has_callbacks? ⇒ Boolean
Query methods
28 29 30 |
# File 'lib/rails_console_pro/introspect_result.rb', line 28 def has_callbacks? callbacks.any? end |
#has_concerns? ⇒ Boolean
36 37 38 |
# File 'lib/rails_console_pro/introspect_result.rb', line 36 def has_concerns? concerns.any? end |
#has_enums? ⇒ Boolean
32 33 34 |
# File 'lib/rails_console_pro/introspect_result.rb', line 32 def has_enums? enums.any? end |
#has_scopes? ⇒ Boolean
40 41 42 |
# File 'lib/rails_console_pro/introspect_result.rb', line 40 def has_scopes? scopes.any? end |
#has_validations? ⇒ Boolean
44 45 46 |
# File 'lib/rails_console_pro/introspect_result.rb', line 44 def has_validations? validations.any? end |
#method_source(method_name) ⇒ Object
Get method source location
69 70 71 72 |
# File 'lib/rails_console_pro/introspect_result.rb', line 69 def method_source(method_name) collector = Services::IntrospectionCollector.new(model) collector.method_source_location(method_name) end |
#scope_sql(scope_name) ⇒ Object
Get scope SQL
64 65 66 |
# File 'lib/rails_console_pro/introspect_result.rb', line 64 def scope_sql(scope_name) scopes.dig(scope_name.to_sym, :sql) end |
#to_html(style: :default) ⇒ Object
Export to HTML
85 86 87 |
# File 'lib/rails_console_pro/introspect_result.rb', line 85 def to_html(style: :default) FormatExporter.to_html(self, title: "Introspection: #{model.name}", style: style) end |
#to_json(pretty: true) ⇒ Object
Export to JSON
75 76 77 |
# File 'lib/rails_console_pro/introspect_result.rb', line 75 def to_json(pretty: true) FormatExporter.to_json(self, pretty: pretty) end |
#to_yaml ⇒ Object
Export to YAML
80 81 82 |
# File 'lib/rails_console_pro/introspect_result.rb', line 80 def to_yaml FormatExporter.to_yaml(self) end |
#validations_for(attribute) ⇒ Object
Get validations for attribute
54 55 56 |
# File 'lib/rails_console_pro/introspect_result.rb', line 54 def validations_for(attribute) validations[attribute] || [] end |