Class: RailsConsolePro::AssociationNavigator
- Inherits:
-
Object
- Object
- RailsConsolePro::AssociationNavigator
- Includes:
- ColorHelper
- Defined in:
- lib/rails_console_pro/association_navigator.rb
Overview
Interactive association navigator
Constant Summary collapse
- ASSOCIATION_ICONS =
{ belongs_to: "↖️", has_one: "→", has_many: "⇒", has_and_belongs_to_many: "⇔" }.freeze
Instance Attribute Summary collapse
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#initialize(model) ⇒ AssociationNavigator
constructor
A new instance of AssociationNavigator.
- #start ⇒ Object
Methods included from ColorHelper
#bold_color, #color, #method_missing, #pastel, #respond_to_missing?
Constructor Details
#initialize(model) ⇒ AssociationNavigator
Returns a new instance of AssociationNavigator.
17 18 19 20 21 |
# File 'lib/rails_console_pro/association_navigator.rb', line 17 def initialize(model) @model = resolve_model(model) @history = [] validate_model! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RailsConsolePro::ColorHelper
Instance Attribute Details
#history ⇒ Object (readonly)
Returns the value of attribute history.
15 16 17 |
# File 'lib/rails_console_pro/association_navigator.rb', line 15 def history @history end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
15 16 17 |
# File 'lib/rails_console_pro/association_navigator.rb', line 15 def model @model end |
Instance Method Details
#start ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rails_console_pro/association_navigator.rb', line 23 def start current_model = @model loop do (current_model) choice = get_user_choice(current_model) break if choice == :exit next handle_back(current_model) if choice == :back next unless choice @history.push(current_model) current_model = navigate_to(current_model, choice) end end |