Class: Anyway::EJSONParser
- Inherits:
-
Object
- Object
- Anyway::EJSONParser
- Defined in:
- lib/anyway/ejson_parser.rb
Instance Attribute Summary collapse
-
#bin_path ⇒ Object
readonly
Returns the value of attribute bin_path.
Instance Method Summary collapse
- #call(file_path) ⇒ Object
-
#initialize(bin_path = "ejson") ⇒ EJSONParser
constructor
A new instance of EJSONParser.
Constructor Details
#initialize(bin_path = "ejson") ⇒ EJSONParser
Returns a new instance of EJSONParser.
12 13 14 |
# File 'lib/anyway/ejson_parser.rb', line 12 def initialize(bin_path = "ejson") @bin_path = bin_path end |
Instance Attribute Details
#bin_path ⇒ Object (readonly)
Returns the value of attribute bin_path.
10 11 12 |
# File 'lib/anyway/ejson_parser.rb', line 10 def bin_path @bin_path end |
Instance Method Details
#call(file_path) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/anyway/ejson_parser.rb', line 16 def call(file_path) return unless File.exist?(file_path) raw_content = nil stdout, stderr, status = Open3.capture3("#{bin_path} decrypt #{file_path}") if status.success? raw_content = JSON.parse(stdout.chomp) else Kernel.warn "Failed to decrypt #{file_path}: #{stderr}" end return unless raw_content raw_content.deep_transform_keys do |key| if key[0] == "_" key[1..] else key end end end |