modularity-rails 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module ModularityRails
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
3
3
  end
@@ -0,0 +1,79 @@
1
+ #= require spec_helper
2
+
3
+ describe 'test environment setup', ->
4
+
5
+ it 'loading libraries', ->
6
+ load_modularity()
7
+ loadCS "/vendor/assets/javascripts/tools/cache.coffee"
8
+
9
+
10
+ describe 'Cache', ->
11
+
12
+ cache = null
13
+ beforeEach ->
14
+ cache = new window.Cache()
15
+
16
+
17
+ describe 'constructor', ->
18
+
19
+ it 'initializes with an empty cache', ->
20
+ expect(cache.cache).toEqual({})
21
+
22
+
23
+ describe 'add', ->
24
+
25
+ it 'stores the given data in the cache', ->
26
+ cache.add('foo', 'bar')
27
+ expect(cache.cache).toEqual({'foo': 'bar'})
28
+
29
+ it 'overwrites existing entries', ->
30
+ cache.cache = {'foo', 'bar'}
31
+ cache.add 'foo', 'new'
32
+ expect(cache.cache['foo']).toBe('new')
33
+
34
+
35
+ describe 'get', ->
36
+
37
+ it "returns undefined if the entry doesn't exist", ->
38
+ expect(cache.get('zonk')).toBe(undefined)
39
+
40
+ it "returns the entry if it exists", ->
41
+ cache.add 'foo', 'bar'
42
+ expect(cache.get('foo')).toBe('bar')
43
+
44
+
45
+ describe 'getMany', ->
46
+
47
+ result = null
48
+ beforeEach ->
49
+ cache.add('one', 1)
50
+ cache.add('two', 2)
51
+ result = cache.getMany ['one', 'three']
52
+
53
+ it "returns the values that exist in the 'found' structure", ->
54
+ expect(result.found).toEqual({'one': 1})
55
+
56
+ it "returns the values that don't exist in the 'missing' structure", ->
57
+ expect(result.missing).toEqual(['three'])
58
+
59
+
60
+ describe 'length', ->
61
+
62
+ it 'returns 0 for empty cache', ->
63
+ expect(cache.length()).toBe 0
64
+
65
+ it 'returns the number of objects in the cache', ->
66
+ cache.add('foo', 'bar')
67
+ cache.add('fooz', 'baz')
68
+ expect(cache.length()).toBe(2)
69
+
70
+
71
+ describe 'replaceAll', ->
72
+
73
+ it 'replaces the whole cache with the given data', ->
74
+ cache.add 'one', 1
75
+ cache.replaceAll {'one': 2, two: 3}
76
+ expect(cache.length()).toBe(2)
77
+ expect(cache.get('one')).toBe(2)
78
+ expect(cache.get('two')).toBe(3)
79
+
@@ -4,7 +4,10 @@
4
4
  #
5
5
  # Please see https://github.com/kevgo/modularity for more information.
6
6
 
7
- class window.Module
7
+
8
+ window.modularity or= {}
9
+
10
+ class window.modularity.Module
8
11
 
9
12
  # The container variable is required. Provide 'testing' in tests.
10
13
  constructor: (container) ->
@@ -3,6 +3,6 @@
3
3
  # A button module.
4
4
  # Responds to clicks on the container element.
5
5
  # The container element is expected to already be populated.
6
- class window.Button extends Module
6
+ class window.modularity.Button extends Module
7
7
  @mixin clickable
8
8
 
@@ -1,7 +1,7 @@
1
1
  # A button that counts how often it is clicked.
2
2
  # This is implemented as a subclass of Button,
3
3
  # to take advantage of the already existing functionality there.
4
- class window.CounterButton extends Button
4
+ class window.modularity.CounterButton extends Button
5
5
 
6
6
  constructor: ->
7
7
  super
@@ -0,0 +1,43 @@
1
+ # A generic cache.
2
+ # Stores key-value pairs.
3
+ class window.modularity.Cache
4
+
5
+ constructor: ->
6
+ @cache = {}
7
+
8
+
9
+ # Adds the given entry to the cache.
10
+ # Overwrites existing entries.
11
+ add: (key, value) ->
12
+ @cache[key] = value
13
+
14
+
15
+ # Returns the entry with the given key from the cache, or NULL if no entry exists.
16
+ get: (key) ->
17
+ @cache[key]
18
+
19
+
20
+ # Looks up several entries at once.
21
+ # Returns a hash of found entries, and a list of missing entries.
22
+ getMany: (keys) ->
23
+ result = { found: {}, missing: [] }
24
+ for key in keys
25
+ do (key) =>
26
+ value = @cache[key]
27
+ if value
28
+ result.found[key] = value
29
+ else
30
+ result.missing.push key
31
+ result
32
+
33
+
34
+ # Replaces the cache with the given data.
35
+ replaceAll: (data) ->
36
+ @cache = data
37
+
38
+
39
+ # Returns the number of cached objects.
40
+ length: () ->
41
+ # TODO(KG): This doesn't work in IE8.
42
+ Object.keys(@cache).length
43
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modularity-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-03 00:00:00.000000000 Z
12
+ date: 2012-05-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70363417911480 !ruby/object:Gem::Requirement
16
+ requirement: &70325015499260 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70363417911480
24
+ version_requirements: *70325015499260
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: capybara-webkit
27
- requirement: &70363417911000 !ruby/object:Gem::Requirement
27
+ requirement: &70325015480180 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70363417911000
35
+ version_requirements: *70325015480180
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: evergreen
38
- requirement: &70363417910480 !ruby/object:Gem::Requirement
38
+ requirement: &70325015479500 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70363417910480
46
+ version_requirements: *70325015479500
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rb-fsevent
49
- requirement: &70363417909960 !ruby/object:Gem::Requirement
49
+ requirement: &70325015478760 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70363417909960
57
+ version_requirements: *70325015478760
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: guard-livereload
60
- requirement: &70363417909540 !ruby/object:Gem::Requirement
60
+ requirement: &70325015478160 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70363417909540
68
+ version_requirements: *70325015478160
69
69
  description: Description of ModularityRails.
70
70
  email:
71
71
  - kevin.goslar@gmail.com
@@ -97,12 +97,14 @@ files:
97
97
  - spec/javascripts/templates/closable.html
98
98
  - spec/javascripts/templates/test.html
99
99
  - spec/javascripts/tools/ajax_loader_spec.coffee
100
+ - spec/javascripts/tools/cache_spec.coffee
100
101
  - vendor/assets/javascripts/mixins/clickable.coffee
101
102
  - vendor/assets/javascripts/mixins/closable.coffee
102
103
  - vendor/assets/javascripts/modularity.js.coffee
103
104
  - vendor/assets/javascripts/modules/button.coffee
104
105
  - vendor/assets/javascripts/modules/counter_button.coffee
105
106
  - vendor/assets/javascripts/tools/ajax_loader.coffee
107
+ - vendor/assets/javascripts/tools/cache.coffee
106
108
  homepage: http://github.com/kevgo/modularity-rails
107
109
  licenses: []
108
110
  post_install_message:
@@ -123,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
125
  version: '0'
124
126
  requirements: []
125
127
  rubyforge_project:
126
- rubygems_version: 1.8.15
128
+ rubygems_version: 1.8.10
127
129
  signing_key:
128
130
  specification_version: 3
129
131
  summary: Summary of ModularityRails.