redinger-hashdown 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,2 +1,5 @@
1
+ == 0.1.2
2
+ * Added :cache to selectable true (default) uses cache, false disables
3
+
1
4
  == 0.1.1
2
5
  * gemified by Christopher Redinger
@@ -39,6 +39,11 @@ This is roughly equivalent to the following implementation:
39
39
 
40
40
  ...except it adds ActiveSupport caching for speedy lookups.
41
41
 
42
+ == Cache
43
+ By default caching is enabled. To disable it for select lists:
44
+
45
+ selectable :cache => false
46
+
42
47
  == COMING SOON:
43
48
 
44
49
  * configuration for key / value generation
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 1
3
- :patch: 1
3
+ :patch: 2
4
4
  :major: 0
@@ -4,12 +4,12 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{hashdown}
8
- s.version = "0.1.1"
7
+ s.name = %q{redinger-hashdown}
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Solomon White", "Christopher Redinger"]
12
- s.date = %q{2009-09-24}
12
+ s.date = %q{2009-09-25}
13
13
  s.description = %q{hashdown is a super lightweight rails plugin that adds hash-style lookups and option lists (for generating dropdowns) to ActiveRecord models}
14
14
  s.email = %q{redinger@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -8,7 +8,7 @@ module Rubysolo # :nodoc:
8
8
  self.cache_store ||= ActiveSupport::Cache::MemoryStore.new
9
9
 
10
10
  def self.select_options(*args)
11
- cache_store.fetch("select_options:#{args.hash}", :force => Rubysolo::Hashdown.force_cache_miss?) {
11
+ cache(args) do
12
12
  options = args.extract_options!
13
13
  options[:value] ||= args.shift || selectable_options[:value]
14
14
 
@@ -23,12 +23,20 @@ module Rubysolo # :nodoc:
23
23
  find_options[:order] ||= options[:value] if has_column?(options[:value])
24
24
 
25
25
  find(:all, find_options).map{|record| record.to_pair(options[:key], options[:value]) }
26
- }.dup
26
+ end.dup
27
27
  end
28
28
 
29
29
  def self.has_column?(column_name)
30
30
  columns.map{|c| c.name }.include?(column_name.to_s)
31
31
  end
32
+
33
+ def cache(args, &block)
34
+ if selectable_options[:cache] == false
35
+ yield
36
+ else
37
+ cache_store.fetch("select_options:#{args.hash}", :force => Rubysolo::Hashdown.force_cache_miss?, &block)
38
+ end
39
+ end
32
40
  end
33
41
  end
34
42
 
@@ -50,6 +50,15 @@ describe "an ActiveRecord model with selectable defined" do
50
50
  State.select_options.length.should == State.count
51
51
  end
52
52
  end
53
+
54
+ it "should not store result in cache when cache is false" do
55
+ @states = NonCachedState.all
56
+ NonCachedState.expects(:find).times(5).returns(@states)
57
+
58
+ 5.times do
59
+ NonCachedState.select_options.length.should == State.count
60
+ end
61
+ end
53
62
 
54
63
  it "should not default non-column ordering" do
55
64
  lambda{ CustomDisplay.select_options }.should_not raise_error
@@ -61,6 +61,11 @@ class State < ActiveRecord::Base
61
61
  selectable
62
62
  end
63
63
 
64
+ class NonCachedState < ActiveRecord::Base
65
+ selectable :cache => false
66
+ set_table_name 'states'
67
+ end
68
+
64
69
  class CustomDisplay < ActiveRecord::Base
65
70
  selectable
66
71
  set_table_name 'states'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redinger-hashdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solomon White
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-09-24 00:00:00 -07:00
13
+ date: 2009-09-25 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -48,9 +48,10 @@ files:
48
48
  - spec/fixtures/states.yml
49
49
  - spec/selectable_spec.rb
50
50
  - spec/spec_helper.rb
51
- has_rdoc: false
51
+ has_rdoc: true
52
52
  homepage: http://github.com/redinger/hashdown
53
- licenses:
53
+ licenses: []
54
+
54
55
  post_install_message:
55
56
  rdoc_options:
56
57
  - --charset=UTF-8