Sha256: a1f4c8f4b382ad669c1ebc8c13ca7f486ccb5ead1398a8dc681afc85bcef8b8c

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 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!(session)
    users    = users_present!(people, session)
    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!(session)
    if !session.tagtree
      msg = "There is no tagtree definition in the configuration files\n" +
            "For this usecase to work out you need to define it."
      session.logger.fatal(msg)
      raise msg
    end
  end

  def users_present!(people, session)
    people.users.tap do |users|
      unless users.length > 0
        session.logger.info(msg = "There are no people with account... aborting script")
        raise msg
      end
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
eco-helpers-2.6.4 lib/eco/api/usecases/default/people/set_default_tag_case.rb
eco-helpers-2.6.3 lib/eco/api/usecases/default/people/set_default_tag_case.rb
eco-helpers-2.6.2 lib/eco/api/usecases/default/people/set_default_tag_case.rb
eco-helpers-2.6.1 lib/eco/api/usecases/default/people/set_default_tag_case.rb
eco-helpers-2.6.0 lib/eco/api/usecases/default/people/set_default_tag_case.rb