code0-license 0.1.1 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a281a7c0e54d55b72eaf40910fe789b9cb96418b57611fe1e26cefc1601867a
4
- data.tar.gz: 4e286be7e8834df304decea922f0c94ddd63f2db2f2359a1c4eabc4dc2e6d547
3
+ metadata.gz: 58f84fcd4c3ba444e2b5c22ba55e7b995b61254815f08743ad18a2851cfe335f
4
+ data.tar.gz: 945497d44a33b64539d98d39183eb2c5f83a36f4d03748be2c108f800bf775b3
5
5
  SHA512:
6
- metadata.gz: 0e279582f67cb3fd5169f12b6f29f59806a54cbe12efaab812cd251ea59ebc1f84f5af6e49e0987c489dabd64bd19e33e3800ba8e06a4321e1212f937ced43f1
7
- data.tar.gz: ca090b9bd571ca362d3cf86eeed045aceb8f600e7adb72587f39dd65d7352df2c415c2990f7c4f74895a5a3f844bd68cbd10e1bb22074b2185b4c529daae4222
6
+ metadata.gz: d3a0196b5a041a75638280cbc84ec8f80e612efd4207fac969748ecf7f1d6c7e83c3848b422f27b4ecc10dea22af940694226efe0f705a8dc268c0bf7b824315
7
+ data.tar.gz: 425ae6074bf97210643a8fe21811f67471cc736fcc9d19a5af105f065de18c782991b9176ed00a306f15dd445627b4ae5d16c1d9d2d7c750d256d049acb8aff9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code0-license (0.1.1)
4
+ code0-license (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Code0
4
4
  class License
5
- VERSION = "0.1.1"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
data/lib/code0/license.rb CHANGED
@@ -28,7 +28,7 @@ module Code0
28
28
 
29
29
  decrypted_license = encryptor.decrypt(data)
30
30
 
31
- new(JSON.parse(decrypted_license))
31
+ new(JSON.parse(decrypted_license, symbolize_names: true))
32
32
  rescue JSON::ParserError
33
33
  raise ValidationError, "License data is invalid JSON"
34
34
  end
@@ -60,19 +60,23 @@ module Code0
60
60
  def valid?
61
61
  return false if !licensee || !licensee.is_a?(Hash) || licensee.empty?
62
62
  return false if !start_date || !start_date.is_a?(Date)
63
- return false if (!end_date || !end_date.is_a?(Date)) && !options["allow_missing_end_date"]
63
+ return false if (!end_date || !end_date.is_a?(Date)) && !options[:allow_missing_end_date]
64
64
 
65
65
  true
66
66
  end
67
67
 
68
68
  def in_active_time?
69
69
  return false if start_date > Date.today
70
- return true if !end_date && options["allow_missing_end_date"]
71
- return false if !end_date && !options["allow_missing_end_date"]
70
+ return true if !end_date && options[:allow_missing_end_date]
71
+ return false if !end_date && !options[:allow_missing_end_date]
72
72
 
73
73
  end_date >= Date.today
74
74
  end
75
75
 
76
+ def restricted?(attribute)
77
+ restrictions.key?(attribute)
78
+ end
79
+
76
80
  def data
77
81
  ATTRIBUTES.to_h { |attr| [attr, send(attr)] }
78
82
  end
@@ -82,15 +86,15 @@ module Code0
82
86
  attr_writer(*ATTRIBUTES)
83
87
 
84
88
  def assign_attributes(data)
85
- %w[start_date end_date].each do |property|
89
+ %i[start_date end_date].each do |property|
86
90
  value = data[property]
87
91
  value = parse_date(data[property]) unless data[property].is_a?(Date)
88
92
  send("#{property}=", value)
89
93
  end
90
94
 
91
- send("licensee=", data["licensee"])
92
- send("restrictions=", data["restrictions"] || {})
93
- send("options=", data["options"] || {})
95
+ send("licensee=", data[:licensee])
96
+ send("restrictions=", data[:restrictions] || {})
97
+ send("options=", data[:options] || {})
94
98
  end
95
99
 
96
100
  def parse_date(str)
@@ -18,11 +18,13 @@ module Code0
18
18
 
19
19
  def in_active_time?: -> bool
20
20
 
21
+ def restricted?: (Symbol) -> bool
22
+
21
23
  def valid?: -> bool
22
24
 
23
25
  private
24
26
 
25
- def assign_attributes: (Hash[String, any]) -> void
27
+ def assign_attributes: (Hash[Symbol, any]) -> void
26
28
 
27
29
  def parse_date: (String) -> Date?
28
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code0-license
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Niklas van Schrick
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-09 00:00:00.000000000 Z
11
+ date: 2024-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake