Class: Cms::EngineAwarePathBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/cms/engine_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_class_or_content_type_or_model) ⇒ EngineAwarePathBuilder

Returns a new instance of EngineAwarePathBuilder.



8
9
10
# File 'lib/cms/engine_helper.rb', line 8

def initialize(model_class_or_content_type_or_model)
  normalize_subject_class(model_class_or_content_type_or_model)
end

Instance Attribute Details

#path_subjectObject (readonly)

Returns the value of attribute path_subject.



6
7
8
# File 'lib/cms/engine_helper.rb', line 6

def path_subject
  @path_subject
end

Instance Method Details

#build(view) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/cms/engine_helper.rb', line 27

def build(view)
  path = []
  path << engine(view)
  path << path_subject
  path

end

#build_preview(view) ⇒ Object



20
21
22
23
24
25
# File 'lib/cms/engine_helper.rb', line 20

def build_preview(view)
  path = []
  path << engine_name
  path << path_subject
  path
end

#engine_classObject



55
56
57
58
59
60
61
# File 'lib/cms/engine_helper.rb', line 55

def engine_class
  if main_app_model?
    Rails.application
  else
    guess_engine_class(subject_class)
  end
end

#engine_nameObject

Determine which ‘Engine’ this model is from based on the class



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cms/engine_helper.rb', line 40

def engine_name
  model_class = subject_class.model_name
  name = EngineAware.module_name(model_class)
  return "main_app" unless name

  begin
    engine = "#{name}::Engine".constantize
  rescue NameError
    # This means there is no Engine for this model, so its from the main Rails App.
    return "main_app"
  end
  engine.engine_name
end

#main_app_model?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/cms/engine_helper.rb', line 35

def main_app_model?
  engine_name == "main_app"
end

#subject_classObject



12
13
14
15
16
17
18
# File 'lib/cms/engine_helper.rb', line 12

def subject_class
  if path_subject.instance_of?(Class)
    path_subject
  else
    path_subject.class
  end
end