Class: Sidenotes::ModelInspector
- Inherits:
-
Object
- Object
- Sidenotes::ModelInspector
- Defined in:
- lib/sidenotes/model_inspector.rb
Constant Summary collapse
- SECTION_METHODS =
{ metadata: :metadata, columns: :columns, indexes: :indexes, associations: :associations, foreign_keys: :foreign_keys }.freeze
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#initialize(model) ⇒ ModelInspector
constructor
A new instance of ModelInspector.
- #inspect_model ⇒ Object
- #inspectable? ⇒ Boolean
Constructor Details
#initialize(model) ⇒ ModelInspector
Returns a new instance of ModelInspector.
7 8 9 |
# File 'lib/sidenotes/model_inspector.rb', line 7 def initialize(model) @model = model end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/sidenotes/model_inspector.rb', line 5 def model @model end |
Instance Method Details
#inspect_model ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sidenotes/model_inspector.rb', line 19 def inspect_model return nil unless inspectable? data = {} sections = Sidenotes.configuration.sections SECTION_METHODS.each do |section, method| data[section.to_s] = send(method) if sections.include?(section) end if sections.include?(:check_constraints) && supports_check_constraints? data['check_constraints'] = check_constraints end data end |
#inspectable? ⇒ Boolean
36 37 38 39 40 41 42 43 |
# File 'lib/sidenotes/model_inspector.rb', line 36 def inspectable? return false if model.abstract_class? return false unless model.respond_to?(:table_name) model.table_exists? rescue ActiveRecord::NoDatabaseError, ActiveRecord::StatementInvalid false end |