Class: ActionBlocks::WorkspaceBuilder
- Inherits:
-
BlockType
show all
- Defined in:
- lib/action_blocks/builders/workspace_builder.rb
Instance Attribute Summary
Attributes inherited from BaseBuilder
#dsl_delegate, #id
Instance Method Summary
collapse
Methods inherited from BlockType
#is_block?, #type
Methods inherited from BaseBuilder
#after_build, #after_load, array_fields, block_type, builds, builds_many, delegate_class, #evaluate, #freeze, includes_scheme_helpers, #initialize, #is_block?, #key, references, sets, sets_many, #ui_reference, #valid?
Instance Method Details
#before_build(parent, *args) ⇒ Object
33
34
35
|
# File 'lib/action_blocks/builders/workspace_builder.rb', line 33
def before_build(parent, *args)
@title = args[0].to_s.titleize
end
|
#dashboard_paths ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/action_blocks/builders/workspace_builder.rb', line 60
def dashboard_paths
paths = {}
@subspaces.each do |ss|
if ss.model_key
ss.dashboards.each do |ds|
paths[ds.model_key] = {
path_type: :dashboard,
subspace_category: ss.category,
subspace_model: ss.model_key,
subspace_key: ss.key,
dashboard_category: ds.category,
dashboard_model: ds.model_key,
dashboard_key: ds.key
}
end
end
end
return paths
end
|
#hashify(user) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/action_blocks/builders/workspace_builder.rb', line 98
def hashify(user)
{
title: @title,
id: @id,
subspaces: @subspaces.map { |ss| ss.hashify(user) },
subspace_categories: hashify_subspace_categories(user),
model_paths: model_paths
}
end
|
#hashify_subspace_categories(user) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/action_blocks/builders/workspace_builder.rb', line 80
def hashify_subspace_categories(user)
isFirst = true
results = []
subspace_categories.each do |category|
results << {
first: isFirst,
type: 'subspace_category',
category: category,
title: category.to_s.titleize,
subspaces: @subspaces.
select {|ss| ss.category == category}.
map { |ss| ss.hashify(user) },
}
isFirst = false
end
return results
end
|
#model_paths ⇒ Object
41
42
43
|
# File 'lib/action_blocks/builders/workspace_builder.rb', line 41
def model_paths
subspace_paths.merge(dashboard_paths)
end
|
#one_non_model_subspace_per_category ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/action_blocks/builders/workspace_builder.rb', line 12
def one_non_model_subspace_per_category
subspace_categories.each do |sc|
if @subspaces.
select {|ss| ss.category == sc && ss.model_key.nil? }.count > 1
errors.add(:subspaces, "Subspace category #{sc.to_s} has more than one non-modeled subspace")
end
end
end
|
#one_route_per_model ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/action_blocks/builders/workspace_builder.rb', line 21
def one_route_per_model
models = subspaces.map {|ss| ss.model_key}.compact
subspaces.each do |ss|
models += ss.dashboards.map {|ss| ss.model_key}.compact
end
models.uniq.each do |model|
if models.select {|m| model == m}.count > 1
errors.add(:subspaces, "More than one subspace or dashboard uses model #{model}")
end
end
end
|
#subspace_categories ⇒ Object
37
38
39
|
# File 'lib/action_blocks/builders/workspace_builder.rb', line 37
def subspace_categories
@subspaces.map(&:category).uniq
end
|
#subspace_paths ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/action_blocks/builders/workspace_builder.rb', line 45
def subspace_paths
paths = {}
@subspaces.each do |ss|
if ss.model_key
paths[ss.model_key] = {
path_type: :subspace,
subspace_category: ss.category,
subspace_model: ss.model_key,
subspace_key: ss.key
}
end
end
return paths
end
|