eco-helpers 0.6.0 → 0.6.1

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: bb418abf2d0a0a3bcf9d4f95c9696b9d6347f006
4
- data.tar.gz: 978e4c69e536b192722df51e8eb361d835a708ae
3
+ metadata.gz: 1be39cfd739ccf1346f635fb4b341faf84567869
4
+ data.tar.gz: e7b0a20c6a4438a8cb7475d93c84a098339ed2b2
5
5
  SHA512:
6
- metadata.gz: 72efbdbf8703f5be28ef9fb223c3886d83ed8a3d72d5ff58efe7bb59ce6cc5f82916cef8cdac685c01c7f1d70d70a6cf43fe7ddc35bfffe3754b98ded18e976e
7
- data.tar.gz: b40e206e5e3d633e8dec159342e1df20b2424e378e4418cdd4820c675335d34f94925a3865ff12c2c10f1b0836178f6adab4cbd036e931a2eb6ffd5e9f082e25
6
+ metadata.gz: 85d763bfd6a440ed19d6bb43b130073cb625eb4da0076d2e09430b6c09709a5aa87218c588988dca3ffd11e771174dac4bdcf688eab59630441d6635e170eb45
7
+ data.tar.gz: a26f655e2f9afc47ffdd4e9a545e8223d248a5430b94ef0dc972e926b1a3ac425bb1a7f23474b6680c4a06875a159111c269f3cdd7f88aa97ba4fb8c3ac01688
@@ -2,33 +2,6 @@ module Eco
2
2
  module API
3
3
  module Common
4
4
  module People
5
- class EntryFactory
6
-
7
- attr_reader :person_parser
8
-
9
- def initialize(schema:, person_parser: nil, fields_mapper: nil, logger: ::Logger.new(IO::NULL))
10
- raise "Constructor needs a PersonSchema. Given: #{schema}" if !schema.is_a?(Ecoportal::API::V1::PersonSchema)
11
- raise "Expecting PersonParser. Given: #{person_parser}" if person_parser && !person_parser.is_a?(Eco::API::Common::People::PersonParser)
12
- raise "Expecting Mapper object. Given: #{fields_mapper}" if fields_mapper && !fields_mapper.is_a?(Eco::Data::Mapper)
13
-
14
- @logger = logger
15
- @schema = Ecoportal::API::V1::PersonSchema.new(JSON.parse(schema.doc.to_json))
16
-
17
- default_parser = Eco::API::Common::People::DefaultParsers.new(schema: @schema)
18
- @parser = default_parser.merge(person_parser)
19
-
20
- @fields_mapper = fields_mapper
21
- end
22
-
23
- def new(data, dependencies: {})
24
- PersonEntry.new(data, parser: @parser, mapper: @fields_mapper, dependencies: dependencies, logger: @logger)
25
- end
26
-
27
- def entries(data)
28
- Entries.new(data, klass: PersonEntry, factory: self)
29
- end
30
- end
31
-
32
5
  class Entries < Eco::Language::Models::Collection
33
6
 
34
7
  # build the shortcuts of Collection
@@ -0,0 +1,35 @@
1
+ module Eco
2
+ module API
3
+ module Common
4
+ module People
5
+ class EntryFactory
6
+
7
+ attr_reader :person_parser
8
+
9
+ def initialize(schema:, person_parser: nil, fields_mapper: nil, logger: ::Logger.new(IO::NULL))
10
+ raise "Constructor needs a PersonSchema. Given: #{schema}" if !schema.is_a?(Ecoportal::API::V1::PersonSchema)
11
+ raise "Expecting PersonParser. Given: #{person_parser}" if person_parser && !person_parser.is_a?(Eco::API::Common::People::PersonParser)
12
+ raise "Expecting Mapper object. Given: #{fields_mapper}" if fields_mapper && !fields_mapper.is_a?(Eco::Data::Mapper)
13
+
14
+ @logger = logger
15
+ @schema = Ecoportal::API::V1::PersonSchema.new(JSON.parse(schema.doc.to_json))
16
+
17
+ default_parser = Eco::API::Common::People::DefaultParsers.new(schema: @schema)
18
+ @parser = default_parser.merge(person_parser)
19
+
20
+ @fields_mapper = fields_mapper
21
+ end
22
+
23
+ def new(data, dependencies: {})
24
+ PersonEntry.new(data, parser: @parser, mapper: @fields_mapper, dependencies: dependencies, logger: @logger)
25
+ end
26
+
27
+ def entries(data)
28
+ Entries.new(data, klass: PersonEntry, factory: self)
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
@@ -15,3 +15,4 @@ require_relative 'people/person_parser'
15
15
  require_relative 'people/default_parsers'
16
16
  require_relative 'people/person_entry'
17
17
  require_relative 'people/entries'
18
+ require_relative 'people/entry_factory'
@@ -32,7 +32,7 @@ module Eco
32
32
  api = config.api(log)
33
33
 
34
34
  unless log_connection
35
- logger.info("Created connection pointing to '#{config.apis.active_api.host}'")
35
+ logger.info("Created connection pointing to '#{config.apis.active_api.host}' in '#{config.apis.active_api.mode}' mode")
36
36
  api.logger.level = ::Logger::UNKNOWN
37
37
  end
38
38
 
@@ -159,6 +159,7 @@ module Eco
159
159
  def process_case(name, type: nil, **params)
160
160
  args = { session: self }.merge(params)
161
161
  fatal("Undefined usecase '#{name}' of type '#{type.to_s}'") if !@use_cases.defined?(name, type: type)
162
+ logger.debug("Session: going to process '#{name}' defined case")
162
163
  @use_cases.case(name, type: type).process(**args)
163
164
  end
164
165
 
@@ -2,10 +2,12 @@ module Eco
2
2
  module API
3
3
  class SessionConfig
4
4
  class People < Hash
5
+ attr_reader :config
5
6
 
6
7
  def initialize(root:)
7
8
  super(nil)
8
- @root = root
9
+ @root = root
10
+ @config = @root
9
11
  end
10
12
 
11
13
  def cache=(file)
@@ -69,18 +71,21 @@ module Eco
69
71
  end
70
72
 
71
73
  # CUSTOM PERSON PARSERS
72
- def person_parser(format: :csv)
73
- self["parsers"] ||= Eco::API::Common::People::PersonParser.new
74
+ def add_parser(format: :csv)
74
75
  new_parsers = Eco::API::Common::People::PersonParser.new
75
76
 
76
- yield(new_parsers, self)
77
+ yield(new_parsers, config)
78
+ parsers[format] ||= Eco::API::Common::People::PersonParser.new
79
+ parsers[format] = parsers[format] ? parsers[format].merge(new_parsers) : new_parsers
80
+ end
77
81
 
78
- parsers = self["parsers"][format]
79
- self["parsers"][format] = parsers ? parsers.merge(new_parsers) : new_parsers
82
+ def parsers
83
+ self["parsers"] ||= {}
84
+ self["parsers"]
80
85
  end
81
86
 
82
87
  def parser(format: :csv)
83
- self.dig("parsers", format)
88
+ parsers[format]
84
89
  end
85
90
 
86
91
  end
@@ -2,19 +2,20 @@ module Eco
2
2
  module API
3
3
  class SessionConfig
4
4
  class UseCases < Hash
5
-
5
+ attr_reader :config
6
+
6
7
  def initialize(root:)
7
8
  super(nil)
8
- @root = root
9
+ @root = root
10
+ @config = @root
9
11
  end
10
12
 
11
13
  # CUSTOM USE CASES
12
14
  def add
13
- self["use_group"] ||= Eco::API::UseCases::UseGroup.new
14
15
  new_group = Eco::API::UseCases::UseGroup.new
16
+ yield(new_group, config)
15
17
 
16
- yield(new_group, self)
17
-
18
+ self["use_group"] ||= Eco::API::UseCases::UseGroup.new
18
19
  group = self["use_group"]
19
20
  group = group ? group.merge(new_group) : group
20
21
  self["use_group"] = group
@@ -126,7 +126,7 @@ module Eco
126
126
 
127
127
  # PEOPLE
128
128
  def discarded_people_file=(value)
129
- people.discarded_people_file = value
129
+ people.discarded_file = value
130
130
  end
131
131
 
132
132
  def people_cache=(file)
@@ -157,7 +157,7 @@ module Eco
157
157
 
158
158
  # CUSTOM PERSON PARSERS
159
159
  def person_parser(format: :csv, &block)
160
- people.parser(format: format, &block)
160
+ people.add_parser(format: format, &block)
161
161
  end
162
162
 
163
163
  # CUSTOM USE CASES
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
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.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -193,6 +193,7 @@ files:
193
193
  - lib/eco/api/common/people/default_parsers/numeric_parser.rb
194
194
  - lib/eco/api/common/people/default_parsers/select_parser.rb
195
195
  - lib/eco/api/common/people/entries.rb
196
+ - lib/eco/api/common/people/entry_factory.rb
196
197
  - lib/eco/api/common/people/person_entry.rb
197
198
  - lib/eco/api/common/people/person_factory.rb
198
199
  - lib/eco/api/common/people/person_modifier.rb