stat_board 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,6 +20,8 @@ A simple dashboard of records created this week, this month, and all time, mount
20
20
 
21
21
  StatBoard.models = [User, Post, Comment]
22
22
 
23
+ Models can also be listed as strings if you encounter any loading order issues.
24
+
23
25
  ## Additonal Configuration
24
26
 
25
27
  In `config/initializers/stat_board.rb`:
@@ -4,6 +4,14 @@ module StatBoard
4
4
  class StatsController < ApplicationController
5
5
  before_filter :basic_authenticate, :if => lambda { StatBoard.username && StatBoard.password }
6
6
 
7
+ def index
8
+ @reports = [
9
+ Reports::OverallReport.new,
10
+ Reports::MonthlyReport.new,
11
+ Reports::WeeklyReport.new
12
+ ]
13
+ end
14
+
7
15
  private
8
16
 
9
17
  def basic_authenticate
@@ -1,8 +1,8 @@
1
- <div id="<%= title.downcase.gsub(" ", "-") %>" class="span4">
1
+ <div id="<%= report.slug %>" class="span4">
2
2
  <table class="table table-striped">
3
3
  <thead>
4
4
  <tr>
5
- <th colspan="2"><%= title %></th>
5
+ <th colspan="2"><%= report.name %></th>
6
6
  </tr>
7
7
  </thead>
8
8
 
@@ -10,7 +10,7 @@
10
10
  <% StatBoard.models.each do |model| %>
11
11
  <tr>
12
12
  <td class="span2"><%= model.to_s.pluralize %></td>
13
- <td class="span2"><%= scope[model].count %></td>
13
+ <td class="span2"><%= report.count(model) %></td>
14
14
  </tr>
15
15
  <% end %>
16
16
  </tbody>
@@ -1,16 +1,6 @@
1
1
  <% if StatBoard.models %>
2
2
  <div class="row">
3
- <%= render "chart",
4
- :title => "Overall",
5
- :scope => lambda { |klass| klass } %>
6
-
7
- <%= render "chart",
8
- :title => "This Month",
9
- :scope => lambda { |klass| klass.where(["created_at > ?", 1.month.ago]) } %>
10
-
11
- <%= render "chart",
12
- :title => "This Week",
13
- :scope => lambda { |klass| klass.where(["created_at > ?", 1.week.ago]) } %>
3
+ <%= render :partial => "chart", :collection => @reports, :as => :report %>
14
4
  </div>
15
5
  <% else %>
16
6
  Please specify some models by setting <code>StatBoard.models</code>
@@ -1,4 +1,8 @@
1
1
  require "stat_board/engine"
2
+ require "stat_board/reports/report"
3
+ require "stat_board/reports/overall_report"
4
+ require "stat_board/reports/monthly_report"
5
+ require "stat_board/reports/weekly_report"
2
6
 
3
7
  module StatBoard
4
8
  mattr_accessor :models, :title, :username, :password
@@ -0,0 +1,13 @@
1
+ module StatBoard
2
+ module Reports
3
+ class MonthlyReport < Report
4
+ def name
5
+ "This Month"
6
+ end
7
+
8
+ def scope(model)
9
+ super.where(["created_at > ?", 1.month.ago])
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module StatBoard
2
+ module Reports
3
+ class OverallReport < Report
4
+ def name
5
+ "Overall"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ module StatBoard
2
+ module Reports
3
+ class Report
4
+ def name
5
+ # define in subclass
6
+ end
7
+
8
+ def scope(model)
9
+ if model.is_a?(String)
10
+ model.constantize
11
+ else
12
+ model
13
+ end
14
+ end
15
+
16
+ def slug
17
+ name.downcase.gsub(" ", "-")
18
+ end
19
+
20
+ def count(model)
21
+ scope(model).count
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ module StatBoard
2
+ module Reports
3
+ class WeeklyReport < Report
4
+ def name
5
+ "This Week"
6
+ end
7
+
8
+ def scope(model)
9
+ super.where(["created_at > ?", 1.week.ago])
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module StatBoard
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stat_board
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-28 00:00:00.000000000 Z
12
+ date: 2012-11-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -91,6 +91,10 @@ files:
91
91
  - app/views/stat_board/stats/index.html.erb
92
92
  - config/routes.rb
93
93
  - lib/stat_board/engine.rb
94
+ - lib/stat_board/reports/monthly_report.rb
95
+ - lib/stat_board/reports/overall_report.rb
96
+ - lib/stat_board/reports/report.rb
97
+ - lib/stat_board/reports/weekly_report.rb
94
98
  - lib/stat_board/version.rb
95
99
  - lib/stat_board.rb
96
100
  - lib/tasks/stat_board_tasks.rake
@@ -98,7 +102,8 @@ files:
98
102
  - Rakefile
99
103
  - README.markdown
100
104
  homepage: https://github.com/vigetlabs/stat_board
101
- licenses: []
105
+ licenses:
106
+ - MIT
102
107
  post_install_message:
103
108
  rdoc_options: []
104
109
  require_paths: