Class: Uniword::Protect::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/protect/manager.rb

Overview

Manages document protection settings.

Provides operations for setting editing restrictions and password protection on documents.

Protection types:

  • :read_only — no edits allowed

  • :comments — only comments allowed

  • :tracked_changes — only tracked changes allowed

  • :forms — only form fields editable

Examples:

Set read-only protection

manager = Manager.new(doc)
manager.apply(:read_only, password: "secret")

Remove protection

manager.remove

Constant Summary collapse

PROTECTION_TYPES =
%i[
  read_only
  comments
  tracked_changes
  forms
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ Manager

Initialize with a document.

Parameters:



35
36
37
38
# File 'lib/uniword/protect/manager.rb', line 35

def initialize(document)
  @document = document
  @protection = nil
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



30
31
32
# File 'lib/uniword/protect/manager.rb', line 30

def document
  @document
end

Instance Method Details

#apply(protection_type, password: nil) ⇒ void

This method returns an undefined value.

Apply editing restriction to the document.

Parameters:

  • protection_type (Symbol)

    One of PROTECTION_TYPES

  • password (String, nil) (defaults to: nil)

    Optional password

Raises:

  • (ArgumentError)

    If protection_type is invalid



46
47
48
49
50
# File 'lib/uniword/protect/manager.rb', line 46

def apply(protection_type, password: nil)
  validate_type(protection_type)

  @protection = build_protection(protection_type, password)
end

#infoHash?

Get current protection info.

Returns:

  • (Hash, nil)

    Protection details or nil



69
70
71
72
73
74
75
76
# File 'lib/uniword/protect/manager.rb', line 69

def info
  return nil unless @protection

  {
    type: protection_type(@protection),
    password_protected: password_protected?(@protection),
  }
end

#protected?Boolean

Check if the document is protected.

Returns:

  • (Boolean)


62
63
64
# File 'lib/uniword/protect/manager.rb', line 62

def protected?
  !@protection.nil?
end

#removevoid

This method returns an undefined value.

Remove all protection from the document.



55
56
57
# File 'lib/uniword/protect/manager.rb', line 55

def remove
  @protection = nil
end