Sha256: b20bd187aadfb450a6917def16ba4ab5bd42e4954ad288fdd8cfb7b4ef5a0aa3

Contents?: true

Size: 1.26 KB

Versions: 17

Compression:

Stored size: 1.26 KB

Contents

class Eco::API::UseCases::Default::People::Utils::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..."
    log(: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

17 entries across 17 versions & 1 rubygems

Version Path
eco-helpers-3.0.21 lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb
eco-helpers-3.0.20 lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb
eco-helpers-3.0.19 lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb
eco-helpers-3.0.18 lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb
eco-helpers-3.0.17 lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb
eco-helpers-3.0.16 lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb
eco-helpers-3.0.15 lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb
eco-helpers-3.0.14 lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb
eco-helpers-3.0.13 lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb
eco-helpers-3.0.12 lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb
eco-helpers-3.0.11 lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb
eco-helpers-3.0.10 lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb
eco-helpers-3.0.9 lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb
eco-helpers-3.0.8 lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb
eco-helpers-3.0.7 lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb
eco-helpers-3.0.6 lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb
eco-helpers-3.0.5 lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb