lunr 2.0.3 → 2.0.4

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.
@@ -1,3 +1,7 @@
1
+ === 2.0.4 / 2010-09-07
2
+
3
+ * Unbreak model instantiation, switch to Hash backing store.
4
+
1
5
  === 2.0.3 / 2010-09-07
2
6
 
3
7
  * Cleanups, squash warnings.
@@ -47,7 +47,7 @@ to the original data store, Lunr might be what you're looking for.
47
47
 
48
48
  === Including the Module
49
49
 
50
- All model class must <code>include Lunr::Model</code>.
50
+ All model classes must <code>include Lunr::Model</code>.
51
51
 
52
52
  === Define the Search Index
53
53
 
@@ -109,7 +109,7 @@ first param must be the Sunspot query object.
109
109
 
110
110
  == Searching
111
111
 
112
- Use Sunspot's excellent search DSL for ad hock searches.
112
+ Use Sunspot's excellent search DSL for ad hoc searches.
113
113
 
114
114
  My::SimpleTrack.search
115
115
  My::SimpleTrack.all # same thing
@@ -6,7 +6,7 @@ module Lunr
6
6
 
7
7
  # Duh.
8
8
 
9
- VERSION = "2.0.3"
9
+ VERSION = "2.0.4"
10
10
 
11
11
  end
12
12
 
@@ -2,16 +2,16 @@ require "lunr/model/klass"
2
2
 
3
3
  module Lunr
4
4
  module Model
5
- attr_accessor :id
5
+ def initialize hash
6
+ @hash = hash
7
+ end
6
8
 
7
- def to_h
8
- @to_h ||= {}.tap do |h|
9
- h[:id] = id
9
+ def id
10
+ @hash[:id]
11
+ end
10
12
 
11
- self.class.properties.each do |name, type|
12
- h[name] = send name
13
- end
14
- end
13
+ def to_h
14
+ @hash
15
15
  end
16
16
  end
17
17
  end
@@ -9,23 +9,20 @@ module Lunr
9
9
 
10
10
  module Klass
11
11
  def create hit
12
- new.tap do |instance|
13
- instance.id = hit.primary_key
12
+ hash = { :id => hit.primary_key }
14
13
 
15
- properties.each do |name, type|
16
- value = hit.stored name
14
+ properties.each do |name, type|
15
+ value = hit.stored name
17
16
 
17
+ if Array === value && value.length == 1 && type == :text
18
18
  # For text fields, which always appear to be multiple.
19
-
20
- if Array === value && value.length == 1 && type == :text
21
- value = value.first
22
- end
23
-
24
- instance.send "#{name}=", value
19
+ value = value.first
25
20
  end
26
21
 
27
- instance.freeze
22
+ hash[name] = value
28
23
  end
24
+
25
+ new(hash).freeze
29
26
  end
30
27
 
31
28
  def first &block
@@ -45,7 +42,9 @@ module Lunr
45
42
 
46
43
  unless name == :all
47
44
  class_eval <<-END, __FILE__, __LINE__ + 1
48
- def self.#{name}; search.#{name} end
45
+ def self.#{name}
46
+ search.#{name}
47
+ end
49
48
  END
50
49
  end
51
50
  end
@@ -61,7 +60,11 @@ module Lunr
61
60
  Sunspot.setup self, &block
62
61
 
63
62
  properties.each do |name, type|
64
- attr_accessor name
63
+ class_eval <<-END, __FILE__, __LINE__ + 1
64
+ def #{name}
65
+ @hash[#{name.inspect}]
66
+ end
67
+ END
65
68
  end
66
69
  end
67
70
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lunr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 3
10
- version: 2.0.3
9
+ - 4
10
+ version: 2.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Barnette