Class: Foobara::CommandConnectors::Http::Commands::Help::Presenter

Inherits:
Object
  • Object
show all
Defined in:
foobara-http-command-connector-0.0.23/src/http/commands/help/presenter.rb,
foobara-http-command-connector-0.0.23/src/http/commands/help/presenter/root.rb,
foobara-http-command-connector-0.0.23/src/http/commands/help/presenter/type.rb,
foobara-http-command-connector-0.0.23/src/http/commands/help/presenter/error.rb,
foobara-http-command-connector-0.0.23/src/http/commands/help/presenter/model.rb,
foobara-http-command-connector-0.0.23/src/http/commands/help/presenter/domain.rb,
foobara-http-command-connector-0.0.23/src/http/commands/help/presenter/entity.rb,
foobara-http-command-connector-0.0.23/src/http/commands/help/presenter/command.rb,
foobara-http-command-connector-0.0.23/src/http/commands/help/presenter/processor.rb,
foobara-http-command-connector-0.0.23/src/http/commands/help/presenter/organization.rb,
foobara-http-command-connector-0.0.23/src/http/commands/help/presenter/request_failed.rb,
foobara-http-command-connector-0.0.23/src/http/commands/help/presenter/processor_class.rb

Defined Under Namespace

Classes: Command, Domain, Entity, Error, Model, Organization, Processor, ProcessorClass, RequestFailed, Root, Type

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manifest) ⇒ Presenter

Returns a new instance of Presenter.



69
70
71
# File 'foobara-http-command-connector-0.0.23/src/http/commands/help/presenter.rb', line 69

def initialize(manifest)
  self.manifest = manifest
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object



165
166
167
168
169
170
171
172
173
# File 'foobara-http-command-connector-0.0.23/src/http/commands/help/presenter.rb', line 165

def method_missing(method_name, *, &)
  if manifest.respond_to?(method_name)
    manifest.send(method_name, *, &)
  else
    # :nocov:
    super
    # :nocov:
  end
end

Instance Attribute Details

#manifestObject

Returns the value of attribute manifest.



67
68
69
# File 'foobara-http-command-connector-0.0.23/src/http/commands/help/presenter.rb', line 67

def manifest
  @manifest
end

Class Method Details

.for(manifest) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'foobara-http-command-connector-0.0.23/src/http/commands/help/presenter.rb', line 21

def for(manifest)
  case manifest
  when Manifest::RootManifest
    Presenter::Root
  when Manifest::Command
    Presenter::Command
    # TODO: do we need a dedicated presenter for this??
  when Manifest::Entity, Manifest::DetachedEntity
    Presenter::Entity
  when Manifest::Model
    Presenter::Model
  when Manifest::Type
    Presenter::Type
  when Manifest::Error
    Presenter::Error
  when Manifest::Domain
    Presenter::Domain
  when Manifest::Organization
    Presenter::Organization
  when Manifest::Processor
    Presenter::Processor
  when Manifest::ProcessorClass
    Presenter::ProcessorClass
  when ErrorCollection
    Presenter::RequestFailed
  else
    # :nocov:
    raise "No presenter found for #{manifest.path}"
    # :nocov:
  end.new(manifest)
end

.template_pathObject



57
58
59
60
61
62
63
64
# File 'foobara-http-command-connector-0.0.23/src/http/commands/help/presenter.rb', line 57

def template_path
  template_path = File.join(
    __dir__,
    "templates",
    "#{template_symbol}.html.erb"
  )
  Pathname.new(template_path).cleanpath.to_s
end

.template_symbolObject



53
54
55
# File 'foobara-http-command-connector-0.0.23/src/http/commands/help/presenter.rb', line 53

def template_symbol
  Util.underscore(Util.non_full_name(self))
end

Instance Method Details



151
152
153
154
155
# File 'foobara-http-command-connector-0.0.23/src/http/commands/help/presenter.rb', line 151

def foobara_reference_link(manifest)
  path = "/help/#{manifest.reference}"

  "<a href=\"#{path}\">#{manifest.reference.split("::").last}</a>"
end

#render_html_list(data, skip_wrapper: false) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'foobara-http-command-connector-0.0.23/src/http/commands/help/presenter.rb', line 73

def render_html_list(data, skip_wrapper: false)
  html = ""

  case data
  when ::Hash
    html << "<ul>" unless skip_wrapper
    data.each do |key, value|
      html << "<li>#{key}"
      html << "<ul>"
      html << render_html_list(value, skip_wrapper: true)
      html << "</ul>"
      html << "</li>"
    end
    html << "</ul>" unless skip_wrapper
  when ::Array
    html << "<ul>" unless skip_wrapper
    data.each do |item|
      html << render_html_list(item)
    end
    html << "</ul>" unless skip_wrapper
  when Manifest::Attributes
    html << "<ul>" unless skip_wrapper
    data.relevant_manifest.each_pair do |key, value|
      if key.to_s == "type"
        next
      end

      if key.to_s == "element_type_declarations"
        key = :attributes
        value = data.attribute_declarations
      end
      html << "<li>#{key}"
      html << "<ul>"
      html << render_html_list(value, skip_wrapper: true)
      html << "</ul>"
      html << "</li>"
    end
    html << "</ul>" unless skip_wrapper
  when Manifest::Array
    html << "<ul>" unless skip_wrapper
    data.relevant_manifest.each_pair do |key, value|
      next if key == :element_type_declaration

      if key.to_s == "type"
        value = root_manifest.lookup_path(key, value)
      end
      html << "<li>#{key}"
      html << "<ul>"
      html << render_html_list(value, skip_wrapper: true)
      html << "</ul>"
      html << "</li>"
    end
    html << render_html_list({ element_type: data.element_type }, skip_wrapper: true)
    html << "</ul>" unless skip_wrapper
  when Manifest::TypeDeclaration
    html << "<ul>" unless skip_wrapper
    data.relevant_manifest.each_pair do |key, value|
      if key.to_s == "type"
        value = root_manifest.lookup_path(key, value)
      end
      html << "<li>#{key}"
      html << "<ul>"
      html << render_html_list(value, skip_wrapper: true)
      html << "</ul>"
      html << "</li>"
    end
    html << "</ul>" unless skip_wrapper
  when Manifest::Type, Manifest::Command, Manifest::Error
    html << foobara_reference_link(data)
  when Manifest::PossibleError
    html << render_html_list(data.error)
  else
    html << "<li>#{data}</li>"
  end

  html
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


175
176
177
178
179
# File 'foobara-http-command-connector-0.0.23/src/http/commands/help/presenter.rb', line 175

def respond_to_missing?(method_name, include_private = false)
  # :nocov:
  manifest.respond_to?(method_name, include_private)
  # :nocov:
end

#root_manifestObject



157
158
159
# File 'foobara-http-command-connector-0.0.23/src/http/commands/help/presenter.rb', line 157

def root_manifest
  @root_manifest ||= Manifest::RootManifest.new(manifest.root_manifest)
end

#template_pathObject



161
162
163
# File 'foobara-http-command-connector-0.0.23/src/http/commands/help/presenter.rb', line 161

def template_path
  self.class.template_path
end