mountain-goat 0.0.2 → 0.0.3

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.
@@ -32,8 +32,8 @@ module MetricTracking
32
32
  block.call(SwitchVariant.new( logger, metric, convert, var ) )
33
33
  end
34
34
 
35
- def mv(metric_type, convert_type, default)
36
- return get_metric_variant(metric_type, convert_type, default)
35
+ def mv(metric_type, convert_type, default, opts = {}, opt = nil)
36
+ return get_metric_variant(metric_type, convert_type, default, opts, opt)
37
37
  end
38
38
 
39
39
  #shorthand
@@ -76,47 +76,48 @@ module MetricTracking
76
76
  #we need to see what meta information we should fill based on the conversion type
77
77
  Rally.create!( { :convert_id => convert.id } ).set_meta_data(options)
78
78
 
79
- #we just converted, let's tally each of our metrics (from cookies)
80
- convert.metrics.each do |metric|
81
- metric_sym = "metric_#{metric.metric_type}".to_sym
82
- metric_variant_sym = "metric_#{metric.metric_type}_variant".to_sym
83
-
84
- value = cookies[metric_sym]
85
- variant_id = cookies[metric_variant_sym]
86
-
87
- #logger.warn "Value: #{metric_sym} - #{value}"
88
- #logger.warn "Value: #{metric_variant_sym} - #{variant_id}"
89
-
90
- if variant_id.blank? #the user just doesn't have this set
91
- next
92
- end
93
-
94
- variant = MetricVariant.first(:conditions => { :id => variant_id.to_i } )
95
-
96
- if variant.nil?
97
- logger.error "Variant #{variant_id} not in metric variants for #{metric.title}"
98
- next
99
- end
100
-
101
- if variant.value != value
102
- logger.warn "Variant #{variant.name} values differ for metric #{metric.title}. '#{variant.value}' != '#{value}'!"
79
+ if defined?(cookies)
80
+ #we just converted, let's tally each of our metrics (from cookies)
81
+ convert.metrics.each do |metric|
82
+ metric_sym = "metric_#{metric.metric_type}".to_sym
83
+ metric_variant_sym = "metric_#{metric.metric_type}_variant".to_sym
84
+
85
+ value = cookies[metric_sym]
86
+ variant_id = cookies[metric_variant_sym]
87
+
88
+ #logger.warn "Value: #{metric_sym} - #{value}"
89
+ #logger.warn "Value: #{metric_variant_sym} - #{variant_id}"
90
+
91
+ if variant_id.blank? #the user just doesn't have this set
92
+ next
93
+ end
94
+
95
+ variant = MetricVariant.first(:conditions => { :id => variant_id.to_i } )
96
+
97
+ if variant.nil?
98
+ logger.error "Variant #{variant_id} not in metric variants for #{metric.title}"
99
+ next
100
+ end
101
+
102
+ if variant.value != value
103
+ logger.warn "Variant #{variant.name} values differ for metric #{metric.title}. '#{variant.value}' != '#{value}'!"
104
+ end
105
+
106
+ logger.warn "Tallying conversion #{convert.name} for #{metric.title} - #{variant.name} (#{variant.value} - #{variant.id})"
107
+ variant.tally_convert
103
108
  end
104
-
105
- logger.warn "Tallying conversion #{convert.name} for #{metric.title} - #{variant.name} (#{variant.value} - #{variant.id})"
106
- variant.tally_convert
107
109
  end
108
110
  end
109
111
 
110
112
  private
111
113
 
112
- def get_metric_variant(metric_type, convert_type, default)
113
- metric_sym = "metric_#{metric_type}".to_sym
114
+ def get_metric_variant(metric_type, convert_type, default, opts = {}, opt = nil)
115
+ metric_sym = "metric_#{metric_type}#{ opt.nil? ? "" : '_' + opt.to_s }".to_sym
114
116
  metric_variant_sym = "metric_#{metric_type}_variant".to_sym
115
117
 
116
118
  #first, we'll check for a cookie value
117
- if cookies[metric_sym] && !cookies[metric_sym].blank?
118
- #we have the cookie
119
-
119
+ if defined?(cookies) && cookies[metric_sym] && !cookies[metric_sym].blank?
120
+ #we have the cookie
120
121
  variant_id = cookies[metric_variant_sym]
121
122
  variant = MetricVariant.first(:conditions => { :id => variant_id.to_i } )
122
123
  if !variant.nil?
@@ -124,7 +125,7 @@ module MetricTracking
124
125
  variant.tally_serve
125
126
  end
126
127
  else
127
- logger.warn "Serving metric #{metric_type} without finding / tallying variant."
128
+ logger.warn "Serving metric #{metric_type} #{ opt.nil? ? "" : opt.to_s } without finding / tallying variant."
128
129
  end
129
130
 
130
131
  return cookies[metric_sym] #it's the best we can do
@@ -141,16 +142,20 @@ module MetricTracking
141
142
 
142
143
  if metric_variant.nil?
143
144
  logger.warn "Missing metric variants for #{metric_type}"
144
- metric_variant = MetricVariant.create!( :metric_id => metric.id, :value => default, :name => default )
145
+ metric_variant = MetricVariant.create!( { :metric_id => metric.id, :value => default, :name => default }.merge(opts) )
145
146
  end
146
147
 
147
148
  metric_variant.tally_serve #donate we served this to a user
148
- logger.debug "Serving #{metric_variant.name} (#{metric_variant.value}) for #{metric_sym}"
149
+ value = metric_variant.read_attribute( opt.nil? ? :value : opt )
150
+ logger.debug "Serving #{metric_variant.name} (#{value}) for #{metric_sym}"
149
151
  #good, we have a variant, let's store it in session
150
- cookies[metric_sym] = { :value => metric_variant.value } #, :domain => WILD_DOMAIN
151
- cookies[metric_variant_sym] = { :value => metric_variant.id } #, :domain => WILD_DOMAIN
152
152
 
153
- return metric_variant.value
153
+ if defined?(cookies)
154
+ cookies[metric_sym] = { :value => value } #, :domain => WILD_DOMAIN
155
+ cookies[metric_variant_sym] = { :value => metric_variant.id } #, :domain => WILD_DOMAIN
156
+ end
157
+
158
+ return value
154
159
  end
155
160
  end
156
161
 
@@ -158,7 +163,7 @@ module MetricTracking
158
163
  metric_variant_sym = "metric_#{metric_type}_variant".to_sym
159
164
 
160
165
  #first, we'll check for a cookie selection
161
- if cookies[metric_variant_sym] && !cookies[metric_variant_sym].blank?
166
+ if defined?(cookies) && cookies[metric_variant_sym] && !cookies[metric_variant_sym].blank?
162
167
  #we have the cookie
163
168
 
164
169
  variant_id = cookies[metric_variant_sym]
@@ -195,7 +200,9 @@ module MetricTracking
195
200
  metric_variant.tally_serve #donate we served this to a user
196
201
  logger.debug "Serving #{metric_variant.name} (#{metric_variant.switch_type}) for #{metric.title} (switch-type)"
197
202
  #good, we have a variant, let's store it in session (not the value, just the selection)
198
- cookies[metric_variant_sym] = { :value => metric_variant.id } #, :domain => WILD_DOMAIN
203
+ if defined?(cookies)
204
+ cookies[metric_variant_sym] = { :value => metric_variant.id } #, :domain => WILD_DOMAIN
205
+ end
199
206
 
200
207
  return metric_variant
201
208
  end
@@ -238,4 +245,6 @@ class ActionView::Base
238
245
  include MetricTracking::View
239
246
  end
240
247
 
241
-
248
+ class ActionMailer::Base
249
+ include MetricTracking::Controller
250
+ end
@@ -1,3 +1,3 @@
1
1
  class MountainGoat
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,27 @@
1
+ <%# locals => f %>
2
+
3
+ <%= f.hidden_field :metric_id %>
4
+
5
+ <% if f.object.metric.is_switch %>
6
+ <span class="switch-type"><%=h f.object.switch_type %></span>
7
+ <% end %>
8
+
9
+ <div class="item name">
10
+ <%= f.label :name, 'Variant name' %><br />
11
+ <%= f.text_field :name %>
12
+ </div>
13
+
14
+ <% if !f.object.metric.is_switch %>
15
+ <div class="item value">
16
+ <%= f.label :value, 'Metric value' %><br />
17
+ <%= f.text_area :value %>
18
+ </div>
19
+ <% end %>
20
+ <div class="item priority">
21
+ <%= f.label :priority, 'Priority' %><br />
22
+ <%= f.text_field :priority %>
23
+ </div>
24
+
25
+ <div class="item submit">
26
+ <%= f.submit 'Submit' %>
27
+ </div>
@@ -16,6 +16,16 @@
16
16
  <%= f.label :value, 'Metric value' %><br />
17
17
  <%= f.text_area :value %>
18
18
  </div>
19
+
20
+ <div class="item opt1">
21
+ <%= f.label :opt1, 'Option 1' %><br />
22
+ <%= f.text_area :opt1 %>
23
+ </div>
24
+
25
+ <div class="item opt2">
26
+ <%= f.label :opt2, 'Option 2' %><br />
27
+ <%= f.text_area :opt2 %>
28
+ </div>
19
29
  <% end %>
20
30
  <div class="item priority">
21
31
  <%= f.label :priority, 'Priority' %><br />
Binary file
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mountain-goat
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Geoffrey Hayes
@@ -93,6 +93,7 @@ files:
93
93
  - lib/mountain_goat/views/mountain_goat/mountain_goat_converts/index.html.erb
94
94
  - lib/mountain_goat/views/mountain_goat/mountain_goat_converts/new.html.erb
95
95
  - lib/mountain_goat/views/mountain_goat/mountain_goat_converts/show.html.erb
96
+ - lib/mountain_goat/views/mountain_goat/mountain_goat_metric_variants/.tmp__metric_variant_form.html.erb.87465~
96
97
  - lib/mountain_goat/views/mountain_goat/mountain_goat_metric_variants/_metric_variant_form.html.erb
97
98
  - lib/mountain_goat/views/mountain_goat/mountain_goat_metric_variants/edit.html.erb
98
99
  - lib/mountain_goat/views/mountain_goat/mountain_goat_metric_variants/index.html.erb
@@ -105,6 +106,7 @@ files:
105
106
  - lib/mountain_goat/views/mountain_goat/mountain_goat_metrics/show.html.erb
106
107
  - migrations/20090716093747_create_metric_tracking_tables.rb
107
108
  - mountain-goat-0.0.1.gem
109
+ - mountain-goat-0.0.2.gem
108
110
  - mountain-goat.gemspec
109
111
  has_rdoc: true
110
112
  homepage: http://github.com/hayesgm/mountain-goat