angular_sprinkles 0.2.9 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f51b684a9bc158c109028e925728b7f7ea11ef7d
4
- data.tar.gz: 46cd826a0e658158aa1f8dfb4ef2f46b1796a4b8
3
+ metadata.gz: ff497a789844351965389703418e3b5cae9b1c0c
4
+ data.tar.gz: 4d438528165b334ccea8b9c847cdcc6cea92cd4a
5
5
  SHA512:
6
- metadata.gz: 43638b8a5a26c7b51710e305002bcbc63fc8ce59153b6971c6b49fef723627fd7b4bca8b1f16712472f5e1fa90fc5f4fc8ae24a2d98f8498d621e81b042c324b
7
- data.tar.gz: 79ef81a80c26637a54d318ee9987151afd232add27c672a08f4d2239146d968756566526c81acad767a42d42e3e5f9a079d3cb0971cd5295c7456df5c9049c9c
6
+ metadata.gz: c6d40cdf9eca41e89d92bc60a91b93996a207b3bb65f536991091c14453dd94ec506de92c4bfa3f5db005aee0700f94eb5898a8e0c6e0b56206a79c5ff6b4f7d
7
+ data.tar.gz: bb5d25e126014778a1219b391884df2865df8d8f4d0493938513587420aca99f0a1af6d44a4ce9b88558b5370b2d03d39c4cf394e70ec3aa2bd141d6862e5a6d
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.9
1
+ 0.2.10
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: angular_sprinkles 0.2.9 ruby lib
5
+ # stub: angular_sprinkles 0.2.10 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "angular_sprinkles"
9
- s.version = "0.2.9"
9
+ s.version = "0.2.10"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Gabe Scholz"]
14
- s.date = "2014-10-16"
14
+ s.date = "2014-10-18"
15
15
  s.description = "Add a few sprinkles of AngularJS to your Rails App"
16
16
  s.email = "gabe@brewhouse.io"
17
17
  s.extra_rdoc_files = [
@@ -29,9 +29,9 @@ Gem::Specification.new do |s|
29
29
  "app/assets/javascripts/angular_sprinkles.js.erb",
30
30
  "circle.yml",
31
31
  "lib/angular_sprinkles.rb",
32
+ "lib/angular_sprinkles/cache.rb",
32
33
  "lib/angular_sprinkles/constructor.rb",
33
34
  "lib/angular_sprinkles/constructor_collection.rb",
34
- "lib/angular_sprinkles/content_cache.rb",
35
35
  "lib/angular_sprinkles/content_yielder.rb",
36
36
  "lib/angular_sprinkles/context.rb",
37
37
  "lib/angular_sprinkles/counter.rb",
@@ -55,9 +55,9 @@ Gem::Specification.new do |s|
55
55
  "lib/angular_sprinkles/model_decorator.rb",
56
56
  "lib/angular_sprinkles/object_key_wrapper.rb",
57
57
  "lib/angular_sprinkles/railtie.rb",
58
+ "spec/angular_sprinkles/cache_spec.rb",
58
59
  "spec/angular_sprinkles/constructor_collection_spec.rb",
59
60
  "spec/angular_sprinkles/constructor_spec.rb",
60
- "spec/angular_sprinkles/content_cache_spec.rb",
61
61
  "spec/angular_sprinkles/content_yielder_spec.rb",
62
62
  "spec/angular_sprinkles/context_spec.rb",
63
63
  "spec/angular_sprinkles/counter_spec.rb",
@@ -1,6 +1,6 @@
1
+ require "angular_sprinkles/cache"
1
2
  require "angular_sprinkles/constructor"
2
3
  require "angular_sprinkles/constructor_collection"
3
- require "angular_sprinkles/content_cache"
4
4
  require "angular_sprinkles/content_yielder"
5
5
  require "angular_sprinkles/directive/attributes"
6
6
  require "angular_sprinkles/directive/input"
@@ -0,0 +1,19 @@
1
+ module AngularSprinkles
2
+ class Cache
3
+ def initialize
4
+ @store = {}
5
+ end
6
+
7
+ def get(key)
8
+ @store[key]
9
+ end
10
+
11
+ def set(key, content = true)
12
+ @store[key] = content
13
+ end
14
+
15
+ def set?(key)
16
+ @store.has_key?(key)
17
+ end
18
+ end
19
+ end
@@ -2,13 +2,19 @@ module AngularSprinkles
2
2
  class KeyGenerator
3
3
  def initialize(args)
4
4
  @counter = args.fetch(:counter)
5
+ @cache = args.fetch(:cache)
5
6
  end
6
7
 
7
8
  def call(object)
9
+ return @cache.get(object) if @cache.set?(object)
10
+
8
11
  klass = "#{object.class}".gsub("::", "__")
9
12
  count = @counter.inc(klass)
13
+ generated_key = "#{klass}_#{count}"
14
+
15
+ @cache.set(object, generated_key)
10
16
 
11
- "#{klass}_#{count}"
17
+ generated_key
12
18
  end
13
19
  end
14
20
  end
@@ -2,8 +2,10 @@ module AngularSprinkles
2
2
  module Mixins
3
3
  module Controller
4
4
  def initialize(*args)
5
- counter = Counter.new
6
- key_generator = KeyGenerator.new(counter: counter)
5
+ key_generator = KeyGenerator.new({
6
+ counter: Counter.new,
7
+ cache: Cache.new
8
+ })
7
9
 
8
10
  constructor_collection = ConstructorCollection.new({
9
11
  json_wrapper: JavaScript::ConstructorThis,
@@ -40,7 +42,7 @@ module AngularSprinkles
40
42
  def view_context
41
43
  super.tap do |context|
42
44
  @_sprinkles.content_yielder = ContentYielder.new({
43
- cache: ContentCache.new,
45
+ cache: Cache.new,
44
46
  context: context,
45
47
  yield_to: JavaScript::PREFIX
46
48
  })
@@ -1,7 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe AngularSprinkles::ContentCache do
3
+ describe AngularSprinkles::Cache do
4
4
  let(:key) { 'key' }
5
+ let(:content) { Object.new }
5
6
 
6
7
  subject { described_class.new }
7
8
 
@@ -12,4 +13,10 @@ describe AngularSprinkles::ContentCache do
12
13
 
13
14
  expect(subject.set?(key)).to eq(true)
14
15
  end
16
+
17
+ it 'can get a key' do
18
+ subject.set(key, content)
19
+
20
+ expect(subject.get(key)).to be(content)
21
+ end
15
22
  end
@@ -1,11 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe AngularSprinkles::KeyGenerator do
4
- let(:counter) { double(inc: inc) }
4
+ let(:counter) { AngularSprinkles::Counter.new }
5
+ let(:cache) { AngularSprinkles::Cache.new }
5
6
  let(:inc) { 1 }
6
7
  let(:object) { double(class: AngularSprinkles) }
7
8
 
8
- subject { described_class.new(counter: counter) }
9
+ subject { described_class.new(counter: counter, cache: cache) }
9
10
 
10
11
  it "returns a suitable variable name" do
11
12
  expect(subject.call(object)).to eq("#{object.class}_#{inc}")
@@ -14,4 +15,9 @@ describe AngularSprinkles::KeyGenerator do
14
15
  it "it substitutes :: for __ in nested classes" do
15
16
  expect(subject.call(subject)).to eq("AngularSprinkles__KeyGenerator_#{inc}")
16
17
  end
18
+
19
+ it "returns the same key if the object is used twice" do
20
+ expect(subject.call(object)).to eq("#{object.class}_#{inc}")
21
+ expect(subject.call(object)).to eq("#{object.class}_#{inc}")
22
+ end
17
23
  end
@@ -6,7 +6,4 @@
6
6
  <%= bind_form_for [@model, @models], :form_submitted do |f| %>
7
7
  <% end %>
8
8
 
9
- <%= bind_form_for @models, :form_submitted do |f| %>
10
- <% end %>
11
-
12
9
  <div ng-bind="<%= @model.bind(:life) %>"></div>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: angular_sprinkles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabe Scholz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-16 00:00:00.000000000 Z
11
+ date: 2014-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -76,9 +76,9 @@ files:
76
76
  - app/assets/javascripts/angular_sprinkles.js.erb
77
77
  - circle.yml
78
78
  - lib/angular_sprinkles.rb
79
+ - lib/angular_sprinkles/cache.rb
79
80
  - lib/angular_sprinkles/constructor.rb
80
81
  - lib/angular_sprinkles/constructor_collection.rb
81
- - lib/angular_sprinkles/content_cache.rb
82
82
  - lib/angular_sprinkles/content_yielder.rb
83
83
  - lib/angular_sprinkles/context.rb
84
84
  - lib/angular_sprinkles/counter.rb
@@ -102,9 +102,9 @@ files:
102
102
  - lib/angular_sprinkles/model_decorator.rb
103
103
  - lib/angular_sprinkles/object_key_wrapper.rb
104
104
  - lib/angular_sprinkles/railtie.rb
105
+ - spec/angular_sprinkles/cache_spec.rb
105
106
  - spec/angular_sprinkles/constructor_collection_spec.rb
106
107
  - spec/angular_sprinkles/constructor_spec.rb
107
- - spec/angular_sprinkles/content_cache_spec.rb
108
108
  - spec/angular_sprinkles/content_yielder_spec.rb
109
109
  - spec/angular_sprinkles/context_spec.rb
110
110
  - spec/angular_sprinkles/counter_spec.rb
@@ -1,15 +0,0 @@
1
- module AngularSprinkles
2
- class ContentCache
3
- def initialize
4
- @store = {}
5
- end
6
-
7
- def set(content)
8
- @store[content.to_s] = true
9
- end
10
-
11
- def set?(content)
12
- @store.has_key?(content.to_s)
13
- end
14
- end
15
- end