Sha256: 2df80a0da2456bb36e2338e8118a43b34681297aaae8540642428ac19ea80caa

Contents?: true

Size: 1.94 KB

Versions: 6

Compression:

Stored size: 1.94 KB

Contents

MAX_GET_PARTIAL = 12_000

ASSETS.cli.config do |cnf|
  cnf.people do |input, session, options|
    get         = options.dig(:people, :get)
    get         = {} if get.nil?

    from_remote = get && get[:from] == :remote
    from_local  = get && get[:from] == :local

    get_full    = from_remote && get[:type] == :full
    get_partial = from_remote && get[:type] == :partial
    get_by_file = from_local  && get[:type] == :file

    # -get-partial: validate input present and under max
    if get_partial
      msg = "To use -get-partial (partial updates), you need to use -entries-from"
      raise msg unless input.is_a?(Enumerable)

      if input.count > MAX_GET_PARTIAL
        get_full    = true
        get_partial = false

        msg  = "(Optimization) "
        msg << "Switching from partial to full people download. "
        msg << "Input (#{input.count}) surpases MAX_GET_PARTIAL "
        msg << "(#{MAX_GET_PARTIAL}) entries."
        session.log(:info) { msg }

        options.deep_merge!(people: {
          get: {
            from: :remote,
            type: :full
          }
        })
      end
    end

    if get == false
      Eco::API::Organization::People.new([])
    elsif get_full
      # -get-people
      session.micro.people_cache
    elsif get_partial
      # -get-partial
      session.micro.people_search(input, options: options)
    elsif get_by_file
      # -people-from-backup
      session.micro.people_load(get[:file], modifier: :file)
    else
      options.deep_merge!(people: {
        get: {
          from: :local,
          type: :full
        }
      })

      people = session.micro.people_load(modifier: %i[newest save])

      if people.empty?
        options.deep_merge!(people: {
          get: {
            from: :remote,
            type: :full
          }
        })
        people = session.micro.people_cache
      end

      people
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
eco-helpers-3.0.20 lib/eco/cli_default/people.rb
eco-helpers-3.0.19 lib/eco/cli_default/people.rb
eco-helpers-3.0.18 lib/eco/cli_default/people.rb
eco-helpers-3.0.17 lib/eco/cli_default/people.rb
eco-helpers-3.0.16 lib/eco/cli_default/people.rb
eco-helpers-3.0.15 lib/eco/cli_default/people.rb