rufus-doric 0.1.7 → 0.1.8

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.txt CHANGED
@@ -2,6 +2,12 @@
2
2
  = rufus-doric CHANGELOG.txt
3
3
 
4
4
 
5
+ == rufus-doric - 0.1.8 released 2010/04/16
6
+
7
+ - view_by 'funcname', 'func' creates a 'funcname' method, not a 'by_funcname'
8
+ - ranges must now be specified with :start[key] and/or :end[key]
9
+
10
+
5
11
  == rufus-doric - 0.1.7 released 2010/04/16
6
12
 
7
13
  - view_by 'tysec', "emit(doc.type + '__' + doc.security_level, null);"
data/TODO.txt CHANGED
@@ -6,12 +6,12 @@
6
6
  [o] all, by : limit and skip (pagination)
7
7
  [o] pagination for everybody in Model (DRY)
8
8
  [o] eventually : pagination for the text index
9
+ [o] view_by 'name', %{ emit(doc.nada) }
10
+ [o] start and end key should be by_x(:start => a, :end => b)
9
11
 
10
12
  [x] lsof check (jig / patron)
11
13
 
12
14
  [ ] eventually : cache the text index
13
15
 
14
- [ ] view_by 'name' do
15
- %{ emit(doc.nada) }
16
- end
16
+ [ ] view_by 'x', 'emit' ==> view 'x', 'emit' ==> Model.x(key)...
17
17
 
@@ -103,6 +103,49 @@ module Doric
103
103
  @_id_field
104
104
  end
105
105
 
106
+ # Creates a by_{key} method.
107
+ #
108
+ # If a func (a String) is passed, a {key} method is created that
109
+ # uses the given view function fragment.
110
+ #
111
+ # == example
112
+ #
113
+ # class Task < Rufus::Doric::Model
114
+ #
115
+ # property :user
116
+ # property :status
117
+ # property :date_terminated
118
+ #
119
+ # view_by :user
120
+ #
121
+ # view_by 'open_tasks', %{
122
+ # if (doc.date_terminated) return;
123
+ # if (doc.status == 'suspended') return;
124
+ # emit(doc.user, null);
125
+ # }
126
+ # end
127
+ #
128
+ # will thus have a by_user method and a open_tasks method
129
+ #
130
+ # Task.by_user('john')
131
+ # # lists all the tasks for the user 'john'
132
+ #
133
+ # Task.open_tasks('john')
134
+ # # lists all the open tasks for the user 'john'
135
+ #
136
+ # Task.open_tasks('john', :skip => 5, :limit => 10)
137
+ # # lists 10 open tasks for the user 'john' (skipping the first 5)
138
+ #
139
+ # == options
140
+ #
141
+ # The methods generated by view_by support the following options :
142
+ #
143
+ # :limit, :skip, :inclusive_end, :descending, :start[key], :end[key]
144
+ #
145
+ # See http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options
146
+ #
147
+ # The all method supports the same options.
148
+ #
106
149
  def self.view_by (key, func=nil)
107
150
 
108
151
  if func
@@ -110,7 +153,7 @@ module Doric
110
153
  k = { key => func }
111
154
 
112
155
  instance_eval %{
113
- def by_#{key} (val, opts={})
156
+ def #{key} (val, opts={})
114
157
  by(#{k.inspect}, val, opts)
115
158
  end
116
159
  }
@@ -534,20 +577,36 @@ module Doric
534
577
  result['rows'].collect { |r| r['doc'] }
535
578
  end
536
579
 
537
- def self.by (key, val, opts)
580
+ # A helper method for .by
581
+ #
582
+ def self.is_option_hash (h)
538
583
 
539
- qs = [ 'include_docs=true' ]
584
+ return false unless h.is_a?(Hash)
585
+ h.keys.each { |k| return false unless k.is_a?(Symbol) }
586
+ true
587
+ end
540
588
 
541
- if val.is_a?(Array) && ( ! key.is_a?(Array))
589
+ # view_by uses this .by method in the background
590
+ #
591
+ def self.by (key, val, opts={})
542
592
 
543
- st, en = val
544
- qs << "startkey=#{Rufus::Doric.escape(st)}" if st
545
- qs << "endkey=#{Rufus::Doric.escape(en)}" if en
546
- else
593
+ #p [ key, val, opts ]
547
594
 
595
+ qs = [ 'include_docs=true' ]
596
+
597
+ if is_option_hash(val)
598
+ opts = val
599
+ else
548
600
  qs << "key=#{Rufus::Doric.escape(val)}"
549
601
  end
550
602
 
603
+ if st = opts[:start] || opts[:startkey]
604
+ qs << "startkey=#{Rufus::Doric.escape(st)}"
605
+ end
606
+ if en = opts[:end] || opts[:endkey]
607
+ qs << "endkey=#{Rufus::Doric.escape(en)}"
608
+ end
609
+
551
610
  add_common_options(qs, opts)
552
611
 
553
612
  skey = case key
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Rufus
3
3
  module Doric
4
- VERSION = '0.1.7'
4
+ VERSION = '0.1.8'
5
5
  end
6
6
  end
7
7
 
data/rufus-doric.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rufus-doric}
8
- s.version = "0.1.7"
8
+ s.version = "0.1.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Mettraux"]
@@ -50,18 +50,21 @@ class UtModelViewRangeTest < Test::Unit::TestCase
50
50
 
51
51
  assert_equal(
52
52
  %w[ climbing drinking ],
53
- Schedule.by_day([ '20101226', nil ]).collect { |s| s.name })
53
+ Schedule.by_day(:start => '20101226').collect { |s| s.name })
54
54
  assert_equal(
55
55
  %w[ climbing drinking ],
56
- Schedule.by_day([ '20101226' ]).collect { |s| s.name })
56
+ Schedule.by_day(:start => '20101226', :end => nil).collect { |s| s.name })
57
57
 
58
58
  assert_equal(
59
59
  %w[ shopping wrestling cooking ],
60
- Schedule.by_day([ nil, '20101225' ]).collect { |s| s.name })
60
+ Schedule.by_day(:end => '20101225').collect { |s| s.name })
61
+ assert_equal(
62
+ %w[ shopping wrestling cooking ],
63
+ Schedule.by_day(:start => nil, :end => '20101225').collect { |s| s.name })
61
64
 
62
65
  assert_equal(
63
66
  %w[ drinking climbing cooking ],
64
- Schedule.by_day([ nil, '20101225' ], :descending => true).collect { |s| s.name })
67
+ Schedule.by_day(:end => '20101225', :descending => true).collect { |s| s.name })
65
68
  end
66
69
 
67
70
  def test_view_limit
@@ -72,10 +75,10 @@ class UtModelViewRangeTest < Test::Unit::TestCase
72
75
 
73
76
  assert_equal(
74
77
  %w[ climbing ],
75
- Schedule.by_day([ '20101226', nil ], :limit => 1).collect { |s| s.name })
78
+ Schedule.by_day(:start => '20101226', :limit => 1).collect { |s| s.name })
76
79
  assert_equal(
77
80
  %w[ drinking ],
78
- Schedule.by_day([ '20101226', nil ], :skip => 1).collect { |s| s.name })
81
+ Schedule.by_day(:start => '20101226', :skip => 1).collect { |s| s.name })
79
82
  end
80
83
 
81
84
  def test_all_opts
@@ -22,6 +22,9 @@ class Team < Rufus::Doric::Model
22
22
  view_by 'tysec', %{
23
23
  emit(doc.type + '__' + doc.security_level, null);
24
24
  }
25
+ view_by 'tysec2', %{
26
+ emit([ doc.type, doc.security_level ], null);
27
+ }
25
28
  end
26
29
 
27
30
 
@@ -40,7 +43,7 @@ class UtModelCustomViewTest < Test::Unit::TestCase
40
43
  #def teardown
41
44
  #end
42
45
 
43
- def test_view_by_and
46
+ def test_views
44
47
 
45
48
  Team.new(
46
49
  'type' => 'rifle',
@@ -63,8 +66,10 @@ class UtModelCustomViewTest < Test::Unit::TestCase
63
66
  'security_level' => 'c'
64
67
  ).save!
65
68
 
66
- assert_equal 2, Team.by_tysec('rifle__a').size
67
- assert_equal 1, Team.by_tysec('rifle__b').size
69
+ assert_equal 2, Team.tysec('rifle__a').size
70
+ assert_equal 1, Team.tysec('rifle__b').size
71
+
72
+ assert_equal 2, Team.tysec2(%w[ rifle a ]).size
68
73
  end
69
74
  end
70
75
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 7
9
- version: 0.1.7
8
+ - 8
9
+ version: 0.1.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Mettraux