Sha256: 1b3b190bc110683c7445adcf12c1a3b3be806c007c05d0c8e52058beda32c848

Contents?: true

Size: 1.68 KB

Versions: 12

Compression:

Stored size: 1.68 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.filter_tags)
                update.add(person)
              end

            end
          end

        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
eco-helpers-1.0.13 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.0.12 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.0.11 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.0.10 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.0.9 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.0.8 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.0.7 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.0.6 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.0.5 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.0.4 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.0.3 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.0.2 lib/eco/api/usecases/default_cases/set_default_tag_case.rb