Class: Docks::Containers::Pattern
- Inherits:
-
Base
- Object
- Base
- Docks::Containers::Pattern
show all
- Extended by:
- Forwardable
- Defined in:
- lib/docks/containers/pattern_container.rb
Constant Summary
collapse
- SYMBOL_SOURCES =
[
Types::Languages::STYLE,
Types::Languages::SCRIPT
]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#[], #[]=, #delete, #fetch, #method_missing, #respond_to?, #summarized?, #tags, #to_h, #update
Constructor Details
#initialize(pattern_details = {}) ⇒ Pattern
Returns a new instance of Pattern.
18
19
20
21
22
23
24
25
26
27
|
# 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
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Docks::Containers::Base
Instance Attribute Details
#files ⇒ Object
Returns the value of attribute files.
15
16
17
|
# File 'lib/docks/containers/pattern_container.rb', line 15
def files
@files
end
|
#modified ⇒ Object
Returns the value of attribute modified.
15
16
17
|
# File 'lib/docks/containers/pattern_container.rb', line 15
def modified
@modified
end
|
#name ⇒ Object
Returns the value of attribute name.
15
16
17
|
# File 'lib/docks/containers/pattern_container.rb', line 15
def name
@name
end
|
Class Method Details
.type ⇒ Object
8
|
# File 'lib/docks/containers/pattern_container.rb', line 8
def self.type; Types::Symbol::PATTERN end
|
Instance Method Details
#==(other_pattern) ⇒ Object
56
57
58
|
# 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) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# 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 ⇒ Object
Also known as:
script_symbols
78
79
80
|
# File 'lib/docks/containers/pattern_container.rb', line 78
def behavior_symbols
@symbols[Types::Languages::SCRIPT]
end
|
#demos ⇒ Object
Also known as:
demo
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# 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
|
#find(descriptor) ⇒ Object
98
99
100
|
# File 'lib/docks/containers/pattern_container.rb', line 98
def find(descriptor)
super || find_in_symbols(descriptor)
end
|
#group ⇒ Object
64
65
66
|
# File 'lib/docks/containers/pattern_container.rb', line 64
def group
fetch(Tags::Group.instance.name, Types::Symbol::COMPONENT.capitalize)
end
|
#has_behavior? ⇒ Boolean
84
85
86
|
# File 'lib/docks/containers/pattern_container.rb', line 84
def has_behavior?
behavior_symbols.length > 0
end
|
#has_structure? ⇒ Boolean
74
75
76
|
# File 'lib/docks/containers/pattern_container.rb', line 74
def has_structure?
structure_symbols.length > 0
end
|
#remove(remove_symbol) ⇒ Object
46
47
48
49
50
|
# 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 ⇒ Object
Also known as:
style_symbols
68
69
70
|
# File 'lib/docks/containers/pattern_container.rb', line 68
def structure_symbols
@symbols[Types::Languages::STYLE]
end
|
#summary ⇒ Object
119
120
121
122
123
124
125
126
127
|
# 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 ⇒ Object
94
95
96
|
# File 'lib/docks/containers/pattern_container.rb', line 94
def symbols
@symbols.values.flatten
end
|
#symbols_of_type(type, options = {}) ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# 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 ⇒ Object
60
61
62
|
# File 'lib/docks/containers/pattern_container.rb', line 60
def title
fetch(Tags::Title.instance.name, name.capitalize)
end
|
#valid? ⇒ Boolean
52
53
54
|
# File 'lib/docks/containers/pattern_container.rb', line 52
def valid?
!@details.values.compact.empty? || SYMBOL_SOURCES.any? { |source| !@symbols[source].empty? }
end
|