Class: LcpRuby::Metadata::ViewGroupDefinition
- Inherits:
-
Object
- Object
- LcpRuby::Metadata::ViewGroupDefinition
- Defined in:
- lib/lcp_ruby/metadata/view_group_definition.rb
Constant Summary collapse
- VALID_SWITCHER_CONTEXTS =
%w[index show form].freeze
Instance Attribute Summary collapse
-
#breadcrumb_config ⇒ Object
readonly
Returns the value of attribute breadcrumb_config.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#navigation_config ⇒ Object
readonly
Returns the value of attribute navigation_config.
-
#primary_page ⇒ Object
readonly
Returns the value of attribute primary_page.
-
#public ⇒ Object
(also: #public?)
readonly
Returns the value of attribute public.
-
#raw_hash ⇒ Object
readonly
Returns the value of attribute raw_hash.
-
#source_path ⇒ Object
Returns the value of attribute source_path.
-
#source_type ⇒ Object
Returns the value of attribute source_type.
-
#views ⇒ Object
readonly
Returns the value of attribute views.
Class Method Summary collapse
Instance Method Summary collapse
-
#auto_append? ⇒ Boolean
Returns false when navigation: { auto_append: false } is set.
- #breadcrumb_enabled? ⇒ Boolean
- #breadcrumb_relation ⇒ Object
-
#each_view_label ⇒ Object
i18n_check Phase 3a façade — yields per-view label literals for the lint walker (see docs/design/i18n_consistency_check.md §B “Façade method signatures”).
- #has_switcher? ⇒ Boolean
-
#initialize(attrs = {}) ⇒ ViewGroupDefinition
constructor
A new instance of ViewGroupDefinition.
-
#navigable? ⇒ Boolean
Returns false when navigation is explicitly disabled (navigation: false).
- #page_names ⇒ Object
- #primary_page?(page_name) ⇒ Boolean
- #show_switcher?(context) ⇒ Boolean
- #switcher_config ⇒ Object
- #view_for_page(page_name) ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ ViewGroupDefinition
Returns a new instance of ViewGroupDefinition.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 11 def initialize(attrs = {}) @name = attrs[:name].to_s @model = attrs[:model]&.to_s.presence @primary_page = attrs[:primary_page].to_s raw_nav = attrs.fetch(:navigation_config, {}) @navigation_config = raw_nav == false ? false : HashUtils.stringify_deep(raw_nav || {}) @views = (attrs[:views] || []).map { |v| HashUtils.stringify_deep(v) } @breadcrumb_config = (attrs[:breadcrumb_config]) @public = attrs[:public] == true @raw_hash = attrs[:raw_hash] @source_path = attrs[:source_path] @source_type = attrs[:source_type] @switcher = parse_switcher(attrs[:switcher_config]) @presenter_diff_cache = {} validate! end |
Instance Attribute Details
#breadcrumb_config ⇒ Object (readonly)
Returns the value of attribute breadcrumb_config.
6 7 8 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 6 def @breadcrumb_config end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
6 7 8 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 6 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 6 def name @name end |
#navigation_config ⇒ Object (readonly)
Returns the value of attribute navigation_config.
6 7 8 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 6 def @navigation_config end |
#primary_page ⇒ Object (readonly)
Returns the value of attribute primary_page.
6 7 8 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 6 def primary_page @primary_page end |
#public ⇒ Object (readonly) Also known as: public?
Returns the value of attribute public.
6 7 8 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 6 def public @public end |
#raw_hash ⇒ Object (readonly)
Returns the value of attribute raw_hash.
6 7 8 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 6 def raw_hash @raw_hash end |
#source_path ⇒ Object
Returns the value of attribute source_path.
6 7 8 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 6 def source_path @source_path end |
#source_type ⇒ Object
Returns the value of attribute source_type.
6 7 8 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 6 def source_type @source_type end |
#views ⇒ Object (readonly)
Returns the value of attribute views.
6 7 8 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 6 def views @views end |
Class Method Details
.from_hash(hash) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 29 def self.from_hash(hash) data = hash["view_group"] || hash views = (data["views"] || []).map do |v| { "page" => (v["page"] || v["presenter"]).to_s, "label" => v["label"], "icon" => v["icon"], # Preserve source-location capture from DSL builder. Nil for # YAML-loaded view groups; consumed by `each_view_label` # (Phase 3a) and Pass 1 walker (Phase 3b). "_label_source_loc" => v["_label_source_loc"] }.compact end nav = data["navigation"] = nav == false ? false : (nav || {}) new( name: data["name"], model: data["model"], primary_page: data["primary"], navigation_config: , views: views, breadcrumb_config: data["breadcrumb"], public: data["public"], switcher_config: data["switcher"], raw_hash: data ) end |
Instance Method Details
#auto_append? ⇒ Boolean
Returns false when navigation: { auto_append: false } is set. The view group is still navigable (can be routed and referenced from menu.yml), but is skipped by Loader#auto_append_unreferenced_view_groups!. Used by infrastructure view groups (audit_logs, job_executions, etc.) to opt out of leaking into top menu by default.
126 127 128 129 130 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 126 def auto_append? return false unless navigable? return true unless .is_a?(Hash) ["auto_append"] != false end |
#breadcrumb_enabled? ⇒ Boolean
73 74 75 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 73 def @breadcrumb_config != false end |
#breadcrumb_relation ⇒ Object
77 78 79 80 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 77 def return nil unless @breadcrumb_config.is_a?(Hash) @breadcrumb_config["relation"] end |
#each_view_label ⇒ Object
i18n_check Phase 3a façade — yields per-view label literals for the lint walker (see docs/design/i18n_consistency_check.md §B “Façade method signatures”). YAML-loaded view groups yield ‘source: nil` and Pass 1 defers them to Pass 3 via that signal.
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 98 def each_view_label return enum_for(:each_view_label) unless block_given? views.each do |view| label = view["label"] next if label.nil? yield( label: label, page: view["page"], source: view["_label_source_loc"] ) end end |
#has_switcher? ⇒ Boolean
111 112 113 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 111 def has_switcher? views.length > 1 && @switcher != false end |
#navigable? ⇒ Boolean
Returns false when navigation is explicitly disabled (navigation: false). Used to exclude view groups from auto-generated navigation menus.
117 118 119 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 117 def navigable? != false end |
#page_names ⇒ Object
82 83 84 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 82 def page_names @page_names ||= views.map { |v| v["page"] }.freeze end |
#primary_page?(page_name) ⇒ Boolean
86 87 88 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 86 def primary_page?(page_name) primary_page == page_name.to_s end |
#show_switcher?(context) ⇒ Boolean
63 64 65 66 67 68 69 70 71 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 63 def show_switcher?(context) return false if views.length < 2 return false if @switcher == false case @switcher when Array then @switcher.include?(context.to_s) else presenters_differ_on?(context.to_s) end end |
#switcher_config ⇒ Object
59 60 61 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 59 def switcher_config @switcher end |
#view_for_page(page_name) ⇒ Object
90 91 92 |
# File 'lib/lcp_ruby/metadata/view_group_definition.rb', line 90 def view_for_page(page_name) views.find { |v| v["page"] == page_name.to_s } end |