dossier-segmenter 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98e767c99db2057ca87c78226335c4800433514b
4
- data.tar.gz: ae308223c209cac474b83bdcb3b94dfb1ee27ace
3
+ metadata.gz: 9c0a7beee75609a16ea0ebec56fb5ef00ec6c609
4
+ data.tar.gz: f628f57c53afa32b00ec87dc740529bf7c8e6139
5
5
  SHA512:
6
- metadata.gz: b569f16bd64f42f669d9962859a1a5995c71a5d8529e540f4e3d03e84ad621e376a904b8be4a12ce11a1a14142ec8250dd3d4f36422613073193be86380ab378
7
- data.tar.gz: 381586de07e4e0c898300c1e4f41eca9a1beec68223e1c6af0213f5bb8ac150d7127bb84c813f10ef4539e4f00a1201b0925a455ceed15eb65a09bde35abc9a4
6
+ metadata.gz: ae6ef17ce24a0160fa5d3cd7278f967d6a1b9326bbef486b89ebf0bce79989c37082ac156681f3f8301eaf08182ccdbea97acea44bcd9e9be3863c1fd7fb1c47
7
+ data.tar.gz: 32c9e83b729b556be902251c7ecd9e5af9f9dedd5724279176c00538f1757af7a0fb3ca0a3f9d7e59c8eb989a6988e315d69f1fc80f3047384780526570b876a
@@ -1,12 +1,11 @@
1
1
  module Dossier
2
2
  class Segment
3
3
  class Definition
4
- attr_accessor :segmenter_class, :report_class, :name, :group_by, :display_name, :next, :prev
4
+ attr_accessor :segmenter_class, :name, :group_by, :display_name, :next, :prev
5
5
  attr_reader :segment_subclass
6
6
 
7
7
  def initialize(segmenter_class, name, options = {})
8
8
  self.segmenter_class = segmenter_class
9
- self.report_class = segmenter_class.report_class
10
9
  self.name = name
11
10
  self.group_by = options.fetch(:group_by, name)
12
11
  self.display_name = options.fetch(:display_name, name)
@@ -53,7 +52,7 @@ module Dossier
53
52
  private
54
53
 
55
54
  def define_segment_subclass
56
- @segment_subclass = report_class.const_set(segment_class_name, Class.new(Dossier::Segment))
55
+ @segment_subclass = segmenter_class.const_set(segment_class_name, Class.new(Dossier::Segment))
57
56
  end
58
57
 
59
58
  def display_name_for_column
@@ -19,13 +19,6 @@ module Dossier
19
19
  def segmenter_class
20
20
  const_get(:Segmenter)
21
21
  end
22
-
23
- def inherited(base)
24
- segmenter_class = Class.new(Dossier::Segmenter)
25
- segmenter_class.report_class = base
26
- base.const_set(:Segmenter, segmenter_class)
27
- super
28
- end
29
22
  end
30
23
 
31
24
  Dossier::Report.send :include, self
@@ -1,5 +1,5 @@
1
1
  module Dossier
2
2
  class Segmenter
3
- VERSION = "0.9.0"
3
+ VERSION = "0.10.0"
4
4
  end
5
5
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Dossier::Segment::Chain do
4
4
  let(:report_class) { Class.new(Dossier::Report) }
5
- let(:segmenter_class) { report_class.segmenter_class }
5
+ let(:segmenter_class) { report_class.const_set(:Segmenter, Class.new(Dossier::Segmenter)) }
6
6
  let(:definition) { Dossier::Segment::Definition.new(segmenter_class, :foo) }
7
7
  let(:next) { Dossier::Segment::Definition.new(segmenter_class, :bar) }
8
8
  let(:chain) { described_class.new.tap { |c| c << definition } }
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Dossier::Segment::Definition do
4
4
  let(:report_class) { Class.new(Dossier::Report) }
5
- let(:segmenter_class) { report_class.segmenter_class }
5
+ let(:segmenter_class) { report_class.const_set(:Segmenter, Class.new(Dossier::Segmenter)) }
6
6
  let(:definition) { described_class.new(segmenter_class, :foo) }
7
7
 
8
8
  describe "attributes" do
@@ -78,7 +78,7 @@ describe Dossier::Segment::Definition do
78
78
  end
79
79
 
80
80
  it "sets up the segment subclasses name constant properly" do
81
- expect(CuteAnimalsReport::Family).to be_a Class
81
+ expect(CuteAnimalsReport::Segmenter::Family).to be_a Class
82
82
  end
83
83
  end
84
84
  end
@@ -3,9 +3,9 @@ require 'spec_helper'
3
3
  describe Dossier::Segment do
4
4
  let(:report_class) { Class.new(Dossier::Report) }
5
5
  let!(:segmenter_class) {
6
- report_class.segmenter_class.tap { |sc|
6
+ report_class.const_set(:Segmenter, Class.new(Dossier::Segmenter) { |sc|
7
7
  sc.segment :foo
8
- }
8
+ })
9
9
  }
10
10
  let(:definition) { segmenter_class.segments.first }
11
11
  let(:report) { report_class.new }
@@ -1,23 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Dossier::Segmenter::Report do
4
- let(:report_class) { Class.new(Dossier::Report) }
5
- let(:segmenter_class) { report_class.const_get(:Segmenter) }
6
- let(:report) { report_class.new }
7
-
8
- it "creates a segment subclass under its own namespace when inherited" do
9
- expect(segmenter_class.ancestors).to include(Dossier::Segmenter)
10
- end
11
-
12
- it "sets its class on the created segment_class" do
13
- expect(segmenter_class.report_class).to eq report_class
14
- end
15
4
 
16
5
  it "has a reference to its segmenter class" do
17
6
  expect(CuteAnimalsReport.segmenter_class).to eq CuteAnimalsReport::Segmenter
18
7
  end
19
8
 
20
- it "does not have a segmenter if no segments have been defined" do
21
- expect(report).to_not be_segmented
22
- end
23
9
  end
@@ -4,14 +4,12 @@ describe Dossier::Segmenter do
4
4
 
5
5
  let(:report_class) { Class.new(Dossier::Report) }
6
6
  let!(:segmenter_class) {
7
- report_class.segmenter_class.tap do |klass|
8
- klass.instance_eval do
7
+ report_class.const_set(:Segmenter, Class.new(described_class) {
9
8
  segment :family
10
9
  segment :domestic, display_name: ->(row) { "#{row[:domestic] ? 'Domestic' : 'Wild'} #{row[:group_name]}" } do
11
10
  segment :group, display_name: :group_name, group_by: :group_id
12
11
  end
13
- end
14
- end
12
+ })
15
13
  }
16
14
  let(:headers) { CuteAnimalsReport::HEADERS.call }
17
15
  let(:rows) { CuteAnimalsReport::ROWS.call }
@@ -69,10 +67,6 @@ describe Dossier::Segmenter do
69
67
  end
70
68
 
71
69
  describe "class" do
72
- it "has a reference to the report that created it" do
73
- expect(segmenter_class.report_class).to eq report_class
74
- end
75
-
76
70
  it "determines headers to skip when displaying" do
77
71
  expect(segmenter_class.skip_headers.sort).to eq %w[family group_name group_id domestic].sort
78
72
  end
@@ -81,7 +75,7 @@ describe Dossier::Segmenter do
81
75
  describe "DSL" do
82
76
  describe "segment" do
83
77
  describe "definition creation" do
84
- let(:segmenter_class) { report_class.segmenter_class }
78
+ let(:segmenter_class) { report_class.const_set(:Segmenter, Class.new(described_class)) }
85
79
  let(:definition) { segmenter_class.segments.last }
86
80
 
87
81
  it "creates a segment definition" do
@@ -32,7 +32,7 @@ class CuteAnimalsReport < Dossier::Report
32
32
  formatter.number_to_dollars(value)
33
33
  end
34
34
 
35
- class Segmenter
35
+ class Segmenter < Dossier::Segmenter
36
36
  segment :family
37
37
  segment :domestic, display_name: ->(row) { "#{row[:domestic] ? 'Domestic' : 'Wild'} #{row[:group_name]}" }
38
38
  segment :group, display_name: :group_name, group_by: :group_id
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dossier-segmenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Hunter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-05 00:00:00.000000000 Z
11
+ date: 2013-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dossier
@@ -136,7 +136,6 @@ files:
136
136
  - LICENSE.txt
137
137
  - README.md
138
138
  - Rakefile
139
- - app/views/dossier/reports/cute_animals.html.haml
140
139
  - dossier-segmenter.gemspec
141
140
  - lib/dossier/segment.rb
142
141
  - lib/dossier/segment/chain.rb
@@ -156,6 +155,7 @@ files:
156
155
  - spec/dossier/segmenter/report_spec.rb
157
156
  - spec/dossier/segmenter_spec.rb
158
157
  - spec/dummy/app/reports/cute_animals_report.rb
158
+ - spec/dummy/app/views/dossier/reports/cute_animals.html.haml
159
159
  - spec/dummy/config.ru
160
160
  - spec/dummy/config/application.rb
161
161
  - spec/dummy/public/favicon.ico
@@ -194,6 +194,7 @@ test_files:
194
194
  - spec/dossier/segmenter/report_spec.rb
195
195
  - spec/dossier/segmenter_spec.rb
196
196
  - spec/dummy/app/reports/cute_animals_report.rb
197
+ - spec/dummy/app/views/dossier/reports/cute_animals.html.haml
197
198
  - spec/dummy/config.ru
198
199
  - spec/dummy/config/application.rb
199
200
  - spec/dummy/public/favicon.ico