Sha256: 1117229c6c2a8db37c673444308379cc44300db5c8a51a802ff0afd5503115d8
Contents?: true
Size: 1.86 KB
Versions: 21
Compression:
Stored size: 1.86 KB
Contents
module Eco module API class UseCases class DefaultCases class SetDefaultTagCase < DefaultCase # 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 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.account_present 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| if session.tagtree person.account.default_tag = session.tagtree.default_tag(*person.filter_tags) else tags = person.filter_tags || [] person.account.default_tag = tags.first unless tags.length > 1 end update.add(person) end end end end end end end end
Version data entries
21 entries across 21 versions & 1 rubygems