Module: Eco::API::MicroCases::People::Manage::Load
- Included in:
- Eco::API::MicroCases::People::Manage
- Defined in:
- lib/eco/api/microcases/people/manage/load.rb
Instance Method Summary collapse
-
#people_load(filename = enviro.config.people.cache, modifier: %i[newest api])) ⇒ Eco::API::Organization::People
Helper to load
Peoplethat works in different phases: 1.
Instance Method Details
#people_load(filename = enviro.config.people.cache, modifier: %i[newest api])) ⇒ Eco::API::Organization::People
Note:
filenamewill be relative to the working directory (the one of the sessionenviroset by the user).
Helper to load People that works in different phases:
- first tries to get the newest cached file that follows
filenamepattern- if not the newest, it tries to find the specific filename
- if it succeeds to identify a cached file, it loads it
- if it fails, it tries to get people from the server
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/eco/api/microcases/people/manage/load.rb', line 21 def people_load(filename = enviro.config.people.cache, modifier: %i[newest api]) # rubocop:disable Metrics/AbcSize modifier = [modifier].flatten load_file = %i[file newest].any? {|flag| modifier.include?(flag)} if filename && load_file load_cache(filename, newest: modifier.include?(:newest)).tap do |people| next if people.is_a?(Eco::API::Organization::People) log(:error) { "could not find the file #{file_manager.dir.file(filename)}" } exit unless modifier.include?(:api) people_load(modifier: modifier - %i[newest file]) end elsif modifier.include?(:api) people_cache(filename, modifier: modifier) end.then do |people| Eco::API::Organization::People.new(people.to_a) end end |