Class: Bequest::License
- Inherits:
-
Object
- Object
- Bequest::License
- Defined in:
- lib/bequest/license.rb
Instance Attribute Summary collapse
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #expired? ⇒ Boolean
-
#initialize(status, expires_at) ⇒ License
constructor
A new instance of License.
- #valid? ⇒ Boolean
Constructor Details
#initialize(status, expires_at) ⇒ License
Returns a new instance of License.
5 6 7 8 |
# File 'lib/bequest/license.rb', line 5 def initialize(status, expires_at) @status = status @expires_at = expires_at end |
Instance Attribute Details
#expires_at ⇒ Object (readonly)
Returns the value of attribute expires_at.
3 4 5 |
# File 'lib/bequest/license.rb', line 3 def expires_at @expires_at end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
3 4 5 |
# File 'lib/bequest/license.rb', line 3 def status @status end |
Class Method Details
.create(data_path, out_path, opts = {}) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/bequest/license.rb', line 11 def create(data_path, out_path, opts = {}) if (opts[:password]||'').any? || (opts[:mac_addr]||'').any? Data.new(File.read(data_path), opts).dump(out_path) else puts "At least ONE of password or mac_addr required" end end |
.load(lic_file_path, opts = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/bequest/license.rb', line 19 def load(lic_file_path, opts = {}) begin data = Marshal::load(File.read(lic_file_path)) original_data, status, expires_at = data.unpack(opts[:password], opts[:mac_addr]) [self.new(status, expires_at), original_data] rescue [self.new(:tampered, nil), nil] end end |
Instance Method Details
#expired? ⇒ Boolean
34 35 36 |
# File 'lib/bequest/license.rb', line 34 def expired? expires_at ? expires_at < Time.now : nil end |
#valid? ⇒ Boolean
30 31 32 |
# File 'lib/bequest/license.rb', line 30 def valid? @status == :ok end |