lib/evercookie/controller.rb in evercookie-0.0.5 vs lib/evercookie/controller.rb in evercookie-0.0.6
- old
+ new
@@ -28,21 +28,23 @@
# == Examples:
# evercookie_is_set?(:key)
# evercookie_is_set?(:key, :value)
#
def evercookie_is_set?(key, value = nil)
- if value.nil?
+ if session[Evercookie.hash_name_for_saved].blank?
+ false
+ elsif value.nil?
session[Evercookie.hash_name_for_saved][key].present?
else
session[Evercookie.hash_name_for_saved][key].present? \
&& session[Evercookie.hash_name_for_saved][key] == value
end
end
end
# controller class defines evercookie actions
- class EvercookieController < ::ApplicationController
+ class EvercookieController < ::ActionController::Base
# Renders javascript with evercookie set script
def set
@data = session[Evercookie.hash_name_for_set] || {key: '', value: ''}
end
@@ -109,23 +111,24 @@
value = cookies[Evercookie.cookie_png]
require 'chunky_png'
image = ChunkyPNG::Image.new(200, 1, ChunkyPNG::Color::BLACK)
- pixel = 0
- while (index = pixel * 3) < value.length
- red = value[index] ? value[index].ord : 0
- green = value[index + 1] ? value[index + 1].ord : 0
- blue = value[index + 2] ? value[index + 2].ord : 0
-
- image[pixel, 0] = ChunkyPNG::Color.rgb(red, green, blue)
-
- pixel += 1
+ (0..value.length).step(3) do |index|
+ image[(index / 3).round, 0] = get_pixel_by_index(value, index)
end
image.to_blob(
{color_mode: ChunkyPNG::COLOR_TRUECOLOR,
compression: Zlib::DEFAULT_COMPRESSION}
)
+ end
+
+ def get_pixel_by_index(value, index)
+ red = value[index] ? value[index].ord : 0
+ green = value[index + 1] ? value[index + 1].ord : 0
+ blue = value[index + 2] ? value[index + 2].ord : 0
+
+ ChunkyPNG::Color.rgb(red, green, blue)
end
end
end