Class: Docks::Containers::Component
- Defined in:
- lib/docks/containers/component_container.rb
Overview
Public: a container for Component symbols.
Instance Attribute Summary
Attributes inherited from Symbol
#belongs_to, #methods, #properties
Class Method Summary collapse
-
.type ⇒ Object
Public: the type of symbols that should be encapsulated by this container.
Instance Method Summary collapse
- #find(descriptor) ⇒ Object
- #has_demo? ⇒ Boolean
-
#initialize(component_hash = {}) ⇒ Component
constructor
A new instance of Component.
- #subcomponents(options = {}, &block) ⇒ Object (also: #subcomponent)
- #summary ⇒ Object
- #variations(&block) ⇒ Object
Methods inherited from Symbol
#add_member, #add_members, from_symbol, #has_members?, #member?, #members, #private?, #public?, #symbol_id, #to_descriptor
Methods inherited from Base
#==, #[], #[]=, #delete, #fetch, #method_missing, #respond_to?, #summarized?, #tags, #to_h, #update
Constructor Details
#initialize(component_hash = {}) ⇒ Component
Returns a new instance of Component.
18 19 20 21 22 23 24 25 |
# File 'lib/docks/containers/component_container.rb', line 18 def initialize(component_hash = {}) super self[:states] ||= [] self[:variants] ||= [] self[:subcomponents] ||= [] self[:included_symbols] ||= [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Docks::Containers::Base
Class Method Details
.type ⇒ Object
Public: the type of symbols that should be encapsulated by this container. This is compared against a symbol’s ‘symbol_type` to determine which container to use.
Returns the type String.
16 |
# File 'lib/docks/containers/component_container.rb', line 16 def self.type; Docks::Types::Symbol::COMPONENT end |
Instance Method Details
#find(descriptor) ⇒ Object
48 49 50 |
# File 'lib/docks/containers/component_container.rb', line 48 def find(descriptor) super || find_in_members(descriptor) end |
#has_demo? ⇒ Boolean
39 40 41 |
# File 'lib/docks/containers/component_container.rb', line 39 def has_demo? !((markup || "") + (helper || "")).empty? end |
#subcomponents(options = {}, &block) ⇒ Object Also known as: subcomponent
27 28 29 30 31 32 33 34 35 |
# File 'lib/docks/containers/component_container.rb', line 27 def subcomponents( = {}, &block) subcomponents = if .fetch(:recursive, false) recursive_subcomponents else self[:subcomponents] end block_given? ? subcomponents.each(&block) : subcomponents end |
#summary ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/docks/containers/component_container.rb', line 52 def summary summary = super [:states, :variants, :subcomponents].each do |property| summary[property] = fetch(property, []).map(&:summary) end summary end |
#variations(&block) ⇒ Object
43 44 45 46 |
# File 'lib/docks/containers/component_container.rb', line 43 def variations(&block) variations = states + variants block_given? ? variations.each(&block) : variations end |