Sha256: a0a60272a6975e5498a29018a1a8edfd85868d7e4821f763b4b3d1ecb9ecf4b1

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

class Eco::API::UseCases::Default::People::SetDefaultTagCase < Eco::API::Common::Loaders::UseCase
  name "set-default-tag"
  type :transform

  # take the deepest tag (the one that is further down in the tree)
  # different options (several nodes at the same depth):
  # => take the common node between them (i.e. you have Hamilton and Auckland -> take New Zealand)
  # => if there's no common node between them, take the `first` (unless they are at top level of the tree)
  def main(people, session, options, usecase)
    tagtree_present!
    users  = users_present!
    update = session.new_job("main", "update", :update, usecase, :account)

    users.each do |person|
      micro.refresh_default_tag(nil, person, options)
      update.add(person)
    end
  end

  private

  def tagtree_present!
    return unless tagtree?

    msg  = "There is no locs struct defined. Aborting..."
    logger.fatal(msg)
    raise msg
  end

  def users_present!
    people.users.tap do |users|
      next if users.length.positive?

      msg = "There are no people with account... aborting script"
      log(:error) { msg }
      raise msg
    end
  end

  def tagtree?
    return false unless (tree = session.tagtree)
    !tree.empty?
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
eco-helpers-2.7.2 lib/eco/api/usecases/default/people/set_default_tag_case.rb
eco-helpers-2.7.1 lib/eco/api/usecases/default/people/set_default_tag_case.rb
eco-helpers-2.7.0 lib/eco/api/usecases/default/people/set_default_tag_case.rb