Module: LazyRecord::Nesting
- Included in:
- Associations, Collections
- Defined in:
- lib/lazy_record/nesting.rb
Overview
Apply the same namespace nesting as self to another object.
Instance Method Summary collapse
- #apply_nesting(class_name) ⇒ Object
- #apply_nesting_one_level_back(class_name) ⇒ Object
- #lazy_const_get(class_name) ⇒ Object
- #lazy_const_get_one_level_back(class_name) ⇒ Object
Instance Method Details
#apply_nesting(class_name) ⇒ Object
6 7 8 |
# File 'lib/lazy_record/nesting.rb', line 6 def apply_nesting(class_name) "#{to_s.split('::')[0..-2].join('::')}::#{class_name}" end |
#apply_nesting_one_level_back(class_name) ⇒ Object
10 11 12 |
# File 'lib/lazy_record/nesting.rb', line 10 def apply_nesting_one_level_back(class_name) "#{to_s.split('::')[0..-3].join('::')}::#{class_name}" end |
#lazy_const_get(class_name) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/lazy_record/nesting.rb', line 14 def lazy_const_get(class_name) lambda do begin const_get(class_name) rescue NameError const_get apply_nesting(class_name) end end end |
#lazy_const_get_one_level_back(class_name) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/lazy_record/nesting.rb', line 24 def lazy_const_get_one_level_back(class_name) lambda do begin const_get(class_name) rescue NameError const_get apply_nesting_one_level_back(class_name) end end end |