class Docks::Containers::Pattern
Constants
- SYMBOL_SOURCES
Attributes
files[RW]
modified[RW]
name[RW]
Public Class Methods
new(pattern_details = {})
click to toggle source
Calls superclass method
Docks::Containers::Base::new
# File lib/docks/containers/pattern_container.rb, line 18 def initialize(pattern_details = {}) super @name = @details.delete(:name) @symbols = {} @files = [] SYMBOL_SOURCES.each do |source| @symbols[source] = [] end end
type()
click to toggle source
# File lib/docks/containers/pattern_container.rb, line 8 def self.type; Types::Symbol::PATTERN end
Public Instance Methods
==(other_pattern)
click to toggle source
# File lib/docks/containers/pattern_container.rb, line 56 def ==(other_pattern) self.class == other_pattern.class && @symbols == other_pattern.instance_variable_get(:@symbols) end
add(source, symbols)
click to toggle source
# File lib/docks/containers/pattern_container.rb, line 29 def add(source, symbols) symbols = [symbols].flatten symbols.each do |symbol| symbol.belongs_to = self end pattern_symbol, regular_symbols = symbols.partition { |symbol| !symbol.pattern.nil? } unless pattern_symbol.empty? pattern_symbol = pattern_symbol.first pattern_symbol[Tags::Title.instance.name] ||= pattern_symbol.delete(Tags::Pattern.instance.name) @details.merge!(pattern_symbol.to_h) end @symbols[source].concat(regular_symbols) end
behavior_symbols()
click to toggle source
# File lib/docks/containers/pattern_container.rb, line 78 def behavior_symbols @symbols[Types::Languages::SCRIPT] end
Also aliased as: script_symbols
demos()
click to toggle source
# File lib/docks/containers/pattern_container.rb, line 102 def demos return @demos unless @demos.nil? @demos = [] components.each do |component| @demos << Demo.new(component) if component.has_demo? component.variations.each do |variation| @demos << Demo.new(variation) if variation.demo_type == Types::Demo::OWN end end @demos end
Also aliased as: demo
find(descriptor)
click to toggle source
Calls superclass method
Docks::Containers::Base#find
# File lib/docks/containers/pattern_container.rb, line 98 def find(descriptor) super || find_in_symbols(descriptor) end
group()
click to toggle source
# File lib/docks/containers/pattern_container.rb, line 64 def group fetch(Tags::Group.instance.name, Types::Symbol::COMPONENT.capitalize) end
has_behavior?()
click to toggle source
# File lib/docks/containers/pattern_container.rb, line 84 def has_behavior? behavior_symbols.length > 0 end
has_structure?()
click to toggle source
# File lib/docks/containers/pattern_container.rb, line 74 def has_structure? structure_symbols.length > 0 end
remove(remove_symbol)
click to toggle source
# File lib/docks/containers/pattern_container.rb, line 46 def remove(remove_symbol) SYMBOL_SOURCES.each do |symbol_source| @symbols[symbol_source].delete_if { |symbol| symbol == remove_symbol } end end
structure_symbols()
click to toggle source
# File lib/docks/containers/pattern_container.rb, line 68 def structure_symbols @symbols[Types::Languages::STYLE] end
Also aliased as: style_symbols
summary()
click to toggle source
Calls superclass method
Docks::Containers::Base#summary
# File lib/docks/containers/pattern_container.rb, line 119 def summary return self if summarized? summary = super summary.group = group summary.title = title summary.instance_variable_set(:@symbols, Hash[@symbols.map { |type, symbols| [type, symbols.map(&:summary)] }]) summary end
symbols()
click to toggle source
# File lib/docks/containers/pattern_container.rb, line 94 def symbols @symbols.values.flatten end
symbols_of_type(type, options = {})
click to toggle source
# File lib/docks/containers/pattern_container.rb, line 129 def symbols_of_type(type, options = {}) type = type.to_s included = options[:include].nil? ? SYMBOL_SOURCES : [options[:include]].flatten excluded = options[:exclude].nil? ? [] : Array(options[:exclude]) SYMBOL_SOURCES.inject([]) do |matches, source| if included.include?(source) && !excluded.include?(source) new_results = @symbols[source].select do |symbol| symbol.symbol_type.to_s == type end matches.concat(new_results) end matches end end
title()
click to toggle source
# File lib/docks/containers/pattern_container.rb, line 60 def title fetch(Tags::Title.instance.name, name.capitalize) end
valid?()
click to toggle source
# File lib/docks/containers/pattern_container.rb, line 52 def valid? !@details.values.compact.empty? || SYMBOL_SOURCES.any? { |source| !@symbols[source].empty? } end
Protected Instance Methods
find_in_symbols(descriptor)
click to toggle source
# File lib/docks/containers/pattern_container.rb, line 153 def find_in_symbols(descriptor) descriptor = Descriptor.new(descriptor) find_result = false SYMBOL_SOURCES.each do |source| @symbols[source].each do |symbol| find_result = symbol.find(descriptor) break if find_result end end find_result end
matches_exactly?(descriptor)
click to toggle source
# File lib/docks/containers/pattern_container.rb, line 149 def matches_exactly?(descriptor) descriptor.symbol.nil? && descriptor.pattern == name end