mochigome 0.1.16 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
data/TODO CHANGED
@@ -8,3 +8,6 @@
8
8
  - Better handling of nil in subgroup fields
9
9
  - Handle has_and_belongs_to_many correctly
10
10
  - Deal with ignore_assoc properly in both directions and when we see :through assocs
11
+ - Refuse to do huge reports (ids_table more than a few thousand rows) beacuse user probably just screwed up the grouping
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
+ - Some kind of on-write caching feature for records that would be expensive to fully re-aggregate every time (i.e. AttendanceRecord)
data/lib/mochigome_ver.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mochigome
2
- VERSION = "0.1.16"
2
+ VERSION = "0.1.17"
3
3
  end
data/lib/model_graph.rb CHANGED
@@ -110,7 +110,7 @@ module Mochigome
110
110
 
111
111
  model.reflections.
112
112
  reject{|name, assoc| assoc.through_reflection}.
113
- reject{|name, assoc| ignore_assocs.include? name}.
113
+ reject{|name, assoc| ignore_assocs.include? name.to_sym}.
114
114
  to_a.sort{|a,b| a.first.to_s <=> b.first.to_s}.
115
115
  each do |name, assoc|
116
116
  # TODO: What about self associations?
@@ -162,7 +162,8 @@ module Mochigome
162
162
  # Use through reflections as a hint for preferred indirect paths
163
163
  model.reflections.
164
164
  select{|name, assoc| assoc.through_reflection}.
165
- reject{|name, assoc| ignore_assocs.include? name}.
165
+ reject{|name, assoc| ignore_assocs.include? name.to_sym}.
166
+ reject{|name, assoc| ignore_assocs.include? assoc.through_reflection.name.to_sym}.
166
167
  to_a.sort{|a,b| a.first.to_s <=> b.first.to_s}.
167
168
  each do |name, assoc|
168
169
  begin
data/lib/relation.rb CHANGED
@@ -54,14 +54,12 @@ module Mochigome
54
54
  raise QueryError.new("No path to #{model}") unless best_path
55
55
  join_on_path(best_path)
56
56
 
57
- # Also use the conditions of any other direct assoc to the target
58
- # TODO: Or maybe any other assoc that's equal length?
57
+ # Also use the conditions of any other path that's at least that short
59
58
  # TODO: Write a test that requires the below code to work
60
59
  @models.reject{|n| best_path.include?(n)}.each do |n|
61
- cond = @model_graph.edge_condition(n, model)
62
- if cond
63
- join_to_expr_models(cond)
64
- @rel = @rel.where(cond)
60
+ extra_path = @model_graph.path_thru([n, model])
61
+ if extra_path && extra_path.size <= best_path.size
62
+ join_on_path(extra_path, :force_condition => true)
65
63
  end
66
64
  end
67
65
  end
@@ -75,11 +73,17 @@ module Mochigome
75
73
  end
76
74
  end
77
75
 
78
- def join_on_path(path)
76
+ def join_on_path(path, options = {})
79
77
  path = path.map(&:to_real_model).uniq
80
78
  join_to_model path.first
81
79
  (0..(path.size-2)).map{|i| [path[i], path[i+1]]}.each do |src, tgt|
82
- add_join_link(src, tgt) unless @models.include?(tgt)
80
+ if @models.include?(tgt)
81
+ if options[:force_condition]
82
+ apply_condition(@model_graph.edge_condition(src, tgt))
83
+ end
84
+ else
85
+ add_join_link(src, tgt)
86
+ end
83
87
  end
84
88
  end
85
89
 
@@ -3,8 +3,10 @@ class WidgetDivisor < ActiveRecord::Base
3
3
  f.name lambda {|r| "Divisor #{r.divisor}"}
4
4
  f.custom_association Widget, lambda {|src_tbl,tgt_tbl|
5
5
  # Argh, arel doesn't provide easy access to the modulus operator
6
- ((tgt_tbl[:number]/src_tbl[:divisor])*src_tbl[:divisor]).
7
- eq(tgt_tbl[:number])
6
+ (src_tbl[:divisor]*Arel::Nodes::NamedFunction.new(
7
+ "ROUND",
8
+ [(tgt_tbl[:number]/src_tbl[:divisor]) - 0.5]
9
+ )).eq(tgt_tbl[:number])
8
10
  }
9
11
  end
10
12
 
@@ -2,7 +2,7 @@ class CreateTables < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :products do |t|
4
4
  t.string :name
5
- t.decimal :price
5
+ t.decimal :price, :precision => 10, :scale => 2
6
6
  t.integer :category_id
7
7
  t.timestamps
8
8
  end
@@ -282,8 +282,8 @@ describe Mochigome::Query do
282
282
  )
283
283
 
284
284
  data_node = q.run
285
- assert_equal Product.all.map(&:price).sum.to_s,
286
- data_node["Products sum price"].to_s
285
+ assert_equal Product.all.map(&:price).sum.to_f.to_s,
286
+ data_node["Products sum price"].to_f.to_s
287
287
  assert_empty data_node.children
288
288
  end
289
289
 
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: 59
4
+ hash: 57
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 16
10
- version: 0.1.16
9
+ - 17
10
+ version: 0.1.17
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-05 00:00:00 Z
18
+ date: 2012-06-14 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement