evercookie 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +127 -0
- data/Rakefile +38 -0
- data/app/assets/images/ec.swf +0 -0
- data/app/assets/javascripts/ec.js +2 -0
- data/app/assets/javascripts/evercookie/evercookie.js.erb +704 -0
- data/app/assets/javascripts/evercookie/swfobject-2.2.min.js +4 -0
- data/app/views/evercookie/evercookie/get.js.erb +2 -0
- data/app/views/evercookie/evercookie/set.js.erb +2 -0
- data/config/routes.rb +20 -0
- data/lib/evercookie.rb +85 -0
- data/lib/evercookie/controller.rb +122 -0
- data/lib/evercookie/engine.rb +17 -0
- data/lib/evercookie/version.rb +4 -0
- data/lib/evercookie/view.rb +25 -0
- data/lib/tasks/evercookie_tasks.rake +4 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/javascripts/index.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/assets/stylesheets/index.css +4 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/index_controller.rb +24 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/index_helper.rb +2 -0
- data/test/dummy/app/views/index/get.html.erb +5 -0
- data/test/dummy/app/views/index/get_detailed.html.erb +26 -0
- data/test/dummy/app/views/index/index.html.erb +36 -0
- data/test/dummy/app/views/index/set.html.erb +3 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/evercookie.rb +8 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +10 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +30554 -0
- data/test/dummy/log/test.log +1516 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/functional/index_controller_test.rb +7 -0
- data/test/dummy/test/unit/helpers/index_helper_test.rb +4 -0
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/CEC/FA0/sprockets%2Fcee8c6b09c33d2b276753e959712724e +0 -0
- data/test/dummy/tmp/cache/assets/D2F/760/sprockets%2F3b464ead21d28d0a1298357a3a7cbc18 +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D45/3C0/sprockets%2Fd45fb0f5f994f0c125db5e026ee65258 +0 -0
- data/test/dummy/tmp/cache/assets/D45/C10/sprockets%2Fac34f7046872aba24b7375de608d8fe6 +0 -0
- data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/D70/2D0/sprockets%2F2c853768baf811357d81d41bdfd05dcf +0 -0
- data/test/dummy/tmp/cache/assets/D70/D10/sprockets%2Fa0d37ff489ed0857f72233f5cb0b9c0b +0 -0
- data/test/dummy/tmp/cache/assets/D8C/A10/sprockets%2Ffc7201c6cbef32453aa4175c520c8eae +0 -0
- data/test/dummy/tmp/cache/assets/D93/360/sprockets%2Fdf600f50f002512c95d93bcfbab891ed +0 -0
- data/test/dummy/tmp/cache/assets/D99/2F0/sprockets%2Fa2cf2651c63ecb32c21ea94fa84cd498 +0 -0
- data/test/dummy/tmp/cache/assets/DAA/C00/sprockets%2F9bddc9410e086be5f5efa982c5247c7b +0 -0
- data/test/dummy/tmp/cache/assets/DCF/EC0/sprockets%2Fe1f34cd8fd7ca6a9a01d26e47c923f1f +0 -0
- data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/DEE/200/sprockets%2F2a3f3abddecb0467eb2d7d5cf5f52302 +0 -0
- data/test/dummy/tmp/cache/assets/DFF/960/sprockets%2Fe73aa53de71d957ef04bdfd2fba2e915 +0 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/E83/750/sprockets%2Fe0a4c2b9c4acf9bcfedbb42a8bd45e80 +0 -0
- data/test/evercookie_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- data/test/unit/controllers/evercookie_controller_test.rb +86 -0
- data/test/unit/helpers/evercookie_controller_helper_test.rb +11 -0
- data/test/unit/helpers/evercookie_view_helper_test.rb +28 -0
- metadata +236 -0
@@ -0,0 +1,4 @@
|
|
1
|
+
/* SWFObject v2.2 <http://code.google.com/p/swfobject/>
|
2
|
+
is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
|
3
|
+
*/
|
4
|
+
var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="ShockwaveFlash.ShockwaveFlash",q="application/x-shockwave-flash",R="SWFObjectExprInst",x="onreadystatechange",O=window,j=document,t=navigator,T=false,U=[h],o=[],N=[],I=[],l,Q,E,B,J=false,a=false,n,G,m=true,M=function(){var aa=typeof j.getElementById!=D&&typeof j.getElementsByTagName!=D&&typeof j.createElement!=D,ah=t.userAgent.toLowerCase(),Y=t.platform.toLowerCase(),ae=Y?/win/.test(Y):/win/.test(ah),ac=Y?/mac/.test(Y):/mac/.test(ah),af=/webkit/.test(ah)?parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,X=!+"\v1",ag=[0,0,0],ab=null;if(typeof t.plugins!=D&&typeof t.plugins[S]==r){ab=t.plugins[S].description;if(ab&&!(typeof t.mimeTypes!=D&&t.mimeTypes[q]&&!t.mimeTypes[q].enabledPlugin)){T=true;X=false;ab=ab.replace(/^.*\s+(\S+\s+\S+$)/,"$1");ag[0]=parseInt(ab.replace(/^(.*)\..*$/,"$1"),10);ag[1]=parseInt(ab.replace(/^.*\.(.*)\s.*$/,"$1"),10);ag[2]=/[a-zA-Z]/.test(ab)?parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0}}else{if(typeof O.ActiveXObject!=D){try{var ad=new ActiveXObject(W);if(ad){ab=ad.GetVariable("$version");if(ab){X=true;ab=ab.split(" ")[1].split(",");ag=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}}catch(Z){}}}return{w3:aa,pv:ag,wk:af,ie:X,win:ae,mac:ac}}(),k=function(){if(!M.w3){return}if((typeof j.readyState!=D&&j.readyState=="complete")||(typeof j.readyState==D&&(j.getElementsByTagName("body")[0]||j.body))){f()}if(!J){if(typeof j.addEventListener!=D){j.addEventListener("DOMContentLoaded",f,false)}if(M.ie&&M.win){j.attachEvent(x,function(){if(j.readyState=="complete"){j.detachEvent(x,arguments.callee);f()}});if(O==top){(function(){if(J){return}try{j.documentElement.doScroll("left")}catch(X){setTimeout(arguments.callee,0);return}f()})()}}if(M.wk){(function(){if(J){return}if(!/loaded|complete/.test(j.readyState)){setTimeout(arguments.callee,0);return}f()})()}s(f)}}();function f(){if(J){return}try{var Z=j.getElementsByTagName("body")[0].appendChild(C("span"));Z.parentNode.removeChild(Z)}catch(aa){return}J=true;var X=U.length;for(var Y=0;Y<X;Y++){U[Y]()}}function K(X){if(J){X()}else{U[U.length]=X}}function s(Y){if(typeof O.addEventListener!=D){O.addEventListener("load",Y,false)}else{if(typeof j.addEventListener!=D){j.addEventListener("load",Y,false)}else{if(typeof O.attachEvent!=D){i(O,"onload",Y)}else{if(typeof O.onload=="function"){var X=O.onload;O.onload=function(){X();Y()}}else{O.onload=Y}}}}}function h(){if(T){V()}else{H()}}function V(){var X=j.getElementsByTagName("body")[0];var aa=C(r);aa.setAttribute("type",q);var Z=X.appendChild(aa);if(Z){var Y=0;(function(){if(typeof Z.GetVariable!=D){var ab=Z.GetVariable("$version");if(ab){ab=ab.split(" ")[1].split(",");M.pv=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}else{if(Y<10){Y++;setTimeout(arguments.callee,10);return}}X.removeChild(aa);Z=null;H()})()}else{H()}}function H(){var ag=o.length;if(ag>0){for(var af=0;af<ag;af++){var Y=o[af].id;var ab=o[af].callbackFn;var aa={success:false,id:Y};if(M.pv[0]>0){var ae=c(Y);if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa)}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class")}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align")}var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad<ac;ad++){if(X[ad].getAttribute("name").toLowerCase()!="movie"){ah[X[ad].getAttribute("name")]=X[ad].getAttribute("value")}}P(ai,ah,Y,ab)}else{p(ae);if(ab){ab(aa)}}}}}else{w(Y,true);if(ab){var Z=z(Y);if(Z&&typeof Z.SetVariable!=D){aa.success=true;aa.ref=Z}ab(aa)}}}}}function z(aa){var X=null;var Y=c(aa);if(Y&&Y.nodeName=="OBJECT"){if(typeof Y.SetVariable!=D){X=Y}else{var Z=Y.getElementsByTagName(r)[0];if(Z){X=Z}}}return X}function A(){return !a&&F("6.0.65")&&(M.win||M.mac)&&!(M.wk&&M.wk<312)}function P(aa,ab,X,Z){a=true;E=Z||null;B={success:false,id:X};var ae=c(X);if(ae){if(ae.nodeName=="OBJECT"){l=g(ae);Q=null}else{l=ae;Q=X}aa.id=R;if(typeof aa.width==D||(!/%$/.test(aa.width)&&parseInt(aa.width,10)<310)){aa.width="310"}if(typeof aa.height==D||(!/%$/.test(aa.height)&&parseInt(aa.height,10)<137)){aa.height="137"}j.title=j.title.slice(0,47)+" - Flash Player Installation";var ad=M.ie&&M.win?"ActiveX":"PlugIn",ac="MMredirectURL="+O.location.toString().replace(/&/g,"%26")+"&MMplayerType="+ad+"&MMdoctitle="+j.title;if(typeof ab.flashvars!=D){ab.flashvars+="&"+ac}else{ab.flashvars=ac}if(M.ie&&M.win&&ae.readyState!=4){var Y=C("div");X+="SWFObjectNew";Y.setAttribute("id",X);ae.parentNode.insertBefore(Y,ae);ae.style.display="none";(function(){if(ae.readyState==4){ae.parentNode.removeChild(ae)}else{setTimeout(arguments.callee,10)}})()}u(aa,ab,X)}}function p(Y){if(M.ie&&M.win&&Y.readyState!=4){var X=C("div");Y.parentNode.insertBefore(X,Y);X.parentNode.replaceChild(g(Y),X);Y.style.display="none";(function(){if(Y.readyState==4){Y.parentNode.removeChild(Y)}else{setTimeout(arguments.callee,10)}})()}else{Y.parentNode.replaceChild(g(Y),Y)}}function g(ab){var aa=C("div");if(M.win&&M.ie){aa.innerHTML=ab.innerHTML}else{var Y=ab.getElementsByTagName(r)[0];if(Y){var ad=Y.childNodes;if(ad){var X=ad.length;for(var Z=0;Z<X;Z++){if(!(ad[Z].nodeType==1&&ad[Z].nodeName=="PARAM")&&!(ad[Z].nodeType==8)){aa.appendChild(ad[Z].cloneNode(true))}}}}}return aa}function u(ai,ag,Y){var X,aa=c(Y);if(M.wk&&M.wk<312){return X}if(aa){if(typeof ai.id==D){ai.id=Y}if(M.ie&&M.win){var ah="";for(var ae in ai){if(ai[ae]!=Object.prototype[ae]){if(ae.toLowerCase()=="data"){ag.movie=ai[ae]}else{if(ae.toLowerCase()=="styleclass"){ah+=' class="'+ai[ae]+'"'}else{if(ae.toLowerCase()!="classid"){ah+=" "+ae+'="'+ai[ae]+'"'}}}}}var af="";for(var ad in ag){if(ag[ad]!=Object.prototype[ad]){af+='<param name="'+ad+'" value="'+ag[ad]+'" />'}}aa.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+ah+">"+af+"</object>";N[N.length]=ai.id;X=c(ai.id)}else{var Z=C(r);Z.setAttribute("type",q);for(var ac in ai){if(ai[ac]!=Object.prototype[ac]){if(ac.toLowerCase()=="styleclass"){Z.setAttribute("class",ai[ac])}else{if(ac.toLowerCase()!="classid"){Z.setAttribute(ac,ai[ac])}}}}for(var ab in ag){if(ag[ab]!=Object.prototype[ab]&&ab.toLowerCase()!="movie"){e(Z,ab,ag[ab])}}aa.parentNode.replaceChild(Z,aa);X=Z}}return X}function e(Z,X,Y){var aa=C("param");aa.setAttribute("name",X);aa.setAttribute("value",Y);Z.appendChild(aa)}function y(Y){var X=c(Y);if(X&&X.nodeName=="OBJECT"){if(M.ie&&M.win){X.style.display="none";(function(){if(X.readyState==4){b(Y)}else{setTimeout(arguments.callee,10)}})()}else{X.parentNode.removeChild(X)}}}function b(Z){var Y=c(Z);if(Y){for(var X in Y){if(typeof Y[X]=="function"){Y[X]=null}}Y.parentNode.removeChild(Y)}}function c(Z){var X=null;try{X=j.getElementById(Z)}catch(Y){}return X}function C(X){return j.createElement(X)}function i(Z,X,Y){Z.attachEvent(X,Y);I[I.length]=[Z,X,Y]}function F(Z){var Y=M.pv,X=Z.split(".");X[0]=parseInt(X[0],10);X[1]=parseInt(X[1],10)||0;X[2]=parseInt(X[2],10)||0;return(Y[0]>X[0]||(Y[0]==X[0]&&Y[1]>X[1])||(Y[0]==X[0]&&Y[1]==X[1]&&Y[2]>=X[2]))?true:false}function v(ac,Y,ad,ab){if(M.ie&&M.mac){return}var aa=j.getElementsByTagName("head")[0];if(!aa){return}var X=(ad&&typeof ad=="string")?ad:"screen";if(ab){n=null;G=null}if(!n||G!=X){var Z=C("style");Z.setAttribute("type","text/css");Z.setAttribute("media",X);n=aa.appendChild(Z);if(M.ie&&M.win&&typeof j.styleSheets!=D&&j.styleSheets.length>0){n=j.styleSheets[j.styleSheets.length-1]}G=X}if(M.ie&&M.win){if(n&&typeof n.addRule==r){n.addRule(ac,Y)}}else{if(n&&typeof j.createTextNode!=D){n.appendChild(j.createTextNode(ac+" {"+Y+"}"))}}}function w(Z,X){if(!m){return}var Y=X?"visible":"hidden";if(J&&c(Z)){c(Z).style.visibility=Y}else{v("#"+Z,"visibility:"+Y)}}function L(Y){var Z=/[\\\"<>\.;]/;var X=Z.exec(Y)!=null;return X&&typeof encodeURIComponent!=D?encodeURIComponent(Y):Y}var d=function(){if(M.ie&&M.win){window.attachEvent("onunload",function(){var ac=I.length;for(var ab=0;ab<ac;ab++){I[ab][0].detachEvent(I[ab][1],I[ab][2])}var Z=N.length;for(var aa=0;aa<Z;aa++){y(N[aa])}for(var Y in M){M[Y]=null}M=null;for(var X in swfobject){swfobject[X]=null}swfobject=null})}}();return{registerObject:function(ab,X,aa,Z){if(M.w3&&ab&&X){var Y={};Y.id=ab;Y.swfVersion=X;Y.expressInstall=aa;Y.callbackFn=Z;o[o.length]=Y;w(ab,false)}else{if(Z){Z({success:false,id:ab})}}},getObjectById:function(X){if(M.w3){return z(X)}},embedSWF:function(ab,ah,ae,ag,Y,aa,Z,ad,af,ac){var X={success:false,id:ah};if(M.w3&&!(M.wk&&M.wk<312)&&ab&&ah&&ae&&ag&&Y){w(ah,false);K(function(){ae+="";ag+="";var aj={};if(af&&typeof af===r){for(var al in af){aj[al]=af[al]}}aj.data=ab;aj.width=ae;aj.height=ag;var am={};if(ad&&typeof ad===r){for(var ak in ad){am[ak]=ad[ak]}}if(Z&&typeof Z===r){for(var ai in Z){if(typeof am.flashvars!=D){am.flashvars+="&"+ai+"="+Z[ai]}else{am.flashvars=ai+"="+Z[ai]}}}if(F(Y)){var an=u(aj,am,ah);if(aj.id==ah){w(ah,true)}X.success=true;X.ref=an}else{if(aa&&A()){aj.data=aa;P(aj,am,ah,ac);return}else{w(ah,true)}}if(ac){ac(X)}})}else{if(ac){ac(X)}}},switchOffAutoHideShow:function(){m=false},ua:M,getFlashPlayerVersion:function(){return{major:M.pv[0],minor:M.pv[1],release:M.pv[2]}},hasFlashPlayerVersion:F,createSWF:function(Z,Y,X){if(M.w3){return u(Z,Y,X)}else{return undefined}},showExpressInstall:function(Z,aa,X,Y){if(M.w3&&A()){P(Z,aa,X,Y)}},removeSWF:function(X){if(M.w3){y(X)}},createCSS:function(aa,Z,Y,X){if(M.w3){v(aa,Z,Y,X)}},addDomLoadEvent:K,addLoadEvent:s,getQueryParamValue:function(aa){var Z=j.location.search||j.location.hash;if(Z){if(/\?/.test(Z)){Z=Z.split("?")[1]}if(aa==null){return L(Z)}var Y=Z.split("&");for(var X=0;X<Y.length;X++){if(Y[X].substring(0,Y[X].indexOf("="))==aa){return L(Y[X].substring((Y[X].indexOf("=")+1)))}}}return""},expressInstallCallback:function(){if(a){var X=c(R);if(X&&l){X.parentNode.replaceChild(l,X);if(Q){w(Q,true);if(M.ie&&M.win){l.style.display="block"}}if(E){E(B)}}a=false}}}}();
|
data/config/routes.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
|
3
|
+
# Adds routes for evercookie under namespace (path)
|
4
|
+
scope "#{Evercookie.get_namespace}" do
|
5
|
+
# route for js file to set cookie
|
6
|
+
match 'set' => "evercookie/evercookie#set", as: :evercookie_set
|
7
|
+
# route for js file to get cookie
|
8
|
+
match 'get' => "evercookie/evercookie#get", as: :evercookie_get
|
9
|
+
# route for save action to save cookie value to session
|
10
|
+
match 'save' => "evercookie/evercookie#save", as: :evercookie_save
|
11
|
+
|
12
|
+
# route to png image to be tracked by js script
|
13
|
+
match 'ec_png' => "evercookie/evercookie#ec_png", as: :evercookie_png
|
14
|
+
# route to etag action to be tracked by js script
|
15
|
+
match 'ec_etag' => "evercookie/evercookie#ec_etag", as: :evercookie_etag
|
16
|
+
# route to cache action to be tracked by js script
|
17
|
+
match 'ec_cache' => "evercookie/evercookie#ec_cache", as: :evercookie_cache
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/evercookie.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# main module for evercookie gem
|
2
|
+
module Evercookie
|
3
|
+
# autoload additional classes used by gem
|
4
|
+
autoload :ViewHelper, 'evercookie/view'
|
5
|
+
autoload :ControllerHelpers, 'evercookie/controller'
|
6
|
+
autoload :EvercookieController, 'evercookie/controller'
|
7
|
+
|
8
|
+
# path for controller
|
9
|
+
mattr_accessor :namespace
|
10
|
+
@@namespace = :evercookie
|
11
|
+
|
12
|
+
# name for main js class
|
13
|
+
mattr_accessor :js_class
|
14
|
+
@@js_class = :evercookie
|
15
|
+
|
16
|
+
# name for cookie for cache
|
17
|
+
mattr_accessor :cookie_cache
|
18
|
+
@@cookie_cache = :evercookie_cache
|
19
|
+
|
20
|
+
# name for cookie for etag
|
21
|
+
mattr_accessor :cookie_etag
|
22
|
+
@@cookie_etag = :evercookie_etag
|
23
|
+
|
24
|
+
# name for cookie for png
|
25
|
+
mattr_accessor :cookie_png
|
26
|
+
@@cookie_png = :evercookie_png
|
27
|
+
|
28
|
+
# session hash name prefix
|
29
|
+
mattr_accessor :hash_name
|
30
|
+
@@hash_name = :evercookie
|
31
|
+
|
32
|
+
# default method for setup evercookie
|
33
|
+
def self.setup
|
34
|
+
yield self
|
35
|
+
end
|
36
|
+
|
37
|
+
# getter for namespace
|
38
|
+
def self.get_namespace
|
39
|
+
@@namespace.to_sym
|
40
|
+
end
|
41
|
+
|
42
|
+
# getter for session key variable for set action
|
43
|
+
def self.hash_name_for_set
|
44
|
+
"#{@@hash_name}_set".to_sym
|
45
|
+
end
|
46
|
+
|
47
|
+
# getter for session key variable for get action
|
48
|
+
def self.hash_name_for_get
|
49
|
+
"#{@@hash_name}_get".to_sym
|
50
|
+
end
|
51
|
+
|
52
|
+
# getter for session key variable all stored evercookies
|
53
|
+
def self.hash_name_for_saved
|
54
|
+
"#{@@hash_name}_saved".to_sym
|
55
|
+
end
|
56
|
+
|
57
|
+
# getter for cookie path in javascript because rails controller actions
|
58
|
+
# get cookies only from it's controller path
|
59
|
+
def self.get_cookie_path
|
60
|
+
"/#{get_namespace}/"
|
61
|
+
end
|
62
|
+
|
63
|
+
# getter for path of save action
|
64
|
+
def self.get_save_path
|
65
|
+
"/#{get_namespace}/save"
|
66
|
+
end
|
67
|
+
|
68
|
+
# getter for path of cache action
|
69
|
+
def self.get_cache_path
|
70
|
+
"/#{get_namespace}/ec_cache"
|
71
|
+
end
|
72
|
+
|
73
|
+
# getter for path of etag action
|
74
|
+
def self.get_etag_path
|
75
|
+
"/#{get_namespace}/ec_etag"
|
76
|
+
end
|
77
|
+
|
78
|
+
# getter for path of png action
|
79
|
+
def self.get_png_path
|
80
|
+
"/#{get_namespace}/ec_png"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# extend Rails engine if it's in Rails application
|
85
|
+
require 'evercookie/engine' if defined?(Rails)
|
@@ -0,0 +1,122 @@
|
|
1
|
+
module Evercookie
|
2
|
+
# defines controller helpers
|
3
|
+
module ControllerHelpers
|
4
|
+
|
5
|
+
# Get value of evercookie by key
|
6
|
+
# == Examples:
|
7
|
+
# evercookie_get_value(:key)
|
8
|
+
#
|
9
|
+
def evercookie_get_value(key)
|
10
|
+
if session[Evercookie.hash_name_for_saved].present?
|
11
|
+
session[Evercookie.hash_name_for_saved][key]
|
12
|
+
else
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Checks whether the evercookie with specific key was defined
|
18
|
+
# == Examples:
|
19
|
+
# evercookie_is_set?(:key)
|
20
|
+
# evercookie_is_set?(:key, :value)
|
21
|
+
#
|
22
|
+
def evercookie_is_set?(key, value = nil)
|
23
|
+
if value.nil?
|
24
|
+
session[Evercookie.hash_name_for_saved][key].present?
|
25
|
+
else
|
26
|
+
session[Evercookie.hash_name_for_saved][key].present? \
|
27
|
+
&& session[Evercookie.hash_name_for_saved][key] == value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# controller class defines evercookie actions
|
33
|
+
class EvercookieController < ::ApplicationController
|
34
|
+
|
35
|
+
# Renders javascript with evercookie set script
|
36
|
+
def set
|
37
|
+
@data = session[Evercookie.hash_name_for_set] || {key: '', value: ''}
|
38
|
+
end
|
39
|
+
|
40
|
+
# Renders javascript with evercookie get script
|
41
|
+
def get
|
42
|
+
@data = session[Evercookie.hash_name_for_get] || {key: '', value: ''}
|
43
|
+
end
|
44
|
+
|
45
|
+
# Saves current evercookie value to session
|
46
|
+
def save
|
47
|
+
if session[Evercookie.hash_name_for_get].present?
|
48
|
+
data = session[Evercookie.hash_name_for_get]
|
49
|
+
if data[:key].present? && cookies[data[:key]].present?
|
50
|
+
session[Evercookie.hash_name_for_saved] = {} unless
|
51
|
+
session[Evercookie.hash_name_for_saved].present?
|
52
|
+
|
53
|
+
session[Evercookie.hash_name_for_saved][data[:key]] =
|
54
|
+
cookies[data[:key]]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
render nothing: true
|
58
|
+
end
|
59
|
+
|
60
|
+
# Renders png image with encoded evercookie value in it
|
61
|
+
def ec_png
|
62
|
+
if not cookies[Evercookie.cookie_png].present?
|
63
|
+
render :nothing => true, :status => 304
|
64
|
+
return true
|
65
|
+
end
|
66
|
+
|
67
|
+
value = cookies[Evercookie.cookie_png]
|
68
|
+
|
69
|
+
require 'chunky_png'
|
70
|
+
image = ChunkyPNG::Image.new(200, 1, ChunkyPNG::Color::BLACK)
|
71
|
+
|
72
|
+
pixel = 0
|
73
|
+
while (index = pixel * 3) < value.length
|
74
|
+
red = value[index] ? value[index].ord : 0
|
75
|
+
green = value[index + 1] ? value[index + 1].ord : 0
|
76
|
+
blue = value[index + 2] ? value[index + 2].ord : 0
|
77
|
+
|
78
|
+
image[pixel, 0] = ChunkyPNG::Color.rgb(red, green, blue)
|
79
|
+
|
80
|
+
pixel += 1
|
81
|
+
end
|
82
|
+
|
83
|
+
response.headers["Content-Type"] = "image/png"
|
84
|
+
response.headers["Last-Modified"] = "Wed, 30 Jun 2010 21:36:48 GMT"
|
85
|
+
response.headers["Expires"] = "Tue, 31 Dec 2030 23:30:45 GMT"
|
86
|
+
response.headers["Cache-Control"] = "private, max-age=630720000"
|
87
|
+
|
88
|
+
img_blob = image.to_blob(
|
89
|
+
{color_mode: ChunkyPNG::COLOR_TRUECOLOR,
|
90
|
+
compression: Zlib::DEFAULT_COMPRESSION}
|
91
|
+
)
|
92
|
+
|
93
|
+
render text: img_blob, status: 200, content_type: 'image/png'
|
94
|
+
end
|
95
|
+
|
96
|
+
# Renders page with etag header for evercookie js script
|
97
|
+
def ec_etag
|
98
|
+
if not cookies[Evercookie.cookie_etag].present?
|
99
|
+
render :text => request.headers['If-None-Match'] || '', :status => 304
|
100
|
+
return true
|
101
|
+
end
|
102
|
+
|
103
|
+
response.headers["Etag"] = cookies[Evercookie.cookie_etag]
|
104
|
+
render text: cookies[Evercookie.cookie_etag]
|
105
|
+
end
|
106
|
+
|
107
|
+
# Renders page with cache header for evercookie js script
|
108
|
+
def ec_cache
|
109
|
+
if not cookies[Evercookie.cookie_cache].present?
|
110
|
+
render :nothing => true, :status => 304
|
111
|
+
return true
|
112
|
+
end
|
113
|
+
|
114
|
+
response.headers["Content-Type"] = "text/html"
|
115
|
+
response.headers["Last-Modified"] = "Wed, 30 Jun 2010 21:36:48 GMT"
|
116
|
+
response.headers["Expires"] = "Tue, 31 Dec 2030 23:30:45 GMT"
|
117
|
+
response.headers["Cache-Control"] = "private, max-age=630720000"
|
118
|
+
|
119
|
+
render text: cookies[Evercookie.cookie_cache]
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Evercookie
|
2
|
+
# adds additional things to rails engine
|
3
|
+
module Rails
|
4
|
+
# adds additional things to rails engine
|
5
|
+
class Engine < ::Rails::Engine
|
6
|
+
# adds ec.js to be precompiled
|
7
|
+
initializer "evercookie precompile hook" do |app|
|
8
|
+
app.config.assets.precompile += %w(ec.js)
|
9
|
+
end
|
10
|
+
|
11
|
+
# registers view helpers
|
12
|
+
config.after_initialize do
|
13
|
+
ActionView::Base.send(:include, Evercookie::ViewHelper)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Evercookie
|
2
|
+
# module defines view helpers
|
3
|
+
module ViewHelper
|
4
|
+
|
5
|
+
# Generates javascript for setting evercookie
|
6
|
+
# == Example:
|
7
|
+
# <%= set_evercookie(:key, :value) %>
|
8
|
+
def set_evercookie(key, value)
|
9
|
+
session[Evercookie.hash_name_for_set] = {key: key, value: value}
|
10
|
+
render inline: "<%= javascript_include_tag 'ec', evercookie_set_path -%>"
|
11
|
+
end
|
12
|
+
|
13
|
+
# Generates javascript for checking if evercookie exists and getting it's
|
14
|
+
# value
|
15
|
+
# == Example:
|
16
|
+
# <%= check_evercookie(:key) %>
|
17
|
+
def check_evercookie(key)
|
18
|
+
if not session[Evercookie.hash_name_for_get].present?
|
19
|
+
session[Evercookie.hash_name_for_get] = {}
|
20
|
+
end
|
21
|
+
session[Evercookie.hash_name_for_get][:key] = key
|
22
|
+
render inline: "<%= javascript_include_tag 'ec', evercookie_get_path -%>"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,261 @@
|
|
1
|
+
== Welcome to Rails
|
2
|
+
|
3
|
+
Rails is a web-application framework that includes everything needed to create
|
4
|
+
database-backed web applications according to the Model-View-Control pattern.
|
5
|
+
|
6
|
+
This pattern splits the view (also called the presentation) into "dumb"
|
7
|
+
templates that are primarily responsible for inserting pre-built data in between
|
8
|
+
HTML tags. The model contains the "smart" domain objects (such as Account,
|
9
|
+
Product, Person, Post) that holds all the business logic and knows how to
|
10
|
+
persist themselves to a database. The controller handles the incoming requests
|
11
|
+
(such as Save New Account, Update Product, Show Post) by manipulating the model
|
12
|
+
and directing data to the view.
|
13
|
+
|
14
|
+
In Rails, the model is handled by what's called an object-relational mapping
|
15
|
+
layer entitled Active Record. This layer allows you to present the data from
|
16
|
+
database rows as objects and embellish these data objects with business logic
|
17
|
+
methods. You can read more about Active Record in
|
18
|
+
link:files/vendor/rails/activerecord/README.html.
|
19
|
+
|
20
|
+
The controller and view are handled by the Action Pack, which handles both
|
21
|
+
layers by its two parts: Action View and Action Controller. These two layers
|
22
|
+
are bundled in a single package due to their heavy interdependence. This is
|
23
|
+
unlike the relationship between the Active Record and Action Pack that is much
|
24
|
+
more separate. Each of these packages can be used independently outside of
|
25
|
+
Rails. You can read more about Action Pack in
|
26
|
+
link:files/vendor/rails/actionpack/README.html.
|
27
|
+
|
28
|
+
|
29
|
+
== Getting Started
|
30
|
+
|
31
|
+
1. At the command prompt, create a new Rails application:
|
32
|
+
<tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
|
33
|
+
|
34
|
+
2. Change directory to <tt>myapp</tt> and start the web server:
|
35
|
+
<tt>cd myapp; rails server</tt> (run with --help for options)
|
36
|
+
|
37
|
+
3. Go to http://localhost:3000/ and you'll see:
|
38
|
+
"Welcome aboard: You're riding Ruby on Rails!"
|
39
|
+
|
40
|
+
4. Follow the guidelines to start developing your application. You can find
|
41
|
+
the following resources handy:
|
42
|
+
|
43
|
+
* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
|
44
|
+
* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
|
45
|
+
|
46
|
+
|
47
|
+
== Debugging Rails
|
48
|
+
|
49
|
+
Sometimes your application goes wrong. Fortunately there are a lot of tools that
|
50
|
+
will help you debug it and get it back on the rails.
|
51
|
+
|
52
|
+
First area to check is the application log files. Have "tail -f" commands
|
53
|
+
running on the server.log and development.log. Rails will automatically display
|
54
|
+
debugging and runtime information to these files. Debugging info will also be
|
55
|
+
shown in the browser on requests from 127.0.0.1.
|
56
|
+
|
57
|
+
You can also log your own messages directly into the log file from your code
|
58
|
+
using the Ruby logger class from inside your controllers. Example:
|
59
|
+
|
60
|
+
class WeblogController < ActionController::Base
|
61
|
+
def destroy
|
62
|
+
@weblog = Weblog.find(params[:id])
|
63
|
+
@weblog.destroy
|
64
|
+
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
The result will be a message in your log file along the lines of:
|
69
|
+
|
70
|
+
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
|
71
|
+
|
72
|
+
More information on how to use the logger is at http://www.ruby-doc.org/core/
|
73
|
+
|
74
|
+
Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
|
75
|
+
several books available online as well:
|
76
|
+
|
77
|
+
* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
|
78
|
+
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
|
79
|
+
|
80
|
+
These two books will bring you up to speed on the Ruby language and also on
|
81
|
+
programming in general.
|
82
|
+
|
83
|
+
|
84
|
+
== Debugger
|
85
|
+
|
86
|
+
Debugger support is available through the debugger command when you start your
|
87
|
+
Mongrel or WEBrick server with --debugger. This means that you can break out of
|
88
|
+
execution at any point in the code, investigate and change the model, and then,
|
89
|
+
resume execution! You need to install ruby-debug to run the server in debugging
|
90
|
+
mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
|
91
|
+
|
92
|
+
class WeblogController < ActionController::Base
|
93
|
+
def index
|
94
|
+
@posts = Post.all
|
95
|
+
debugger
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
So the controller will accept the action, run the first line, then present you
|
100
|
+
with a IRB prompt in the server window. Here you can do things like:
|
101
|
+
|
102
|
+
>> @posts.inspect
|
103
|
+
=> "[#<Post:0x14a6be8
|
104
|
+
@attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
|
105
|
+
#<Post:0x14a6620
|
106
|
+
@attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
|
107
|
+
>> @posts.first.title = "hello from a debugger"
|
108
|
+
=> "hello from a debugger"
|
109
|
+
|
110
|
+
...and even better, you can examine how your runtime objects actually work:
|
111
|
+
|
112
|
+
>> f = @posts.first
|
113
|
+
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
114
|
+
>> f.
|
115
|
+
Display all 152 possibilities? (y or n)
|
116
|
+
|
117
|
+
Finally, when you're ready to resume execution, you can enter "cont".
|
118
|
+
|
119
|
+
|
120
|
+
== Console
|
121
|
+
|
122
|
+
The console is a Ruby shell, which allows you to interact with your
|
123
|
+
application's domain model. Here you'll have all parts of the application
|
124
|
+
configured, just like it is when the application is running. You can inspect
|
125
|
+
domain models, change values, and save to the database. Starting the script
|
126
|
+
without arguments will launch it in the development environment.
|
127
|
+
|
128
|
+
To start the console, run <tt>rails console</tt> from the application
|
129
|
+
directory.
|
130
|
+
|
131
|
+
Options:
|
132
|
+
|
133
|
+
* Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
|
134
|
+
made to the database.
|
135
|
+
* Passing an environment name as an argument will load the corresponding
|
136
|
+
environment. Example: <tt>rails console production</tt>.
|
137
|
+
|
138
|
+
To reload your controllers and models after launching the console run
|
139
|
+
<tt>reload!</tt>
|
140
|
+
|
141
|
+
More information about irb can be found at:
|
142
|
+
link:http://www.rubycentral.org/pickaxe/irb.html
|
143
|
+
|
144
|
+
|
145
|
+
== dbconsole
|
146
|
+
|
147
|
+
You can go to the command line of your database directly through <tt>rails
|
148
|
+
dbconsole</tt>. You would be connected to the database with the credentials
|
149
|
+
defined in database.yml. Starting the script without arguments will connect you
|
150
|
+
to the development database. Passing an argument will connect you to a different
|
151
|
+
database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
|
152
|
+
PostgreSQL and SQLite 3.
|
153
|
+
|
154
|
+
== Description of Contents
|
155
|
+
|
156
|
+
The default directory structure of a generated Ruby on Rails application:
|
157
|
+
|
158
|
+
|-- app
|
159
|
+
| |-- assets
|
160
|
+
| |-- images
|
161
|
+
| |-- javascripts
|
162
|
+
| `-- stylesheets
|
163
|
+
| |-- controllers
|
164
|
+
| |-- helpers
|
165
|
+
| |-- mailers
|
166
|
+
| |-- models
|
167
|
+
| `-- views
|
168
|
+
| `-- layouts
|
169
|
+
|-- config
|
170
|
+
| |-- environments
|
171
|
+
| |-- initializers
|
172
|
+
| `-- locales
|
173
|
+
|-- db
|
174
|
+
|-- doc
|
175
|
+
|-- lib
|
176
|
+
| `-- tasks
|
177
|
+
|-- log
|
178
|
+
|-- public
|
179
|
+
|-- script
|
180
|
+
|-- test
|
181
|
+
| |-- fixtures
|
182
|
+
| |-- functional
|
183
|
+
| |-- integration
|
184
|
+
| |-- performance
|
185
|
+
| `-- unit
|
186
|
+
|-- tmp
|
187
|
+
| |-- cache
|
188
|
+
| |-- pids
|
189
|
+
| |-- sessions
|
190
|
+
| `-- sockets
|
191
|
+
`-- vendor
|
192
|
+
|-- assets
|
193
|
+
`-- stylesheets
|
194
|
+
`-- plugins
|
195
|
+
|
196
|
+
app
|
197
|
+
Holds all the code that's specific to this particular application.
|
198
|
+
|
199
|
+
app/assets
|
200
|
+
Contains subdirectories for images, stylesheets, and JavaScript files.
|
201
|
+
|
202
|
+
app/controllers
|
203
|
+
Holds controllers that should be named like weblogs_controller.rb for
|
204
|
+
automated URL mapping. All controllers should descend from
|
205
|
+
ApplicationController which itself descends from ActionController::Base.
|
206
|
+
|
207
|
+
app/models
|
208
|
+
Holds models that should be named like post.rb. Models descend from
|
209
|
+
ActiveRecord::Base by default.
|
210
|
+
|
211
|
+
app/views
|
212
|
+
Holds the template files for the view that should be named like
|
213
|
+
weblogs/index.html.erb for the WeblogsController#index action. All views use
|
214
|
+
eRuby syntax by default.
|
215
|
+
|
216
|
+
app/views/layouts
|
217
|
+
Holds the template files for layouts to be used with views. This models the
|
218
|
+
common header/footer method of wrapping views. In your views, define a layout
|
219
|
+
using the <tt>layout :default</tt> and create a file named default.html.erb.
|
220
|
+
Inside default.html.erb, call <% yield %> to render the view using this
|
221
|
+
layout.
|
222
|
+
|
223
|
+
app/helpers
|
224
|
+
Holds view helpers that should be named like weblogs_helper.rb. These are
|
225
|
+
generated for you automatically when using generators for controllers.
|
226
|
+
Helpers can be used to wrap functionality for your views into methods.
|
227
|
+
|
228
|
+
config
|
229
|
+
Configuration files for the Rails environment, the routing map, the database,
|
230
|
+
and other dependencies.
|
231
|
+
|
232
|
+
db
|
233
|
+
Contains the database schema in schema.rb. db/migrate contains all the
|
234
|
+
sequence of Migrations for your schema.
|
235
|
+
|
236
|
+
doc
|
237
|
+
This directory is where your application documentation will be stored when
|
238
|
+
generated using <tt>rake doc:app</tt>
|
239
|
+
|
240
|
+
lib
|
241
|
+
Application specific libraries. Basically, any kind of custom code that
|
242
|
+
doesn't belong under controllers, models, or helpers. This directory is in
|
243
|
+
the load path.
|
244
|
+
|
245
|
+
public
|
246
|
+
The directory available for the web server. Also contains the dispatchers and the
|
247
|
+
default HTML files. This should be set as the DOCUMENT_ROOT of your web
|
248
|
+
server.
|
249
|
+
|
250
|
+
script
|
251
|
+
Helper scripts for automation and generation.
|
252
|
+
|
253
|
+
test
|
254
|
+
Unit and functional tests along with fixtures. When using the rails generate
|
255
|
+
command, template test files will be generated for you and placed in this
|
256
|
+
directory.
|
257
|
+
|
258
|
+
vendor
|
259
|
+
External libraries that the application depends on. Also includes the plugins
|
260
|
+
subdirectory. If the app has frozen rails, those gems also go here, under
|
261
|
+
vendor/rails/. This directory is in the load path.
|