Class: Eco::API::UseCases::DefaultCases::SetDefaultTagCase

Inherits:
Eco::API::UseCases::DefaultCase show all
Defined in:
lib/eco/api/usecases/default_cases/set_default_tag_case.rb

Instance Method Summary collapse

Methods inherited from Eco::API::UseCases::DefaultCase

#initialize

Constructor Details

This class inherits a constructor from Eco::API::UseCases::DefaultCase

Instance Method Details

#processObject

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)



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/eco/api/usecases/default_cases/set_default_tag_case.rb', line 11

def process
  @cases.define("set-default-tag", type: :transform) do |people, session, options, usecase|
    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

    # IMPORTANT: this two lines ensure that only people to be updated is selected
    all_people = people
    people = people.

    if people.length <= 0
      msg = "There are no people with account... aborting script"
      session.logger.info(msg)
      raise msg
    end

    update   = session.job_group("main").new("update", usecase: usecase, type: :update, sets: :account)

    people.each_with_index  do |person, i|
      #next unless person.id == "5c527ba63f7690001243f5b2"
      person..default_tag = session.tagtree.default_tag(*person.filter_tags)
      update.add(person)
    end

  end
end