Class: OodAppkit::ClusterDecorator
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- OodAppkit::ClusterDecorator
- Defined in:
- lib/ood_appkit/cluster_decorator.rb
Overview
A decorator that adds a presentation layer to the OodCluster::Cluster object
Instance Attribute Summary collapse
-
#id ⇒ Symbol
readonly
The identifier used as the key in the OodAppkit clusters hash (used for reverse searching).
-
#title ⇒ String
readonly
The title used to describe this cluster to users.
-
#url ⇒ String
readonly
The URL for this cluster that users can use to view more information.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
The comparison operator.
-
#initialize(cluster:, id:, title: "", url: "", validators: {}, **_) ⇒ ClusterDecorator
constructor
A new instance of ClusterDecorator.
-
#valid?(method = :cluster) ⇒ Boolean
Whether the given method is valid (i.e., passes all supplied validators).
Constructor Details
#initialize(cluster:, id:, title: "", url: "", validators: {}, **_) ⇒ ClusterDecorator
Returns a new instance of ClusterDecorator.
24 25 26 27 28 29 30 |
# File 'lib/ood_appkit/cluster_decorator.rb', line 24 def initialize(cluster:, id:, title: "", url: "", validators: {}, **_) super(cluster) @id = id.to_sym @title = title.to_s @url = url.to_s @validators = validators.each_with_object({}) { |(k, v), h| h[k.to_sym] = v } end |
Instance Attribute Details
#id ⇒ Symbol (readonly)
The identifier used as the key in the OodAppkit clusters hash (used for reverse searching)
9 10 11 |
# File 'lib/ood_appkit/cluster_decorator.rb', line 9 def id @id end |
#title ⇒ String (readonly)
The title used to describe this cluster to users
13 14 15 |
# File 'lib/ood_appkit/cluster_decorator.rb', line 13 def title @title end |
#url ⇒ String (readonly)
The URL for this cluster that users can use to view more information
17 18 19 |
# File 'lib/ood_appkit/cluster_decorator.rb', line 17 def url @url end |
Instance Method Details
#==(other) ⇒ Boolean
The comparison operator
42 43 44 |
# File 'lib/ood_appkit/cluster_decorator.rb', line 42 def ==(other) id == other.to_sym end |
#valid?(method = :cluster) ⇒ Boolean
Whether the given method is valid (i.e., passes all supplied validators)
35 36 37 |
# File 'lib/ood_appkit/cluster_decorator.rb', line 35 def valid?(method = :cluster) @validators.fetch(method.to_sym, []).all? { |v| v.success? } end |