eco-helpers 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bca4917cf9f15ff3f6c758fae5e33713d3830cb7
4
- data.tar.gz: e5bf71ee72f3098292004c32af8a2897d6f7b5e9
3
+ metadata.gz: 85392e849cd1d52b3d418909563426dd5a0e85df
4
+ data.tar.gz: dca53525fdd42a7e8e8a3eeb6ebe402247f2f6df
5
5
  SHA512:
6
- metadata.gz: c7a90f27cc328d0be292f9618068d185c01fe020da49a4f343b5b40df51f2850f05625b8dab2e105f5cb6c206d4cd6188b14d8f2d297d9198221b592beffabe9
7
- data.tar.gz: 91b9c265e0212b2662ac962b9102fff5ba82cbcd3301032430a864b847e4db8f94118cc7fa5af416bcf2153c4c42a1b96a4d8b92f59721d3e30875f3e408ac65
6
+ metadata.gz: 78621678bc8ce2684df57639274b4af7d4dc779c24e747514cce305bf566d0525ee54d9b1cae8ca7ab09854d8a6e8ce3ee1b54a3077a6681821fdad5dc09f13f
7
+ data.tar.gz: c3c146afdfab2fda1867ed625cdca68d7ce3908d5eb71458ab3dde07c2af11ac2b79289922bc10e3b8a4436eff2085931a355e42e1ed3c51497f9e6166b7209c
@@ -8,7 +8,8 @@ module Eco
8
8
  def process
9
9
  @parsers.define_attribute(:number, dependencies: @options) do |parser|
10
10
  parser.def_parser do |value, deps|
11
- deps[:schema]&.fields[deps["attr"]].parse_text(value)
11
+ #deps[:schema]&.fields[deps["attr"]].parse_text(value)
12
+ value = value.to_s.strip == "" ? nil : (value.to_f rescue nil)
12
13
  end.def_serializer do |value|
13
14
  value.is_a?(Array) ? value.map { |v| v.to_s } : value.to_s
14
15
  end
@@ -33,7 +33,7 @@ module Eco
33
33
  @by_id.fetch(policy_group_id(id_name), nil)
34
34
  end
35
35
 
36
- def user_pg_ids(initial: [], final: [], non_custom: [], preserve_custom: true)
36
+ def user_pg_ids(initial: [], final: [], non_custom: (non_custom_used = false; []), preserve_custom: true)
37
37
  non_custom = to_id([non_custom].flatten.compact)
38
38
  initial = to_id([initial].flatten.compact)
39
39
  final = to_id([final].flatten.compact)
@@ -41,8 +41,11 @@ module Eco
41
41
  raise "Expected Array for :initial, :final and :custom"
42
42
  end
43
43
 
44
- initial_custom = initial - non_custom
45
- final = final + initial_custom if preserve_custom
44
+ if non_custom_used && preserve_custom
45
+ initial_custom = initial - non_custom
46
+ final = final + initial_custom
47
+ end
48
+
46
49
  new_pg_ids = final - initial
47
50
  # keep same order as they where
48
51
  (initial & final) + new_pg_ids
@@ -0,0 +1,43 @@
1
+ module Eco
2
+ module API
3
+ module UseCases
4
+ class DefaultCases
5
+ class ToCsvDetailedCase < BaseCase
6
+
7
+ def process
8
+ @cases.define("to-csv-detailed", type: :export) do |people, session, options|
9
+ unless people && !people.empty?
10
+ session.logger.warn("No source people to create the file... aborting!")
11
+ next false
12
+ end
13
+
14
+ unless file = options[:file]
15
+ session.logger.error("Destination file not specified")
16
+ next false
17
+ end
18
+
19
+ abilities = session.new_preset([]).keys
20
+
21
+ session.logger.info("going to create file: #{file}")
22
+ CSV.open(file, "w") do |csv|
23
+ deps = {"supervisor_id" => {people: people}}
24
+ header = session.new_entry(people.first, dependencies: deps).to_hash.keys
25
+ header += abilities
26
+
27
+ csv << header
28
+ people.each do |person|
29
+ data = session.new_entry(person, dependencies: deps).to_hash.values
30
+ person_abilities = (person.account && person.account.permissions_custom) || {}
31
+ data += abilities.map {|key| person_abilities[key] || "no access"}
32
+ csv << data
33
+ end
34
+ end
35
+ true
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -7,6 +7,7 @@ module Eco
7
7
  @source = array_of_arrays
8
8
 
9
9
  if @source
10
+ # internal should be always last in @source
10
11
  @source = @source.map { |a| a.reverse } unless internal == :last
11
12
 
12
13
  # first declarations take priority
@@ -20,7 +21,7 @@ module Eco
20
21
  def list(type = :internal)
21
22
  return [] if !@source
22
23
  @source.map do |pair|
23
- type == :internal ? pair.first : pair.last
24
+ type == :internal ? pair.last : pair.first
24
25
  end.uniq
25
26
  end
26
27
 
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "0.6.6"
2
+ VERSION = "0.6.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eco-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -295,6 +295,7 @@ files:
295
295
  - lib/eco/api/usecases/default_cases/set_supervisor_case.rb
296
296
  - lib/eco/api/usecases/default_cases/switch_supervisor_case.rb
297
297
  - lib/eco/api/usecases/default_cases/to_csv_case.rb
298
+ - lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb
298
299
  - lib/eco/api/usecases/default_cases/update_case.rb
299
300
  - lib/eco/api/usecases/default_cases/update_details_case.rb
300
301
  - lib/eco/api/usecases/default_cases/upsert_case.rb