class ActionBlocks::WorkspaceBuilder

Public Instance Methods

before_build(parent, *args) click to toggle source
# File lib/action_blocks/builders/workspace_builder.rb, line 33
def before_build(parent, *args)
  @title = args[0].to_s.titleize
end
dashboard_paths() click to toggle source
# 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) click to toggle source
# File lib/action_blocks/builders/workspace_builder.rb, line 98
def hashify(user)
  {
    # key: key,
    title: @title,
    id: @id,
    subspaces: @subspaces.map { |ss| ss.hashify(user) },
    subspace_categories: hashify_subspace_categories(user),
    model_paths: model_paths
    # record_paths: @record_paths.map { |rp| rp.hashify(user) }
  }
end
hashify_subspace_categories(user) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/action_blocks/builders/workspace_builder.rb, line 37
def subspace_categories
  @subspaces.map(&:category).uniq
end
subspace_paths() click to toggle source
# 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