Class: EJSON::Data
Instance Attribute Summary collapse
-
#encryption ⇒ Object
readonly
Returns the value of attribute encryption.
Instance Method Summary collapse
- #decrypt_all(data = @data) ⇒ Object
- #dump ⇒ Object
- #encrypt_all(data = @data) ⇒ Object
-
#initialize(data, encryption) ⇒ Data
constructor
A new instance of Data.
Constructor Details
#initialize(data, encryption) ⇒ Data
Returns a new instance of Data.
22 23 24 |
# File 'lib/ejson.rb', line 22 def initialize(data, encryption) @data, @encryption = data, encryption end |
Instance Attribute Details
#encryption ⇒ Object (readonly)
Returns the value of attribute encryption.
21 22 23 |
# File 'lib/ejson.rb', line 21 def encryption @encryption end |
Instance Method Details
#decrypt_all(data = @data) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ejson.rb', line 43 def decrypt_all(data=@data) case data when Hash Hash[ data.map { |k,v| [k, decrypt_all(v)] } ] when Array data.map { |d| decrypt_all(d) } when String encryption.load(data) else data end end |
#dump ⇒ Object
26 27 28 |
# File 'lib/ejson.rb', line 26 def dump JSON.pretty_generate(encrypt_all(@data)) end |
#encrypt_all(data = @data) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ejson.rb', line 30 def encrypt_all(data=@data) case data when Hash Hash[ data.map { |k,v| [k, encrypt_all(v)] } ] when Array data.map { |d| encrypt_all(d) } when String encryption.dump(data) else data end end |