sapling 0.3.0 → 0.4.1

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/README.md CHANGED
@@ -19,7 +19,7 @@ Add a route to your routes file. Feel free to change the 'sapling/stylesheet.css
19
19
  map.sapling_script 'sapling/script.js', :controller => 'sapling', :action => 'script'
20
20
 
21
21
  After including your javascript library, add this:
22
-
22
+
23
23
  <%= javascript_include_tag sapling_script_path, :id => 'sapling_script' %>
24
24
 
25
25
  Run the `db/create.sql` file to create the sapling_settings table on your DB
@@ -34,34 +34,34 @@ Ensure you have a current_user method to your application controller, which retu
34
34
  end
35
35
  ...
36
36
  end
37
-
38
37
 
39
-
38
+
39
+
40
40
  For a given feature `space_chat`,
41
41
 
42
42
  Server-side Usage
43
43
  -----------------
44
44
 
45
45
  To check if a feature is enabled for a user in rails controllers or views: use
46
-
46
+
47
47
  sapling.active?(:space_chat [, :user => the current user])
48
-
49
-
48
+
49
+
50
50
  *Note*: sapling will automatically populate the user argument by calling `current_user`
51
-
51
+
52
52
  To get the css classes the javascript adds to the HTML element for a feature:
53
53
 
54
54
  sapling.css_class(:space_chat)
55
- sapling.css_toggle_class(:space_chat)
56
-
55
+ sapling.css_toggle_class(:space_chat)
56
+
57
57
  To enable a feature for a specific user, in the rails console:
58
-
58
+
59
59
  Sapling::ActiveRecord.new.activate_user(:space_chat, space_admin)
60
-
60
+
61
61
  To disable a feature for a specific user, in the rails console:
62
-
62
+
63
63
  Sapling::ActiveRecord.new.deactivate_user(:space_chat, space_admin)
64
-
64
+
65
65
  To enable a feature for 50% of the users, in the rails console:
66
66
 
67
67
  Sapling::ActiveRecord.new.activate_percentage(:space_chat, 50)`
@@ -69,7 +69,7 @@ To enable a feature for 50% of the users, in the rails console:
69
69
  To disable a feature activated for anyone but individually-activated users, in the rails console:
70
70
 
71
71
  Sapling::ActiveRecord.new.deactivate_percentage(:space_chat)
72
-
72
+
73
73
  *Note*: Individually-activated users are always activated, regardless of the percentage setting. A deactivated user
74
74
  may still have access to a feature if they fall within an active percentage.
75
75
 
@@ -78,15 +78,21 @@ Custom Feature-Active Tests
78
78
 
79
79
  You can optionally inject your own code for testing if a feature is active. In rails, just added methods of the following form to your ApplicationController:
80
80
 
81
- # Example: override feature-active? for feature :new_homepage
82
- # options:
81
+ # Example: override feature-active? for feature :new_homepage
82
+ #
83
+ # options:
83
84
  # :feature => object of type Sapling::Feature
84
85
  # (current settings for the feature from the database)
85
- # :user => user to test for feature-active
86
+ # :active => true if the feature would be active without the override
87
+ #
88
+ # remaining options are those passed to 'sapling.active?'
89
+ # :user => user to test for feature-active
90
+ # :context_id => Integer
91
+ #
86
92
  # return true if the feature is active.
87
- def new_homepage_active?(options={})
93
+ def new_homepage_active?(options={})
88
94
  # your test here
89
- end
95
+ end
90
96
 
91
97
  *Note* If you are using Sapling manually, when you create a Sapling instance, you can pass in an any object which responds to "current_user" and implements zero or more of your feature-active overrides.
92
98
 
@@ -130,8 +136,8 @@ ERB:
130
136
  <div class="<%= sapling.css_class(:chat) %> disabled">
131
137
  DESPAIR - SPIFF CHAT NOT ENABLED FOR YOU
132
138
  </div>
133
-
134
-
139
+
140
+
135
141
  *Note* Currently, the javascript generated depends on MooTools being loaded first.
136
142
 
137
143
  TODO
@@ -8,3 +8,12 @@ When using Sapling in rails, there are some api changes:
8
8
 
9
9
  old: feature_class(feature_name)
10
10
  new: sapling.css_class(feature_name)
11
+
12
+ 0.4.1
13
+ =====
14
+
15
+ Added option value for overrides. The hash value :active is now passed into
16
+ every override method called. This indicates if the feature would be active
17
+ without the override.
18
+
19
+ Fixed fatal bug in the Sapling+Rails controller javascript generation.
@@ -11,22 +11,15 @@ module Sapling
11
11
  private
12
12
  def active_internal(feature_name,options)
13
13
  feature_method = "#{feature_name}_active?".to_sym
14
+ base_active = (f=features[feature_name]) && f.active?(options)
14
15
  if controller && controller.respond_to?(feature_method)
15
16
  # use override
16
- controller.send(feature_method,options.merge(:feature => features[feature_name]))
17
+ controller.send(feature_method,options.merge(:feature => features[feature_name],:active => base_active))
17
18
  else
18
- (f=features[feature_name]) && f.active?(options)
19
+ base_active
19
20
  end
20
21
  end
21
22
 
22
- # override feature test example for feature :new_homepage
23
- # options:
24
- # feature is of type Feature
25
- # :user
26
- # returns true if the feature is enabled
27
- # def new_homepage_active?(options={})
28
- # # your test here
29
- # end
30
23
  public
31
24
 
32
25
  # see Sapling::API::Client
@@ -45,7 +38,7 @@ module Sapling
45
38
  end
46
39
 
47
40
  def js_generator
48
- @js_generator ||= JavascriptGenerator.new
41
+ @js_generator ||= JavascriptGenerator.new(self)
49
42
  end
50
43
 
51
44
  def css_class_prefix
@@ -1,3 +1,3 @@
1
1
  module Sapling
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -1,4 +1,4 @@
1
- require 'test_helper'
1
+ require File.join(File.dirname(__FILE__),"..",'test_helper')
2
2
 
3
3
  class FeatureTest < ActionController::IntegrationTest
4
4
  fixtures :all
@@ -10,6 +10,13 @@ class FeatureTest < ActionController::IntegrationTest
10
10
  assert_equal '1', response.body
11
11
  end
12
12
 
13
+ # Replace this with your real tests.
14
+ test "js generation works" do
15
+ post user_sessions_path, :user_id => 1
16
+ get "/sapling/script.js"
17
+ assert response.body['sapling_feature_my_custom_test_feature_on']
18
+ end
19
+
13
20
  test "users cant use 'my_custom_test_feature'" do
14
21
  # user1 is listed, user2 is not
15
22
  assert Sapling::ActiveRecord.new.features[:my_custom_test_feature].users[1]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sapling
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 0
10
- version: 0.3.0
8
+ - 4
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Shane Brinkman-Davis
@@ -16,7 +16,8 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-02-03 00:00:00 Z
19
+ date: 2012-02-03 00:00:00 -08:00
20
+ default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
22
23
  name: activerecord
@@ -201,6 +202,7 @@ files:
201
202
  - spec/sapling_examples.rb
202
203
  - spec/spec.opts
203
204
  - spec/spec_helper.rb
205
+ has_rdoc: true
204
206
  homepage: https://github.com/imikimi/sapling
205
207
  licenses: []
206
208
 
@@ -230,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
232
  requirements: []
231
233
 
232
234
  rubyforge_project: sapling
233
- rubygems_version: 1.8.10
235
+ rubygems_version: 1.5.3
234
236
  signing_key:
235
237
  specification_version: 3
236
238
  summary: Incrementally roll out your features. Uses ActiveRecord to store configuration and supports client-side roll-out of cached pages.