dina 0.7.3.0 → 0.7.5.0

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
  SHA256:
3
- metadata.gz: 06235bf5d722c2f96bbbc1d4c4bd3dd7e78bc1eef08c0e9e7412c6920312c17b
4
- data.tar.gz: 4bd30f51b2626a453e1871dab175057869be4d6bd15d00817cf835ff6ec89d00
3
+ metadata.gz: 8ccd7e97e13338d74abe532c9682da8c190428a6a49e9f185ab8b8ced6ac31ac
4
+ data.tar.gz: 65fbba40026990fd8cfaa90803e8c909dc3431eea4585800093d9c433801bb25
5
5
  SHA512:
6
- metadata.gz: d25fecef73f0669268ab5e52e29b935b5e42447988aff67e48489f9b46aec181ab05fde556460384ceab61ca1ecdf9d55e7049d43610f53c6e044091eefba1db
7
- data.tar.gz: a8a9e55dd08583d371a47e1fe1004e1003edd844a866ddc51bcc6b6ec5c150f5e57814c024d18a14464c63787bbc158e079e27f8acfc55ee6fb9f7a7c2dd84ed
6
+ metadata.gz: 0a13c0b80dea86b275fa961cb0f6c17d7645c5a0ed99fc09b6dbbe087923aa6dc95dcc746bc3ebbdfe26f4200f7486fb94355295ea1ead24a632bcebebf5a233
7
+ data.tar.gz: 1b4fc2d14a4766fbd598cec301c4e39c002e044e34c70b6a6c48fe4852539e00775def68611a1197807e932de23802a9a568abceb76a04f2907d7405dcf09d74
@@ -6,31 +6,16 @@ module Dina
6
6
  @descriptions = []
7
7
  if opts[:descriptions]
8
8
  @descriptions = opts[:descriptions]
9
- end
10
- if opts[:english]
11
- self.english_description = opts[:english]
12
- end
13
- if opts[:french]
14
- self.french_description = opts[:french]
9
+ else
10
+ self.set_description(opts)
15
11
  end
16
12
  end
17
13
 
18
- def english_description=(desc)
19
- descriptions.delete_if{|o| o[:lang] == "en"}
20
- descriptions << { lang: "en", desc: desc }
21
- end
22
-
23
- def english_description
24
- descriptions.select{|o| o[:lang] == "en"}.first[:desc]
25
- end
26
-
27
- def french_description=(desc)
28
- descriptions.delete_if{|o| o[:lang] == "fr"}
29
- descriptions << { lang: "fr", desc: desc }
30
- end
31
-
32
- def french_description
33
- descriptions.select{|o| o[:lang] == "fr"}.first[:desc]
14
+ def set_description(opts = {})
15
+ opts.each do |key, value|
16
+ descriptions.delete_if{|o| o[:lang] == key.to_s}
17
+ descriptions << { lang: key.to_s, desc: value }
18
+ end
34
19
  end
35
20
 
36
21
  def to_hash
@@ -4,7 +4,7 @@ module Dina
4
4
  class MultilingualDescriptionCaster
5
5
  def self.cast(value, default)
6
6
  begin
7
- Dina::MultilingualDescription.new(value).to_hash
7
+ MultilingualDescription.new(value).to_hash
8
8
  rescue ArgumentError
9
9
  { descriptions: [] }
10
10
  end
@@ -6,31 +6,16 @@ module Dina
6
6
  @titles = []
7
7
  if opts[:titles]
8
8
  @titles = opts[:titles]
9
- end
10
- if opts[:english]
11
- self.english_title = opts[:english]
12
- end
13
- if opts[:french]
14
- self.french_title = opts[:french]
9
+ else
10
+ self.set_title(opts)
15
11
  end
16
12
  end
17
13
 
18
- def english_title=(title)
19
- titles.delete_if{|o| o[:lang] == "en"}
20
- titles << { lang: "en", title: title }
21
- end
22
-
23
- def english_title
24
- titles.select{|o| o[:lang] == "en"}.first[:title]
25
- end
26
-
27
- def french_title=(title)
28
- titles.delete_if{|o| o[:lang] == "fr"}
29
- titles << { lang: "fr", title: title }
30
- end
31
-
32
- def french_title
33
- titles.select{|o| o[:lang] == "fr"}.first[:title]
14
+ def set_title(opts ={})
15
+ opts.each do |key, value|
16
+ titles.delete_if{|o| o[:lang] == key.to_s}
17
+ titles << { lang: key.to_s, title: value }
18
+ end
34
19
  end
35
20
 
36
21
  def to_hash
@@ -4,7 +4,7 @@ module Dina
4
4
  class MultilingualTitleCaster
5
5
  def self.cast(value, default)
6
6
  begin
7
- Dina::MultilingualTitle.new(value).to_hash
7
+ MultilingualTitle.new(value).to_hash
8
8
  rescue ArgumentError
9
9
  { titles: [] }
10
10
  end
@@ -4,5 +4,6 @@ module Dina
4
4
  class TokenStoreContentInvalid < DinaException; end
5
5
  class ConfigItemMissing < DinaException; end
6
6
  class ObjectInvalid < DinaException; end
7
+ class PropertyInvalid < ObjectInvalid; end
7
8
  class PropertyValueInvalid < ObjectInvalid; end
8
9
  end
@@ -38,22 +38,20 @@ module Dina
38
38
  symbolized_params = params.transform_keys(&:to_sym)
39
39
  params["id"] = SecureRandom.uuid if !symbolized_params[:id]
40
40
  super
41
+ extend_model_methods
41
42
  end
42
43
 
43
- def english_description
44
- if self.respond_to?(:multilingualDescription)
45
- multilingualDescription[:descriptions].select{|o| o[:lang] == "en"}.first[:desc]
46
- end
47
- end
44
+ private
48
45
 
49
- def french_description
46
+ def extend_model_methods
50
47
  if self.respond_to?(:multilingualDescription)
51
- multilingualDescription[:descriptions].select{|o| o[:lang] == "fr"}.first[:desc]
48
+ extend MultiLingualDescription
49
+ end
50
+ if self.respond_to?(:multilingualTitle)
51
+ extend MultiLingualTitle
52
52
  end
53
53
  end
54
54
 
55
- private
56
-
57
55
  def on_before_create
58
56
  self.attributes.delete_if { |k, v| v.nil? || v == "" }
59
57
  self.attributes = self.attributes.deep_symbolize_keys
@@ -46,22 +46,6 @@ module Dina
46
46
  ]
47
47
  end
48
48
 
49
- def english_description=(desc)
50
- description[:en] = desc
51
- end
52
-
53
- def english_description
54
- description[:en]
55
- end
56
-
57
- def french_description=(desc)
58
- description[:fr] = desc
59
- end
60
-
61
- def french_description
62
- description[:fr]
63
- end
64
-
65
49
  private
66
50
 
67
51
  def on_before_save
@@ -0,0 +1,18 @@
1
+ module Dina
2
+ module MultiLingualDescription
3
+
4
+ # Adds or updates a multilingualDescription with a language key
5
+ #
6
+ # @param opts [Hash] the description expessed as { en: "My description" }
7
+ def set_multilingualDescription(opts = {})
8
+ if self.multilingualDescription.nil?
9
+ self.multilingualDescription = opts
10
+ else
11
+ descriptions = multilingualDescription["descriptions"]
12
+ descriptions.delete_if{|o| o["lang"] == opts.keys[0].to_s}
13
+ descriptions << { "lang" => opts.keys[0].to_s, "desc" => opts[opts.keys[0]] }
14
+ end
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module Dina
2
+ module MultiLingualTitle
3
+
4
+ # Adds or updates a multilingualTitle with a language key
5
+ #
6
+ # @param opts [Hash] the title expessed as { en: "My title" }
7
+ def set_multilingualTitle(opts = {})
8
+ if self.multilingualTitle.nil?
9
+ self.multilingualTitle = opts
10
+ else
11
+ titles = multilingualTitle["titles"]
12
+ titles.delete_if{|o| o["lang"] == opts.keys[0].to_s}
13
+ titles << { "lang" => opts.keys[0].to_s, "title" => opts[opts.keys[0]] }
14
+ end
15
+ end
16
+
17
+ end
18
+ end
data/lib/dina/version.rb CHANGED
@@ -3,7 +3,7 @@ module Dina
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 7
6
- PATCH = 3
6
+ PATCH = 5
7
7
  BUILD = 0
8
8
 
9
9
  def self.version
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dina
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3.0
4
+ version: 0.7.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David P. Shorthouse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-04 00:00:00.000000000 Z
11
+ date: 2023-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_api_client
@@ -199,6 +199,8 @@ files:
199
199
  - lib/dina/search/search_mapping.rb
200
200
  - lib/dina/utils/identifier.rb
201
201
  - lib/dina/utils/identifier_type.rb
202
+ - lib/dina/utils/multi_lingual_description.rb
203
+ - lib/dina/utils/multi_lingual_title.rb
202
204
  - lib/dina/version.rb
203
205
  homepage: https://github.com/dshorthouse/dina
204
206
  licenses: