mochigome 0.1.21 → 0.1.22

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.
Files changed (4) hide show
  1. data/TODO +1 -0
  2. data/lib/mochigome_ver.rb +1 -1
  3. data/lib/relation.rb +29 -19
  4. metadata +4 -4
data/TODO CHANGED
@@ -11,3 +11,4 @@
11
11
  - Refuse to do huge reports (ids_table more than a few thousand rows) beacuse user probably just screwed up the grouping
12
12
  - Allow row counts that skip layers (i.e. a school count report on School$region, SchoolDetail$comp_shelter should have a top-level box that summarizes the # of schools that do and do not have competency shelters)
13
13
  - Some kind of on-write caching feature for records that would be expensive to fully re-aggregate every time (i.e. AttendanceRecord)
14
+ - Some cancan joins must be allowed to double-back over already-joined tables (i.e. the troublesome SchoolStudent ability)
data/lib/mochigome_ver.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mochigome
2
- VERSION = "0.1.21"
2
+ VERSION = "0.1.22"
3
3
  end
data/lib/relation.rb CHANGED
@@ -59,13 +59,13 @@ module Mochigome
59
59
  @models.reject{|n| best_path.include?(n)}.each do |n|
60
60
  extra_path = @model_graph.path_thru([n, model])
61
61
  if extra_path && extra_path.size <= best_path.size
62
- join_on_path(extra_path, :force_condition => true)
62
+ join_on_path extra_path
63
63
  end
64
64
  end
65
65
  end
66
66
 
67
67
  def join_on_path_thru(path)
68
- full_path = @model_graph.path_thru(path).uniq
68
+ full_path = @model_graph.path_thru(path)
69
69
  if full_path
70
70
  join_on_path(full_path)
71
71
  else
@@ -74,16 +74,18 @@ module Mochigome
74
74
  end
75
75
 
76
76
  def join_on_path(path, options = {})
77
- path = path.map(&:to_real_model).uniq
78
- join_to_model path.first
79
- (0..(path.size-2)).map{|i| [path[i], path[i+1]]}.each do |src, tgt|
80
- if @models.include?(tgt)
81
- if options[:force_condition]
77
+ begin
78
+ path = path.map(&:to_real_model).uniq
79
+ join_to_model path.first
80
+ (0..(path.size-2)).map{|i| [path[i], path[i+1]]}.each do |src, tgt|
81
+ if @models.include?(tgt)
82
82
  apply_condition(@model_graph.edge_condition(src, tgt))
83
+ else
84
+ add_join_link(src, tgt)
83
85
  end
84
- else
85
- add_join_link(src, tgt)
86
86
  end
87
+ rescue QueryError => e
88
+ raise QueryError.new("Error pathing #{path.map(&:name).inspect}: #{e}")
87
89
  end
88
90
  end
89
91
 
@@ -116,15 +118,22 @@ module Mochigome
116
118
 
117
119
  def apply_access_filter_func(func)
118
120
  @models.each do |m|
119
- h = func.call(m)
120
- h.delete(:join_paths).try :each do |path|
121
- join_on_path path
122
- end
123
- if h[:condition]
124
- apply_condition h.delete(:condition)
125
- end
126
- unless h.empty?
127
- raise QueryError.new("Unknown assoc filter keys #{h.keys.inspect}")
121
+ begin
122
+ h = func.call(m)
123
+ h.delete(:join_paths).try :each do |path|
124
+ # FIXME: Eventually we need to support joins that
125
+ # double back, if only for CanCan stuff, so get rid of this
126
+ # uniq junk.
127
+ join_on_path_thru path.uniq
128
+ end
129
+ if h[:condition]
130
+ apply_condition h.delete(:condition)
131
+ end
132
+ unless h.empty?
133
+ raise QueryError.new("Unknown assoc filter keys #{h.keys.inspect}")
134
+ end
135
+ rescue QueryError => e
136
+ raise QueryError.new("Error checking access to #{m.name}: #{e}")
128
137
  end
129
138
  end
130
139
  end
@@ -137,7 +146,8 @@ module Mochigome
137
146
 
138
147
  @model_join_stack.push tgt
139
148
  begin
140
- cond = @model_graph.edge_condition(src, tgt)
149
+ cond = @model_graph.edge_condition(src, tgt) or
150
+ raise QueryError.new("No direct link from #{src} to #{tgt}")
141
151
  join_to_expr_models(cond)
142
152
  @rel = @rel.join(tgt.arel_table, Arel::Nodes::InnerJoin).on(cond)
143
153
  ensure
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mochigome
3
3
  version: !ruby/object:Gem::Version
4
- hash: 49
4
+ hash: 55
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 21
10
- version: 0.1.21
9
+ - 22
10
+ version: 0.1.22
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Mike Simon
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-15 00:00:00 Z
18
+ date: 2012-07-17 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement