Sha256: f53826660109b3e17bcfe2dd91a1d5495befd1bac5b707c8d5c56b73f9edb5e4

Contents?: true

Size: 1.69 KB

Versions: 3

Compression:

Stored size: 1.69 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)
                exit
              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
                session.logger.info("There are no people with account... aborting script")
                exit
              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.account.default_tag = session.tagtree.default_tag(*person.account.filter_tags)
                update.add(person)
              end

            end
          end

        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
eco-helpers-0.9.5 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.9.4 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.9.3 lib/eco/api/usecases/default_cases/set_default_tag_case.rb