trackoid 0.1.3 → 0.1.4

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -84,7 +84,7 @@ module Mongoid #:nodoc:
84
84
 
85
85
  # Defines the aggregation model. It checks for class name conflicts
86
86
  def define_aggregate_model
87
- raise Errors::ClassAlreadyDefined.new(internal_aggregates_name) if foreign_class_defined
87
+ raise Errors::ClassAlreadyDefined.new(internal_aggregates_name) if foreign_class_defined?
88
88
  parent_name = self.name.underscore
89
89
  define_klass do
90
90
  include Mongoid::Document
@@ -106,8 +106,12 @@ module Mongoid #:nodoc:
106
106
 
107
107
  # Returns true if there is a class defined with the same name as our
108
108
  # aggregate class.
109
- def foreign_class_defined
110
- Object.const_defined?(internal_aggregates_name.to_sym)
109
+ def foreign_class_defined?
110
+ # The following construct doesn't work with namespaced constants.
111
+ # Object.const_defined?(internal_aggregates_name.to_sym)
112
+
113
+ cn = internal_aggregates_name.constantize rescue nil
114
+ !cn.nil?
111
115
  end
112
116
 
113
117
  # Adds the aggregate field to the array of aggregated fields.
@@ -96,29 +96,14 @@ module Mongoid #:nodoc:
96
96
  # Private methods
97
97
  private
98
98
  def data_for(date)
99
- return 0 if @data.nil? ||
100
- @data[date.year.to_s].nil? ||
101
- @data[date.year.to_s][date.month.to_s].nil?
102
- @data[date.year.to_s][date.month.to_s][date.day.to_s] || 0
99
+ @data.try(:[], date.year.to_s).try(:[], date.month.to_s).try(:[], date.day.to_s) || 0
103
100
  end
104
101
 
105
- # TODO: It should be a better way of updating a hash. :-)
106
102
  def update_data(value, date)
107
- if @data[date.year.to_s]
108
- if @data[date.year.to_s][date.month.to_s]
109
- @data[date.year.to_s][date.month.to_s][date.day.to_s] = value
110
- else
111
- @data[date.year.to_s][date.month.to_s] = {
112
- date.day.to_s => value
113
- }
114
- end
115
- else
116
- @data[date.year.to_s] = {
117
- date.month.to_s => {
118
- date.day.to_s => value
119
- }
120
- }
121
- end
103
+ [:year, :month].inject(@data) { |data, period|
104
+ data[date.send(period).to_s] ||= {}
105
+ }
106
+ @data[date.year.to_s][date.month.to_s][date.day.to_s] = value
122
107
  end
123
108
 
124
109
  def year_literal(d); "#{d.year}"; end
data/trackoid.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{trackoid}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jose Miguel Perez"]
12
- s.date = %q{2010-06-06}
12
+ s.date = %q{2010-07-14}
13
13
  s.description = %q{Trackoid uses an embeddable approach to track analytics data using the poweful features of MongoDB for scalability}
14
14
  s.email = %q{josemiguel@perezruiz.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trackoid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jose Miguel Perez
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-06 00:00:00 +02:00
18
+ date: 2010-07-14 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency