lib/key_master.rb in cocoapods-keys-0.9.5 vs lib/key_master.rb in cocoapods-keys-1.0.0
- old
+ new
@@ -19,30 +19,36 @@
# Generate a base64 hash string that is ~25 times the length of all keys
@data_length = @keys.values.map(&:length).reduce(:+) * (20 + rand(10))
data = `head -c #{@data_length} /dev/random | base64 | head -c #{@data_length}`
- length = data.length
+ data = data + '\\"'
+ @data_length = data.length
# Swap the characters within the hashed string with the characters from
# the keyring values. Then store that index in a index-ed copy of the values.
@keys.each do |key, value|
@indexed_keys[key] = []
value.chars.each_with_index do |char, char_index|
loop do
- index = rand data.length
- unless @used_indexes.include?(index)
- data[index] = char
-
- @used_indexes << index
+ if char == '"'
+ index = data.delete('\\').length - 1
@indexed_keys[key][char_index] = index
break
- end
+ else
+ index = rand data.length
+ unless @used_indexes.include?(index)
+ data[index] = char
+ @used_indexes << index
+ @indexed_keys[key][char_index] = index
+ break
+ end
+ end
end
end
end
data
@@ -77,10 +83,11 @@
// on #{Time.now.strftime("%d/%m/%Y")}
// For more information see https://github.com/cocoapods/cocoapods-keys
//
#import <objc/runtime.h>
+#import <Foundation/NSDictionary.h>
#import "<%= @name %>.h"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wincomplete-implementation"
@@ -119,20 +126,34 @@
}
<% end %>
static char <%= name %>Data[<%= @data_length %>] = "<%= @data %>";
+- (NSString *)description
+{
+ return [@{
+<%- @keys.each do |key, value| -%>
+ @"<%= key %>": self.<%= key %>,
+<%- end -%>
+ } description];
+}
+
+- (id)debugQuickLookObject
+{
+ return [self description];
+}
+
@end
SOURCE
render_erb(erb)
end
:private
def render_erb(erb)
require 'erb'
- ERB.new(erb).result(binding)
+ ERB.new(erb, nil, '-').result(binding)
end
def key_data_arrays
Hash[@indexed_keys.map {|key, value| [key, value.map { |i| name + "Data[#{i}]" }.join(', ')]}]
end