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



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_pathObject



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_pathObject



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_redirectionObject



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

def disable_spawn_redirection
  @disable_spawn_redirection = true
end

#pathObject



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_hashObject



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

Returns:

  • (Boolean)


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

def spawn_redirection_disabled?
  !!@disable_spawn_redirection
end