ooze-parser 0.1.11 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +22 -0
  3. data/.rubocop.yml +102 -0
  4. data/.ruby-version +1 -0
  5. data/.yardopts +10 -0
  6. data/README.md +23 -0
  7. data/lib/ooz/base/evolution.rb +2 -1
  8. data/lib/ooz/base/field/actions_list.rb +10 -0
  9. data/lib/ooz/base/field/checklist.rb +3 -2
  10. data/lib/ooz/base/field/contractor_entities.rb +15 -0
  11. data/lib/ooz/base/field/cross_reference.rb +3 -2
  12. data/lib/ooz/base/field/date.rb +4 -3
  13. data/lib/ooz/base/field/file.rb +3 -2
  14. data/lib/ooz/base/field/gauge.rb +3 -2
  15. data/lib/ooz/base/field/geo.rb +10 -0
  16. data/lib/ooz/base/field/image_gallery.rb +3 -2
  17. data/lib/ooz/base/field/mailbox.rb +10 -0
  18. data/lib/ooz/base/field/people.rb +5 -3
  19. data/lib/ooz/base/field/select.rb +18 -13
  20. data/lib/ooz/base/field.rb +30 -13
  21. data/lib/ooz/base/field_factory.rb +9 -3
  22. data/lib/ooz/base/force.rb +3 -3
  23. data/lib/ooz/base/genome.rb +14 -0
  24. data/lib/ooz/base/model.rb +16 -9
  25. data/lib/ooz/base/model_factory.rb +13 -9
  26. data/lib/ooz/base/ooze.rb +21 -9
  27. data/lib/ooz/base/stage/task/action_factory.rb +5 -2
  28. data/lib/ooz/base/stage/task/scheduled_callback.rb +2 -1
  29. data/lib/ooz/base/stage/task/strategy/direct.rb +1 -1
  30. data/lib/ooz/base/stage/task/strategy/editable.rb +1 -1
  31. data/lib/ooz/base/stage/task/strategy/prior.rb +1 -1
  32. data/lib/ooz/base/stage/task/strategy/prior_supervisor.rb +1 -1
  33. data/lib/ooz/base/stage/task/strategy.rb +9 -9
  34. data/lib/ooz/base/stage/task/strategy_factory.rb +8 -2
  35. data/lib/ooz/base/stage/task.rb +12 -11
  36. data/lib/ooz/base/stage.rb +4 -2
  37. data/lib/ooz/base.rb +1 -0
  38. data/lib/ooz/common/base_class.rb +15 -9
  39. data/lib/ooz/common/base_factory.rb +0 -3
  40. data/lib/ooz/common/base_model.rb +13 -8
  41. data/lib/ooz/common/hash_diff.rb +6 -4
  42. data/lib/ooz/model/evolution.rb +1 -2
  43. data/lib/ooz/model/field/actions_list.rb +15 -0
  44. data/lib/ooz/model/field/checklist/item.rb +5 -0
  45. data/lib/ooz/model/field/checklist.rb +7 -1
  46. data/lib/ooz/model/field/contractor_entities.rb +14 -0
  47. data/lib/ooz/model/field/cross_reference.rb +5 -0
  48. data/lib/ooz/model/field/date.rb +5 -0
  49. data/lib/ooz/model/field/file.rb +7 -1
  50. data/lib/ooz/model/field/gauge.rb +6 -0
  51. data/lib/ooz/model/field/geo.rb +15 -0
  52. data/lib/ooz/model/field/image_gallery.rb +7 -1
  53. data/lib/ooz/model/field/mailbox.rb +14 -0
  54. data/lib/ooz/model/field/number.rb +5 -0
  55. data/lib/ooz/model/field/people.rb +5 -0
  56. data/lib/ooz/model/field/plain_text.rb +5 -0
  57. data/lib/ooz/model/field/rich_text.rb +5 -0
  58. data/lib/ooz/model/field/select/option.rb +5 -0
  59. data/lib/ooz/model/field/select.rb +7 -1
  60. data/lib/ooz/model/field.rb +24 -14
  61. data/lib/ooz/model/field_factory.rb +1 -1
  62. data/lib/ooz/model/ooze.rb +48 -17
  63. data/lib/ooz/model/section.rb +1 -3
  64. data/lib/ooz/model/stage.rb +10 -2
  65. data/lib/ooz/version.rb +1 -1
  66. data/lib/ooze-parser.rb +1 -0
  67. data/ooze-parser.gemspec +18 -17
  68. metadata +18 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17f2257b16610a5145ae081447aef22941fa85ec6bdb923992c8892262cde223
4
- data.tar.gz: 43dbea66a84a5d4ade5508a605e2ca25f1198f64b5bee03e125d684ebaa34837
3
+ metadata.gz: 5a67c203d84a3a2890d20f2a2c7da655bc7fb521a8c92f7101b882535800ba92
4
+ data.tar.gz: 999a154e5ff6088ce1e022496087b5012c90ca25937432c9b1951eeb91bb83de
5
5
  SHA512:
6
- metadata.gz: eef8cf42922b94246efcefd475a56582666816d148ea7bf0ef3fc9dca591e4490a9b9aff0175dbd9ddab856b84fa04a96b0ff553d7a67219feabefa00169b8e2
7
- data.tar.gz: d586b55a165bad8d781b7c85755aad8ef6f8f46932c34ad4ba372221d7a3f6c0af2d54959c10fd67eae2cb895f834ed35accc37d5505acc568b54239ae811b13
6
+ metadata.gz: 7563820fe8469c75f646fbd88883a308e8f000cb14b57fc23dbaa18b1dd81122ba3d9eb6d167610b01a215e9b3cde26524d41fa65621817a3d2f1a176ecea736
7
+ data.tar.gz: 334f759ba653339d2c1001fd759ff6d8f699b70f9b73fc214d785804bc9e74fc19ef6beb87d2ce6955c7629903a138d3119d609a0f7ef7c77af1ae1b364d6e5b
data/.gitignore CHANGED
@@ -1 +1,23 @@
1
+ # it's a gem, ignore the lockfile
2
+ Gemfile.lock
3
+
4
+ # build artifacts
1
5
  *.gem
6
+ /.bundle
7
+ /.vscode
8
+ .solargraph.yml
9
+ /vendor/bundle
10
+ /spec/reports/
11
+ /tmp/
12
+ /pkg/
13
+
14
+ # docs
15
+ /.yardoc
16
+ /_yardoc/
17
+ /coverage/
18
+ /doc/
19
+
20
+ # rspec failure tracking
21
+ .rspec_status
22
+ scratch.rb
23
+ .byebug_history
data/.rubocop.yml ADDED
@@ -0,0 +1,102 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.2.2
3
+ Exclude:
4
+ - 'config/routes.rb'
5
+ NewCops: enable
6
+
7
+ Metrics/ClassLength:
8
+ Max: 500
9
+ Metrics/ModuleLength:
10
+ Max: 300
11
+ Metrics/MethodLength:
12
+ Max: 50
13
+ Metrics/AbcSize:
14
+ Max: 30
15
+ Metrics/ParameterLists:
16
+ Max: 5
17
+ CountKeywordArgs: false
18
+ Metrics/BlockLength:
19
+ CountAsOne: ['array', 'heredoc', 'method_call']
20
+ Max: 50
21
+ Metrics/CyclomaticComplexity:
22
+ Max: 30
23
+ Metrics/PerceivedComplexity:
24
+ Max: 30
25
+
26
+ Style/AccessorGrouping:
27
+ Enabled: false
28
+ Style/ConditionalAssignment:
29
+ Enabled: false
30
+ Style/BlockDelimiters:
31
+ BracesRequiredMethods: ['log']
32
+ AllowedPatterns: ['proc', 'new']
33
+ Style/HashSyntax:
34
+ EnforcedShorthandSyntax: either
35
+ EnforcedStyle: no_mixed_keys
36
+ Style/ArgumentsForwarding:
37
+ UseAnonymousForwarding: false
38
+ Style/ClassAndModuleChildren:
39
+ Enabled: false
40
+ Style/FrozenStringLiteralComment:
41
+ Enabled: false
42
+ Style/StringLiterals:
43
+ Enabled: false
44
+ Style/StringLiteralsInInterpolation:
45
+ Enabled: false
46
+ Style/Documentation:
47
+ Enabled: false
48
+ Style/CommentedKeyword:
49
+ Enabled: false
50
+ Style/MultilineBlockChain:
51
+ Enabled: false
52
+ Style/AndOr:
53
+ Enabled: false
54
+ Style/Alias:
55
+ EnforcedStyle: prefer_alias_method
56
+ Style/FetchEnvVar:
57
+ Enabled: false
58
+ Style/RegexpLiteral:
59
+ EnforcedStyle: mixed
60
+ AllowInnerSlashes: true
61
+
62
+ Layout/HashAlignment:
63
+ EnforcedColonStyle: table
64
+ EnforcedHashRocketStyle: table
65
+ Layout/LeadingCommentSpace:
66
+ Enabled: false
67
+ AllowGemfileRubyComment: true
68
+ Layout/ParameterAlignment:
69
+ Enabled: false
70
+ Layout/MultilineMethodDefinitionBraceLayout:
71
+ EnforcedStyle: symmetrical
72
+ Layout/LineLength:
73
+ Enabled: true
74
+ Layout/SpaceInsideHashLiteralBraces:
75
+ Enabled: false
76
+ Layout/SpaceInsideBlockBraces:
77
+ Enabled: false
78
+ Layout/SpaceAroundOperators:
79
+ Enabled: false
80
+ Layout/ExtraSpacing:
81
+ AllowForAlignment: true
82
+ AllowBeforeTrailingComments: true
83
+ Layout/AccessModifierIndentation:
84
+ EnforcedStyle: indent
85
+ Layout/DotPosition:
86
+ EnforcedStyle: trailing
87
+ Layout/MultilineMethodCallIndentation:
88
+ EnforcedStyle: indented
89
+ Layout/FirstHashElementIndentation:
90
+ Enabled: false
91
+ Layout/EmptyLineAfterGuardClause:
92
+ Enabled: false
93
+
94
+ Naming/VariableNumber:
95
+ EnforcedStyle: snake_case
96
+ CheckSymbols: false
97
+ Naming/MethodParameterName:
98
+ AllowedNames: ['x', 'y', 'i', 'j', 'id', 'io', 'to']
99
+ Naming/RescuedExceptionsVariableName:
100
+ Enabled: false
101
+ Naming/BlockForwarding:
102
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.2
data/.yardopts ADDED
@@ -0,0 +1,10 @@
1
+ --readme README.md
2
+ --charset utf-8
3
+ --markup-provider=redcarpet
4
+ --markup=markdown
5
+ --no-private
6
+ --output-dir ./doc
7
+ 'lib/**/*.rb'
8
+ CHANGELOG.md
9
+ -
10
+ LICENSE
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # Ooze Parser (ooze-parser)
2
+
3
+ JSON parser for ecoPortal Ooze.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ooze-parser'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```shell
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```shell
22
+ $ gem install ooze-parser
23
+ ```
@@ -2,8 +2,9 @@ module Ooz
2
2
  module Base
3
3
  class Evolution < Base::Model
4
4
  overridable_const :stage_class, Base::Stage
5
+
5
6
  passthrough :_id, :patch_ver, to: :doc
6
- passthrough_arr :stages, to: :doc, klass: :stage_class
7
+ embedding_many :stages, to: :doc, klass: :stage_class
7
8
  end
8
9
  end
9
10
  end
@@ -0,0 +1,10 @@
1
+ module Ooz
2
+ module Base
3
+ class Field
4
+ class ActionsList < Field
5
+ passthrough :action_ids, to: :doc
6
+ passthrough :action_recurrence_ids, to: :doc
7
+ end
8
+ end
9
+ end
10
+ end
@@ -7,15 +7,16 @@ module Ooz
7
7
  end
8
8
  end
9
9
 
10
- require_relative "checklist/item"
10
+ require_relative 'checklist/item'
11
11
 
12
12
  module Ooz
13
13
  module Base
14
14
  class Field
15
15
  class Checklist
16
16
  overridable_const :checklist_item_class, Base::Field::Checklist::Item
17
+
17
18
  passthrough :complete, to: :doc
18
- passthrough_arr :items, to: :doc, klass: :checklist_item_class
19
+ embedding_many :items, to: :doc, klass: :checklist_item_class
19
20
  end
20
21
  end
21
22
  end
@@ -0,0 +1,15 @@
1
+ module Ooz
2
+ module Base
3
+ class Field
4
+ class ContractorEntities < Field
5
+ passthrough :contractor_entities_ids, to: :doc
6
+ passthrough :singular, :is_me_button, :show_approval_status, to: :doc
7
+ passthrough :apply_attached_contractors_permissions_to, :grant_permissions_enabled, to: :doc
8
+ passthrough :attached_contractors_permissions_flags, to: :doc
9
+ passthrough :attached_contractors_admin_permissions_flags, to: :doc
10
+ passthrough :admin_access, to: :doc
11
+ passthrough :regular_access, to: :doc
12
+ end
13
+ end
14
+ end
15
+ end
@@ -2,8 +2,9 @@ module Ooz
2
2
  module Base
3
3
  class Field
4
4
  class CrossReference < Field
5
- passthrough :reference_ids, :register_id, :hide_create, :hide_attach, :hide_metadata, :hide_dashboards,
6
- :display_fields, :display_fields_in_lookup, to: :doc
5
+ passthrough :reference_ids, :register_id, to: :doc
6
+ passthrough :hide_create, :hide_attach, :hide_metadata, :hide_dashboards, to: :doc
7
+ passthrough :display_fields, :display_fields_in_lookup, to: :doc
7
8
  end
8
9
  end
9
10
  end
@@ -2,9 +2,10 @@ module Ooz
2
2
  module Base
3
3
  class Field
4
4
  class Date < Field
5
- passthrough :show_time, :past_only, :today_button, :create_event, :event_id,
6
- :remind_me_in, :value, :renews, :renews_unit, :renews_every, :renews_until,
7
- to: :doc
5
+ passthrough :value, to: :doc
6
+ passthrough :show_time, :past_only, :today_button, to: :doc
7
+ passthrough :create_event, :event_id, to: :doc
8
+ passthrough :remind_me_in, :renews, :renews_unit, :renews_every, :renews_until, to: :doc
8
9
  end
9
10
  end
10
11
  end
@@ -7,14 +7,15 @@ module Ooz
7
7
  end
8
8
  end
9
9
 
10
- require_relative "file/file"
10
+ require_relative 'file/file'
11
11
 
12
12
  module Ooz
13
13
  module Base
14
14
  class Field
15
15
  class File
16
16
  overridable_const :file_class, Base::Field::File::File
17
- passthrough_arr :items, to: :doc, klass: :file_class
17
+
18
+ embedding_many :items, to: :doc, klass: :file_class
18
19
  end
19
20
  end
20
21
  end
@@ -7,15 +7,16 @@ module Ooz
7
7
  end
8
8
  end
9
9
 
10
- require_relative "gauge/stop"
10
+ require_relative 'gauge/stop'
11
11
 
12
12
  module Ooz
13
13
  module Base
14
14
  class Field
15
15
  class Gauge
16
16
  overridable_const :gauge_stop_class, Base::Field::Gauge::Stop
17
+
17
18
  passthrough :value, :max, to: :doc
18
- passthrough_arr :stops, to: :doc, klass: :gauge_stop_class
19
+ embedding_many :stops, to: :doc, klass: :gauge_stop_class
19
20
  end
20
21
  end
21
22
  end
@@ -0,0 +1,10 @@
1
+ module Ooz
2
+ module Base
3
+ class Field
4
+ class Geo < Field
5
+ passthrough :coordinates, to: :doc
6
+ passthrough :address, to: :doc
7
+ end
8
+ end
9
+ end
10
+ end
@@ -7,15 +7,16 @@ module Ooz
7
7
  end
8
8
  end
9
9
 
10
- require_relative "image_gallery/image"
10
+ require_relative 'image_gallery/image'
11
11
 
12
12
  module Ooz
13
13
  module Base
14
14
  class Field
15
15
  class ImageGallery
16
16
  overridable_const :image_class, Base::Field::ImageGallery::Image
17
+
17
18
  passthrough :stretch, :no_popup, :hide_options, :layout, to: :doc
18
- passthrough_arr :images, to: :doc, klass: :image_class
19
+ embedding_many :images, to: :doc, klass: :image_class
19
20
  end
20
21
  end
21
22
  end
@@ -0,0 +1,10 @@
1
+ module Ooz
2
+ module Base
3
+ class Field
4
+ class Mailbox < Field
5
+ passthrough :email_ids, to: :doc
6
+ passthrough :address_id, to: :doc
7
+ end
8
+ end
9
+ end
10
+ end
@@ -2,9 +2,11 @@ module Ooz
2
2
  module Base
3
3
  class Field
4
4
  class People < Field
5
- passthrough :people_ids, :singular, :attach_mode, :is_me_button, :person_schema_id, :viewable_fields,
6
- :attached_people_permissions_enabled, :attached_people_permissions_editable,
7
- to: :doc
5
+ passthrough :people_ids, to: :doc
6
+ passthrough :singular, :attach_mode, :is_me_button, to: :doc
7
+ passthrough :person_schema_id, to: :doc
8
+ passthrough :viewable_fields, to: :doc
9
+ passthrough :attached_people_permissions_enabled, :attached_people_permissions_editable, to: :doc
8
10
  end
9
11
  end
10
12
  end
@@ -7,7 +7,7 @@ module Ooz
7
7
  end
8
8
  end
9
9
 
10
- require_relative "select/option"
10
+ require_relative 'select/option'
11
11
 
12
12
  module Ooz
13
13
  module Base
@@ -18,36 +18,41 @@ module Ooz
18
18
  # @param master [Ooz::Model::Field::Select]
19
19
  # @param more [Ooz::Model::Field::Select, Array<Hash>]
20
20
  # @note it prevents douplicated values
21
- def merge_options(master, more, silent: false)
21
+ def merge_options(master, more, silent: false) # rubocop:disable Metrics/AbcSize
22
22
  if !master.is_a?(Ooz::Model::Field::Select)
23
- raise ArgumentError.new("Expecting 'master' to be Ooz::Model::Field::Select. Given: #{master.class}")
23
+ msg = "Expecting 'master' to be Ooz::Model::Field::Select. Given: #{master.class}"
24
+ raise ArgumentError, msg
24
25
  elsif !more.is_a?(Ooz::Model::Field::Select) && !more.is_a?(Array)
25
- raise ArgumentError.new("Expecting 'more' to be Ooz::Model::Field::Select or Array<Hash>. Given: #{more.class}")
26
+ msg = "Expecting 'more' to be Ooz::Model::Field::Select or Array<Hash>. Given: #{more.class}"
27
+ raise ArgumentError, msg
26
28
  end
27
- opts1 = master.doc["options"]
28
- opts2 = more.is_a?(Array)? more : more.doc["options"]
29
29
 
30
- to_add = opts2.reject do |opt|
31
- opts1.any? {|o| o["value"] == opt["value"]}
30
+ opts_1 = master.doc['options']
31
+ opts_2 = more.is_a?(Array)? more : more.doc['options']
32
+
33
+ to_add = opts_2.reject do |opt|
34
+ opts_1.any? { |o| o['value'] == opt['value'] }
32
35
  end
33
36
 
34
37
  # Some feedback
35
38
  if !silent && more.is_a?(Ooz::Model::Field::Select) && !to_add.empty?
36
39
  puts "Merging more options to the field '#{more.label}':\n"
40
+
37
41
  str_opts = to_add.map do |opt|
38
- "'#{opt["value"]}' => '#{opt["name"]}'"
42
+ "'#{opt['value']}' => '#{opt['name']}'"
39
43
  end.join("\n • ")
40
44
 
41
- puts " • " + str_opts + "\n"
45
+ puts " • #{str_opts}\n"
42
46
  end
43
47
 
44
- opts1.push(*to_add)
48
+ opts_1.push(*to_add)
45
49
  end
46
50
  end
47
-
51
+
48
52
  overridable_const :select_option, Base::Field::Select::Option
53
+
49
54
  passthrough :multiple, :flat, :data_type, :other, :other_desc, to: :doc
50
- passthrough_arr :options, to: :doc, klass: :select_option
55
+ embedding_many :options, to: :doc, klass: :select_option
51
56
  end
52
57
  end
53
58
  end
@@ -1,24 +1,41 @@
1
1
  module Ooz
2
2
  module Base
3
3
  class Field < Base::Model
4
+ overridable_const :geome_class, Base::Genome
5
+
4
6
  passthrough :_id, :_type, :label, :tooltip, :patch_ver, to: :doc
5
7
  passthrough :global_binding, to: :doc
6
8
  passthrough :hidden, :deindex, :accent, to: :doc
7
9
  passthrough :required, :hide_view, :hidden_on_reports, to: :doc
10
+
11
+ passthrough :label_translations, :tooltip_translations, to: :doc
12
+ passthrough :content_translations, to: :doc
13
+
14
+ embedding_one :genome, to: :doc, klass: :genome_class
15
+
16
+ def ref
17
+ return unless (gen = genome)
18
+
19
+ gen.ref
20
+ end
8
21
  end
9
22
  end
10
23
  end
11
24
 
12
- require_relative "field/undefined"
13
- require_relative "field/select"
14
- require_relative "field/date"
15
- require_relative "field/plain_text"
16
- require_relative "field/rich_text"
17
- require_relative "field/number"
18
- require_relative "field/gauge"
19
- require_relative "field/people"
20
- require_relative "field/tag_field"
21
- require_relative "field/cross_reference"
22
- require_relative "field/file"
23
- require_relative "field/image_gallery"
24
- require_relative "field/checklist"
25
+ require_relative 'field/undefined'
26
+ require_relative 'field/select'
27
+ require_relative 'field/date'
28
+ require_relative 'field/plain_text'
29
+ require_relative 'field/rich_text'
30
+ require_relative 'field/number'
31
+ require_relative 'field/gauge'
32
+ require_relative 'field/people'
33
+ require_relative 'field/tag_field'
34
+ require_relative 'field/cross_reference'
35
+ require_relative 'field/file'
36
+ require_relative 'field/image_gallery'
37
+ require_relative 'field/checklist'
38
+ require_relative 'field/contractor_entities'
39
+ require_relative 'field/geo'
40
+ require_relative 'field/actions_list'
41
+ require_relative 'field/mailbox'
@@ -1,9 +1,15 @@
1
1
  module Ooz
2
2
  module Base
3
3
  class FieldFactory < ModelFactory
4
- def_parent_class Base::Field
5
- def_white_classes "Select", "TagField", "Date", "PlainText", "RichText",
6
- "Number", "Gauge", "People", "CrossReference", "File", "ImageGallery", "Checklist"
4
+ parent_class_is Base::Field
5
+
6
+ WHITE_CLASS = %w[
7
+ Select TagField Date PlainText RichText
8
+ Number Gauge People CrossReference File
9
+ ImageGallery Checklist
10
+ ].freeze
11
+
12
+ white_classes_are(*WHITE_CLASS)
7
13
  end
8
14
  end
9
15
  end
@@ -5,16 +5,16 @@ module Ooz
5
5
  end
6
6
  end
7
7
 
8
- require_relative "force/binding"
8
+ require_relative 'force/binding'
9
9
 
10
10
  module Ooz
11
11
  module Base
12
12
  class Force
13
13
  overridable_const :binding_class, Base::Force::Binding
14
+
14
15
  passthrough :_id, :name, :weight, :patch_ver, to: :doc
15
16
  passthrough :script, to: :doc
16
- passthrough_arr :binings, to: :doc, klass: :binding_class
17
+ embedding_many :binings, to: :doc, klass: :binding_class
17
18
  end
18
-
19
19
  end
20
20
  end
@@ -0,0 +1,14 @@
1
+ module Ooz
2
+ module Base
3
+ class Genome < Base::Model
4
+ passthrough :_id, to: :doc
5
+ passthrough :signature, :type, to: :doc
6
+
7
+ def ref
8
+ return unless type && signature
9
+
10
+ [type, signature].join('.')
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,37 +1,44 @@
1
1
  module Ooz
2
2
  module Base
3
3
  class Model < Common::BaseModel
4
-
5
4
  attr_reader :root
6
5
 
7
6
  def initialize(*args, root: nil)
8
7
  super(*args)
8
+
9
9
  @root = root
10
10
  end
11
11
 
12
12
  def ooze
13
- self.is_a?(Ooze)? self : root && root.ooze
13
+ is_a?(Ooze)? self : root&.ooze
14
14
  end
15
15
 
16
16
  private
17
17
 
18
18
  def to_hash(arr, key: "_id")
19
- raise "Sorry, expected Array, given: #{arr.class.name}" if !arr.is_a?(Array)
20
- arr.map do |e|
19
+ msg = "Sorry, expected Array, given: #{arr.class.name}"
20
+ raise msg unless arr.is_a?(Array)
21
+
22
+ arr.to_h do |e|
21
23
  [e.send(key), e]
22
- end.to_h
24
+ end
23
25
  end
24
26
 
25
27
  def collect_from(ids, elements_hash)
26
- raise "Sorry, 'ids' expected to be Array, given: #{arr.class.name}" if !ids.is_a?(Array)
27
- raise "Expected hash, given: #{elements_hash.class.name}" if !elements_hash.is_a?(Hash)
28
+ msg = "Sorry, 'ids' expected to be Array, given: #{arr.class.name}"
29
+ raise msg unless ids.is_a?(Array)
30
+
31
+ msg = "Expected hash, given: #{elements_hash.class.name}"
32
+ raise msg unless elements_hash.is_a?(Hash)
33
+
28
34
  ids.map do |id|
29
35
  elements_hash[id].tap do |e|
30
- puts "Warning: there is no element with id '#{id}'" if !e
36
+ next if e
37
+
38
+ puts "Warning: there is no element with id '#{id}'"
31
39
  end
32
40
  end
33
41
  end
34
-
35
42
  end
36
43
  end
37
44
  end
@@ -2,7 +2,7 @@ module Ooz
2
2
  module Base
3
3
  class ModelFactory < Common::BaseFactory
4
4
  class << self
5
- def def_white_classes (*str_classes)
5
+ def white_classes_are(*str_classes)
6
6
  str_classes = str_classes.map do |cls|
7
7
  case cls
8
8
  when cls.respond_to?(:name)
@@ -13,12 +13,14 @@ module Ooz
13
13
  cls
14
14
  end
15
15
  end.compact
16
+
16
17
  overridable_const :white_classes, str_classes
17
18
  end
18
19
 
19
- def def_parent_class (parent_class)
20
- msg = "Expected a valid parent class for you factory, from which the other classes inherit. Given #{parent_class}"
21
- valid_class = parent_class && parent_class.is_a?(Class)
20
+ def parent_class_is(parent_class)
21
+ msg = 'Expected a valid parent class for you factory, from which the other classes inherit.'
22
+ msg << " Given #{parent_class}"
23
+ valid_class = parent_class.is_a?(Class)
22
24
  raise msg unless valid_class
23
25
 
24
26
  overridable_const :parent_class, parent_class
@@ -26,14 +28,17 @@ module Ooz
26
28
  end
27
29
 
28
30
  def new(*args, **kargs)
29
- raise "You must use 'def_parent_class' to initialize your Factory class" if !defined?(parent_class)
31
+ msg = "You must use 'parent_class_is' to initialize your Factory class"
32
+ raise msg unless defined?(parent_class)
30
33
 
31
- type = args.first&.dig("_type")&.split("::")&.last
32
- raise "Your object should have field '_type' defined" if !type
34
+ raw_type = args.first&.dig('_type')
35
+ type = raw_type&.split('::')&.last
36
+ raise "Your object should have field '_type' defined" unless type
33
37
 
34
38
  if white_classes.include?(type)
35
39
  str_class = "#{base_namespace}::#{type}"
36
- raise "This class does not exist: #{str_class}" if !Object.const_defined?(str_class)
40
+ raise "This class does not exist: #{str_class}" unless Object.const_defined?(str_class)
41
+
37
42
  klass = Object.const_get(str_class)
38
43
  else
39
44
  str_class = "#{base_namespace}::Undefined"
@@ -42,7 +47,6 @@ module Ooz
42
47
 
43
48
  klass.new(*args, **kargs)
44
49
  end
45
-
46
50
  end
47
51
  end
48
52
  end