Module: Maglev::Page::PathConcern
- Extended by:
- ActiveSupport::Concern
- Included in:
- Maglev::Page
- Defined in:
- app/models/maglev/page/path_concern.rb
Overview
rubocop:disable Style/ClassAndModuleChildren
Constant Summary collapse
- COMMON_ASSOCIATION_PATH_OPTIONS =
{ class_name: '::Maglev::PagePath', foreign_key: 'maglev_page_id', inverse_of: :page }.freeze
Instance Method Summary collapse
- #canonical_path_hash ⇒ Object
- #current_path ⇒ Object
- #default_path ⇒ Object
- #disable_spawn_redirection ⇒ Object
- #path ⇒ Object
- #path=(value) ⇒ Object
- #path_hash ⇒ Object
- #spawn_redirection_disabled? ⇒ Boolean
Instance Method Details
#canonical_path_hash ⇒ Object
56 57 58 59 60 |
# File 'app/models/maglev/page/path_concern.rb', line 56 def canonical_path_hash @canonical_path_hash ||= canonical_paths.to_a.each_with_object({}.with_indifferent_access) do |path, memo| memo[path.locale] ||= path end end |
#current_path ⇒ Object
51 52 53 54 |
# File 'app/models/maglev/page/path_concern.rb', line 51 def current_path locale = Maglev::I18n.current_locale canonical_path_hash[locale] ||= paths.build(locale: locale, canonical: true) end |
#default_path ⇒ Object
32 33 34 |
# File 'app/models/maglev/page/path_concern.rb', line 32 def default_path @default_path ||= path_hash[Maglev::I18n.default_locale] end |
#disable_spawn_redirection ⇒ Object
66 67 68 |
# File 'app/models/maglev/page/path_concern.rb', line 66 def disable_spawn_redirection @disable_spawn_redirection = true end |
#path ⇒ Object
36 37 38 |
# File 'app/models/maglev/page/path_concern.rb', line 36 def path current_path.value end |
#path=(value) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/maglev/page/path_concern.rb', line 40 def path=(value) unless value.respond_to?(:each_pair) current_path.value = value return end value.each_pair do |locale, new_path| Maglev::I18n.with_locale(locale) { self.path = new_path } end end |
#path_hash ⇒ Object
62 63 64 |
# File 'app/models/maglev/page/path_concern.rb', line 62 def path_hash canonical_path_hash.transform_values(&:value) end |
#spawn_redirection_disabled? ⇒ Boolean
70 71 72 |
# File 'app/models/maglev/page/path_concern.rb', line 70 def spawn_redirection_disabled? !!@disable_spawn_redirection end |