kojac 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +7 -0
  3. data/Gemfile +17 -0
  4. data/Gemfile.lock +158 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +69 -0
  7. data/Rakefile +27 -0
  8. data/app/assets/javascripts/can_extensions.js +45 -0
  9. data/app/assets/javascripts/kojac.js +1230 -0
  10. data/app/assets/javascripts/kojac_canjs.js +191 -0
  11. data/app/assets/javascripts/kojac_ember.js +463 -0
  12. data/app/controllers/kojac_controller.rb +70 -0
  13. data/app/serializers/default_kojac_serializer.rb +10 -0
  14. data/diagram.odg +0 -0
  15. data/kojac.gemspec +36 -0
  16. data/lib/kojac/app_serialize.rb +29 -0
  17. data/lib/kojac/kojac_rails.rb +432 -0
  18. data/lib/kojac/ring_strong_parameters.rb +195 -0
  19. data/lib/kojac/version.rb +3 -0
  20. data/lib/kojac.rb +8 -0
  21. data/lib/tasks/kojac_tasks.rake +4 -0
  22. data/notes.txt +48 -0
  23. data/spec/.DS_Store +0 -0
  24. data/spec/can_cache_spec.js +87 -0
  25. data/spec/can_factory_spec.js +144 -0
  26. data/spec/can_model_spec.js +127 -0
  27. data/spec/demo/README.rdoc +261 -0
  28. data/spec/demo/Rakefile +7 -0
  29. data/spec/demo/app/assets/javascripts/application.js +15 -0
  30. data/spec/demo/app/assets/stylesheets/application.css +13 -0
  31. data/spec/demo/app/controllers/application_controller.rb +3 -0
  32. data/spec/demo/app/helpers/application_helper.rb +2 -0
  33. data/spec/demo/app/mailers/.gitkeep +0 -0
  34. data/spec/demo/app/models/.gitkeep +0 -0
  35. data/spec/demo/app/views/layouts/application.html.erb +14 -0
  36. data/spec/demo/config/application.rb +65 -0
  37. data/spec/demo/config/boot.rb +10 -0
  38. data/spec/demo/config/database.yml +25 -0
  39. data/spec/demo/config/environment.rb +5 -0
  40. data/spec/demo/config/environments/development.rb +37 -0
  41. data/spec/demo/config/environments/production.rb +67 -0
  42. data/spec/demo/config/environments/test.rb +37 -0
  43. data/spec/demo/config/initializers/backtrace_silencers.rb +7 -0
  44. data/spec/demo/config/initializers/inflections.rb +15 -0
  45. data/spec/demo/config/initializers/mime_types.rb +5 -0
  46. data/spec/demo/config/initializers/secret_token.rb +7 -0
  47. data/spec/demo/config/initializers/session_store.rb +8 -0
  48. data/spec/demo/config/initializers/wrap_parameters.rb +14 -0
  49. data/spec/demo/config/locales/en.yml +5 -0
  50. data/spec/demo/config/routes.rb +58 -0
  51. data/spec/demo/config.ru +4 -0
  52. data/spec/demo/lib/assets/.gitkeep +0 -0
  53. data/spec/demo/log/.gitkeep +0 -0
  54. data/spec/demo/public/404.html +26 -0
  55. data/spec/demo/public/422.html +26 -0
  56. data/spec/demo/public/500.html +25 -0
  57. data/spec/demo/public/favicon.ico +0 -0
  58. data/spec/demo/script/rails +6 -0
  59. data/spec/ember_factory_spec.js +157 -0
  60. data/spec/ember_model_spec.js +179 -0
  61. data/spec/external/.DS_Store +0 -0
  62. data/spec/external/ember/.DS_Store +0 -0
  63. data/spec/external/ember/ember-1.0.0-rc.6.js +30970 -0
  64. data/spec/external/ember/handlebars-1.0.0-rc.4.js +2239 -0
  65. data/spec/external/jasmine/MIT.LICENSE +20 -0
  66. data/spec/external/jasmine/jasmine-html.js +616 -0
  67. data/spec/external/jasmine/jasmine.css +81 -0
  68. data/spec/external/jasmine/jasmine.js +2529 -0
  69. data/spec/external/jasmine.async.js +51 -0
  70. data/spec/external/jquery/jquery-1.7.2.js +9404 -0
  71. data/spec/external/jquery/jquery-1.7.2.min.js +4 -0
  72. data/spec/external/jquery/jquery-1.9.1.js +9597 -0
  73. data/spec/external/json2.js +480 -0
  74. data/spec/external/steal/steal-121115.js +2747 -0
  75. data/spec/external/steal/steal-3.2.3.js +2098 -0
  76. data/spec/external/steal/steal-3.2.3.min.js +27 -0
  77. data/spec/external/steal/steal.js +2466 -0
  78. data/spec/external/steal/steal.min.js +32 -0
  79. data/spec/external/steal/stealconfig.js +19 -0
  80. data/spec/external/underscore.js +1223 -0
  81. data/spec/external/underscore_plus.js +261 -0
  82. data/spec/external.zip +0 -0
  83. data/spec/handler_stack_spec.js +143 -0
  84. data/spec/helpers/SpecHelper.js +10 -0
  85. data/spec/kojac_caching_spec.js +105 -0
  86. data/spec/kojac_mock_spec.js +230 -0
  87. data/spec/kojac_model_spec.js +126 -0
  88. data/spec/kojac_object_spec.js +171 -0
  89. data/spec/kojac_operations_spec.js +41 -0
  90. data/spec/mockjson/order_item.js +37 -0
  91. data/spec/mockjson/order_item__49.js +15 -0
  92. data/spec/mockjson/order_item__50.js +15 -0
  93. data/spec/mockjson/order_item__51.js +15 -0
  94. data/spec/mockjson/product.js +82 -0
  95. data/spec/mockjson/product__3.js +22 -0
  96. data/spec/model_ring_spec.rb +52 -0
  97. data/spec/operation_include_spec.js +77 -0
  98. data/spec/run.html +81 -0
  99. data/spec/spec.js +2 -0
  100. data/spec/support/jasmine.yml +86 -0
  101. metadata +380 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODkyNDY5NGExYzM1NmM2MGU0NTU0ZGM1YTk0Mjk0MzU1OTQwMmQzZQ==
5
+ data.tar.gz: !binary |-
6
+ NTRlMTFjNTliMDcxMGU5MTQ0OGYzMWY0ZjM5NmY5M2NhNTJmZDM5Yw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NzY3MGYyODk2YzJmMzgzYjY0ZTkzNGJmYjgyYTliMTg4NzQ1ZjdlMzFmMmU4
10
+ ZTljYjQxZTQzNGQxZjZhMTZlYmYyMjA4NTM5MzQ5MjdjODJmNDIxMDVkNDU3
11
+ Njk5NDJhNGZlMGViY2NkNmU4ZWZlOWVlM2IxZjRlZThkOGY2YWU=
12
+ data.tar.gz: !binary |-
13
+ NDkyOWZmOWVjYmUwYmExMDIxNGJlOTM4M2JmY2U0Y2Q4MWRjOTk1YzA5NTNj
14
+ NTQzZmI0MmQ4NGE2OWYwMmQ1ZjY2ZDg1ZWQ3YzFlNTQwNzQxZDdhODMwNWM4
15
+ NjQyNGVhZDc3ZTdlMWIxNjk5OTY3OWJkNDE2MTVjYWRiNjBkY2I=
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/demo/db/*.sqlite3
5
+ spec/demo/log/*.log
6
+ spec/demo/tmp/
7
+ spec/demo/.sass-cache
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Declare your gem's dependencies in kojac.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # jquery-rails is used by the dummy application
9
+ gem "jquery-rails"
10
+
11
+ # Declare any dependencies that are still in development here instead of in
12
+ # your gemspec. These might include edge Rails or gems from your path or
13
+ # Git. Remember to move these dependencies to your gemspec before releasing
14
+ # your gem to rubygems.org.
15
+
16
+ # To use debugger
17
+ # gem 'debugger'
data/Gemfile.lock ADDED
@@ -0,0 +1,158 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kojac (0.9.0)
5
+ jquery-rails
6
+ json2-rails
7
+ strong_parameters
8
+ underscore_plus
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ actionmailer (3.2.14)
14
+ actionpack (= 3.2.14)
15
+ mail (~> 2.5.4)
16
+ actionpack (3.2.14)
17
+ activemodel (= 3.2.14)
18
+ activesupport (= 3.2.14)
19
+ builder (~> 3.0.0)
20
+ erubis (~> 2.7.0)
21
+ journey (~> 1.0.4)
22
+ rack (~> 1.4.5)
23
+ rack-cache (~> 1.2)
24
+ rack-test (~> 0.6.1)
25
+ sprockets (~> 2.2.1)
26
+ active_model_serializers (0.8.1)
27
+ activemodel (>= 3.0)
28
+ activemodel (3.2.14)
29
+ activesupport (= 3.2.14)
30
+ builder (~> 3.0.0)
31
+ activerecord (3.2.14)
32
+ activemodel (= 3.2.14)
33
+ activesupport (= 3.2.14)
34
+ arel (~> 3.0.2)
35
+ tzinfo (~> 0.3.29)
36
+ activeresource (3.2.14)
37
+ activemodel (= 3.2.14)
38
+ activesupport (= 3.2.14)
39
+ activesupport (3.2.14)
40
+ i18n (~> 0.6, >= 0.6.4)
41
+ multi_json (~> 1.0)
42
+ arel (3.0.2)
43
+ barber (0.4.2)
44
+ ember-source
45
+ execjs
46
+ handlebars-source
47
+ builder (3.0.4)
48
+ canjs-rails (1.1.2)
49
+ railties (>= 3.2.0, < 5.0)
50
+ thor (~> 0.14)
51
+ capybara (2.1.0)
52
+ mime-types (>= 1.16)
53
+ nokogiri (>= 1.3.3)
54
+ rack (>= 1.0.0)
55
+ rack-test (>= 0.5.4)
56
+ xpath (~> 2.0)
57
+ diff-lcs (1.2.4)
58
+ ember-data-source (0.13)
59
+ ember-source
60
+ ember-rails (0.12.0)
61
+ active_model_serializers
62
+ barber (>= 0.4.1)
63
+ ember-data-source
64
+ ember-source (>= 1.0.0.rc2.2)
65
+ execjs (>= 1.2)
66
+ railties (>= 3.1)
67
+ ember-source (1.0.0.rc7)
68
+ handlebars-source (= 1.0.12)
69
+ erubis (2.7.0)
70
+ execjs (1.4.0)
71
+ multi_json (~> 1.0)
72
+ handlebars-source (1.0.12)
73
+ hike (1.2.3)
74
+ i18n (0.6.5)
75
+ journey (1.0.4)
76
+ jquery-rails (3.0.4)
77
+ railties (>= 3.0, < 5.0)
78
+ thor (>= 0.14, < 2.0)
79
+ json (1.8.0)
80
+ json2-rails (1.0.0)
81
+ mail (2.5.4)
82
+ mime-types (~> 1.16)
83
+ treetop (~> 1.4.8)
84
+ mime-types (1.24)
85
+ multi_json (1.7.9)
86
+ nokogiri (1.5.9)
87
+ polyglot (0.3.3)
88
+ rack (1.4.5)
89
+ rack-cache (1.2)
90
+ rack (>= 0.4)
91
+ rack-ssl (1.3.3)
92
+ rack
93
+ rack-test (0.6.2)
94
+ rack (>= 1.0)
95
+ rails (3.2.14)
96
+ actionmailer (= 3.2.14)
97
+ actionpack (= 3.2.14)
98
+ activerecord (= 3.2.14)
99
+ activeresource (= 3.2.14)
100
+ activesupport (= 3.2.14)
101
+ bundler (~> 1.0)
102
+ railties (= 3.2.14)
103
+ railties (3.2.14)
104
+ actionpack (= 3.2.14)
105
+ activesupport (= 3.2.14)
106
+ rack-ssl (~> 1.3.2)
107
+ rake (>= 0.8.7)
108
+ rdoc (~> 3.4)
109
+ thor (>= 0.14.6, < 2.0)
110
+ rake (10.1.0)
111
+ rdoc (3.12.2)
112
+ json (~> 1.4)
113
+ rspec-core (2.13.1)
114
+ rspec-expectations (2.13.0)
115
+ diff-lcs (>= 1.1.3, < 2.0)
116
+ rspec-mocks (2.13.1)
117
+ rspec-rails (2.13.2)
118
+ actionpack (>= 3.0)
119
+ activesupport (>= 3.0)
120
+ railties (>= 3.0)
121
+ rspec-core (~> 2.13.0)
122
+ rspec-expectations (~> 2.13.0)
123
+ rspec-mocks (~> 2.13.0)
124
+ sprockets (2.2.2)
125
+ hike (~> 1.2)
126
+ multi_json (~> 1.0)
127
+ rack (~> 1.0)
128
+ tilt (~> 1.1, != 1.3.0)
129
+ sqlite3 (1.3.7)
130
+ strong_parameters (0.2.1)
131
+ actionpack (~> 3.0)
132
+ activemodel (~> 3.0)
133
+ railties (~> 3.0)
134
+ thor (0.18.1)
135
+ tilt (1.4.1)
136
+ treetop (1.4.15)
137
+ polyglot
138
+ polyglot (>= 0.3.1)
139
+ tzinfo (0.3.37)
140
+ underscore-rails (1.4.3)
141
+ underscore_plus (0.9.0)
142
+ railties (~> 3.1)
143
+ underscore-rails (= 1.4.3)
144
+ xpath (2.0.0)
145
+ nokogiri (~> 1.3)
146
+
147
+ PLATFORMS
148
+ ruby
149
+
150
+ DEPENDENCIES
151
+ canjs-rails
152
+ capybara
153
+ ember-rails
154
+ jquery-rails
155
+ kojac!
156
+ rails (~> 3.2)
157
+ rspec-rails
158
+ sqlite3
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ > "Sometimes the strategic breakthrough will be a new algorithm ... Much more often, strategic breakthrough will come from redoing the representation of the data or tables. This is where the heart of a program lies."
2
+ > - "The Mythical Man Month" by Fred Brooks
3
+
4
+ ## What is KOJAC ?
5
+
6
+ KOJAC is an acronym for Key Oriented JSON Application Cache. Yes you may know of [Kojak, the 1970s TV cop show](http://en.wikipedia.org/wiki/Kojak).
7
+
8
+ KOJAC is an opinionated design and implementation for data management within ["single page"](http://en.wikipedia.org/wiki/Single-page_application) or ["Rich Internet"](http://en.wikipedia.org/wiki/Rich_Internet_application) applications. It relates most heavily to the client and data protocol. The server may continue the key/value style down to a key/value-style database if desired, but that is not necessary. KOJAC also makes sense for the client design when a standard REST-style server is to be used, but naturally multiple operations will require multiple server requests.
9
+
10
+ Single page applications require a different way of thinking, and present different challenges to traditional server-based applications. In particular, application state and user data must be managed and synchronised with the server.
11
+
12
+ Behind the design of KOJAC is the belief that how we structure and identify data has an enormous impact on the size and complexity of the application code.
13
+
14
+ #### 1) Think REST ...
15
+
16
+ Like [REST](http://en.wikipedia.org/wiki/Representational_state_transfer), the server has "resources" eg. customers or products that the client may do CRUD (Create, Read, Update, Destroy) operations on. Unlike REST, URLs are replaced by keys. Keys follow a standard format eg. `<resource>__<id>`.
17
+
18
+ Values may be of any valid JSON type ie. Null, Int, Number, String, Boolean, Array, Object. Potentially the Client, server and protocol can use the same key/value schema.
19
+
20
+ #### 2) ...with multiple operations per request...
21
+
22
+ Multiple operations per http request. Freely specify a mixture of CRUD operations on any resources in a given order, and get back the results (including errors) of any operation. That means your data can be broken down to single values, and you can request just the values you need from the server.
23
+
24
+ #### 3) ...and an object factory.
25
+
26
+ An optional custom factory method easily converts raw JSON into your application classes and property types. When KOJAC is used with Ember.js, the included EmberModel class enables application models to be declared with typed properties, and data is intelligently converted (if required) when these properties are set. Model classes serve as a live data dictionary for your app, and provide a meaningful place for related methods. Typed properties simplify application code by reducing the need to check and convert types.
27
+
28
+ #### 4) A central cache keeps things responsive
29
+
30
+ Responses from the server update the cache (by default), keeping it fresh. With frameworks like Ember, the view can bind directly to the cache key eg. {rowIdsBinding: "App.cache.products"} for display as soon as it arrives.
31
+
32
+ #### 5) No boiler-plate code
33
+
34
+ As date in the cache is often up to date and in your application classes, very little code is required to support or use the KOJAC framework once setup.
35
+
36
+
37
+ <br/>
38
+ <br/>
39
+ <br/>
40
+ KOJAC is server agnostic, open for hacking and debugging, uses and supports jQuery (especially Deferred Objects/Promises), prefers Ember.js but doesn't require it.
41
+
42
+ ## Code Examples
43
+
44
+ 1) Minimal example:
45
+
46
+ <pre>
47
+ kojac.read('products')
48
+ </pre>
49
+
50
+ ...the results will eventually appear as kojac.cache.products
51
+
52
+ 2) Full example:
53
+
54
+ <pre>
55
+ kojac.read(['products','brands','categories__12']).done(function(aContext) {
56
+ // handle eg. aContext.results().products or aContext.ops[0].results.products or kojac.cache.products
57
+ }).fail(function(aContext) {
58
+ // handle aContext.error()
59
+ });
60
+ </pre>
61
+
62
+ 3) Create
63
+
64
+ <pre>
65
+ kojac.create(['products']).done(function(aContext) {
66
+ // handle aContext.ops[0].result or kojac.cache[aContext.ops[0].resultKey]
67
+ });
68
+ </pre>
69
+
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Kojac'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,45 @@
1
+ CanUtils = {
2
+
3
+ isCanObject: function(aObject) {
4
+ return aObject instanceof can.Construct;
5
+ },
6
+
7
+ attr: function(aObject,aProperty,aValue) {
8
+ if (!aObject)
9
+ return undefined;
10
+ if (this.isCanObject(aObject)) {
11
+ return aObject.attr(aProperty,aValue)
12
+ } else {
13
+ if (arguments.length===3) { // set
14
+ return aObject[aProperty] = aValue;
15
+ } else {
16
+ return aObject[aProperty]
17
+ }
18
+ }
19
+ },
20
+
21
+ copyProperties: function(aDest,aSource,aProperties,aExclude) {
22
+ var p;
23
+ var v;
24
+ if (aProperties) {
25
+ for (var i=0;i<aProperties.length;i++) {
26
+ p = aProperties[i];
27
+ if (aExclude && aExclude.indexOf(p)>=0)
28
+ continue;
29
+ v = this.attr(aSource,p);
30
+ if (v!==undefined)
31
+ this.attr(aDest,p,v);
32
+ }
33
+ } else {
34
+ for (p in aSource) {
35
+ if (aExclude && aExclude.indexOf(p)>=0)
36
+ continue;
37
+ v = this.attr(aSource,p);
38
+ if (v!==undefined)
39
+ this.attr(aDest,p,v);
40
+ }
41
+ }
42
+ return aDest;
43
+ }
44
+
45
+ };