Class: LolDba::RelationInspector
- Inherits:
-
Object
- Object
- LolDba::RelationInspector
- Defined in:
- lib/lol_dba/index_finding/relation_inspector.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
-
#reflection_name ⇒ Object
readonly
Returns the value of attribute reflection_name.
-
#reflection_options ⇒ Object
readonly
Returns the value of attribute reflection_options.
Instance Method Summary collapse
- #get_through_foreign_key(target_class, reflection_options) ⇒ Object
-
#initialize(model_class, reflection_options, reflection_name) ⇒ RelationInspector
constructor
A new instance of RelationInspector.
- #reflections ⇒ Object
Constructor Details
#initialize(model_class, reflection_options, reflection_name) ⇒ RelationInspector
Returns a new instance of RelationInspector.
5 6 7 8 9 |
# File 'lib/lol_dba/index_finding/relation_inspector.rb', line 5 def initialize(model_class, , reflection_name) @model_class = model_class @reflection_options = @reflection_name = reflection_name end |
Instance Attribute Details
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
3 4 5 |
# File 'lib/lol_dba/index_finding/relation_inspector.rb', line 3 def model_class @model_class end |
#reflection_name ⇒ Object (readonly)
Returns the value of attribute reflection_name.
3 4 5 |
# File 'lib/lol_dba/index_finding/relation_inspector.rb', line 3 def reflection_name @reflection_name end |
#reflection_options ⇒ Object (readonly)
Returns the value of attribute reflection_options.
3 4 5 |
# File 'lib/lol_dba/index_finding/relation_inspector.rb', line 3 def @reflection_options end |
Instance Method Details
#get_through_foreign_key(target_class, reflection_options) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/lol_dba/index_finding/relation_inspector.rb', line 11 def get_through_foreign_key(target_class, ) # has_many :through reflection = target_class.reflections[.[:through].to_s] # has_and_belongs_to_many reflection ||= # Guess foreign key? if reflection.[:foreign_key] reflection.[:foreign_key] else "#{target_class.name.tableize.singularize}_id" end end |
#reflections ⇒ Object
26 27 28 |
# File 'lib/lol_dba/index_finding/relation_inspector.rb', line 26 def reflections model_class.reflections.stringify_keys end |