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

Instance Method Details

#canonical_path_hashObject



55
56
57
58
59
# File 'app/models/maglev/page/path_concern.rb', line 55

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_pathObject



50
51
52
53
# File 'app/models/maglev/page/path_concern.rb', line 50

def current_path
  locale = Maglev::I18n.current_locale
  canonical_path_hash[locale] ||= paths.build(locale: locale, canonical: true)
end

#default_pathObject



31
32
33
# File 'app/models/maglev/page/path_concern.rb', line 31

def default_path
  @default_path ||= path_hash[Maglev::I18n.default_locale]
end

#disable_spawn_redirectionObject



65
66
67
# File 'app/models/maglev/page/path_concern.rb', line 65

def disable_spawn_redirection
  @disable_spawn_redirection = true
end

#pathObject



35
36
37
# File 'app/models/maglev/page/path_concern.rb', line 35

def path
  current_path.value
end

#path=(value) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'app/models/maglev/page/path_concern.rb', line 39

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_hashObject



61
62
63
# File 'app/models/maglev/page/path_concern.rb', line 61

def path_hash
  canonical_path_hash.transform_values(&:value)
end

#spawn_redirection_disabled?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/models/maglev/page/path_concern.rb', line 69

def spawn_redirection_disabled?
  !!@disable_spawn_redirection
end