disclaimer 0.0.1 → 0.0.2

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.rdoc CHANGED
@@ -4,7 +4,19 @@ A tool for adding disclaimers to applications.
4
4
 
5
5
  == Installation
6
6
 
7
- === Gemfile TODO - add config option
7
+ To use this engine:
8
+
9
+ === Gemfile
10
+
11
+ Add the following to your Gemfile
12
+
13
+ gem 'disclaimer'
14
+
15
+ === Migrations
16
+
17
+ To add disclaimer's migrations to the host apps' migrations, run this command:
18
+
19
+ rake disclaimer:install:migrations
8
20
 
9
21
  === Routing
10
22
 
@@ -16,12 +28,15 @@ See test/dummy/config/routes.rb
16
28
 
17
29
  == Usage
18
30
 
19
- First create a disclaimer document (see below) and give it a name. (The name is in underscore form: like_this).
31
+ First create a disclaimer document (see below) and give it a name. (The name is
32
+ in underscore form: like_this).
20
33
 
21
- Then in your application controller, define the disclaimer you wish to use with 'disclaimer(:document_name)'.
34
+ Then in your application controller, define the disclaimer you wish to use with
35
+ 'disclaimer(:document_name)'.
22
36
 
23
- So for example, you have a disclaimer document with the name :our_company_disclaimer and you want to make sure that
24
- everyone who visits your products controller has accepted this disclaimer. Modify the controller like this:
37
+ So for example, you have a disclaimer document with the name :our_company_disclaimer
38
+ and you want to make sure that everyone who visits your products controller has
39
+ accepted this disclaimer. Modify the controller like this:
25
40
 
26
41
  class ProductsController < ApplicationController
27
42
 
@@ -32,29 +47,52 @@ everyone who visits your products controller has accepted this disclaimer. Modif
32
47
 
33
48
  end
34
49
 
35
- Then when a user navigates to the products controller, they will be redirected to the disclaimer document at:
50
+ Then when a user navigates to the products controller, they will be redirected
51
+ to the disclaimer document at:
36
52
 
37
53
  /disclaimer/documents/our_company_disclaimer
38
54
 
39
- If they accept the disclaimer, they will be redirected back to the page they were originally aiming for.
55
+ If they accept the disclaimer, they will be redirected back to the page they were
56
+ originally aiming for.
40
57
 
41
- The acceptance is stored in session and therefore will be remembered for as long as the browser is open.
58
+ The acceptance is stored in session and therefore will be remembered for as long
59
+ as the browser is open.
42
60
 
43
61
  === Options
44
62
 
45
- A before_filter is used to provide this functionality, and you can pass before_filter options through from
46
- the disclaimer declaration. Therefore, to only display a disclaimer for the index and show actions in a controller
63
+ A before_filter is used to provide this functionality, and you can pass
64
+ before_filter options through from the disclaimer declaration. Therefore, to
65
+ only display a disclaimer for the index and show actions in a controller
47
66
  use:
48
67
 
49
68
  disclaimer :our_company_disclaimer, :only => [:index, :show]
50
69
 
51
70
  == Documents and Segments
52
71
 
53
- Documents can be created at /disclaimer/documents, and Segments as /disclaimer/segments. Documents can contain
54
- many segments, and segments can be shared across many documents (that is, you can share common sections of a disclaimer
55
- across many documents). This behaviour can be overwritten in the host application.
72
+ Each disclaimer consists of a Disclaimer::Document, and this document can have
73
+ many Segments. Segments can be shared across many documents.
74
+
75
+ == Controller CRUD actions
76
+
77
+ By default, documents#show (GET) and documents#accept (POST) are the only acceptable
78
+ disclaimer actions.
79
+
80
+ If you wish to enable all the CRUD actions available in the documents and segments
81
+ controllers, set Disclaimer.enable_crud! in an initializer. For example, see
82
+ test/dummy/config/initializers/disclaimer.rb
83
+
84
+ With CRUD actions enabled documents can be managed at /disclaimer/documents, and
85
+ Segments at /disclaimer/segments. If you wish to modify the controller behaviour
86
+ (for example by adding access control), copy disclaimer's app/disclaimer/controllers
87
+ to the same location in your application, and modify these copies. The versions
88
+ in your application will take precedence over those in disclaimer.
89
+
90
+ == Into production
91
+
92
+ I would recommend using seeding to generate your initial disclaimer documents,
93
+ or you could create a custom rake task to do this for you. Alternatively use
94
+ the option used in test/dummy:
56
95
 
57
- The disclaimer engine does not restrict access to these controllers. Such restriction should be configured in
58
- the host application. However, everyone needs access to the disclaimer documents#show action so that they can read
59
- and accept the disclaimer.
96
+ disclaimer Disclaimer::Document.first.name.to_sym
60
97
 
98
+ This will display the first disclaimer document in your database.
data/config/routes.rb CHANGED
@@ -1,18 +1,32 @@
1
1
  Disclaimer::Engine.routes.draw do
2
2
 
3
- root :to => "documents#index"
4
-
5
- resources :documents do
6
- member do
7
- get :delete
8
- post :accept
3
+ if Disclaimer.enable_crud?
4
+ root :to => "documents#index"
5
+
6
+ resources :documents do
7
+ member do
8
+ get :delete
9
+ post :accept
10
+ end
9
11
  end
10
- end
12
+
13
+ resources :segments do
14
+ member do
15
+ get :delete
16
+ end
17
+ end
18
+
19
+ else
11
20
 
12
- resources :segments do
13
- member do
14
- get :delete
21
+ resources :documents, :only => :show do
22
+ member do
23
+ post :accept
24
+ end
15
25
  end
26
+
27
+
28
+
16
29
  end
30
+
17
31
 
18
32
  end
@@ -1,3 +1,3 @@
1
1
  module Disclaimer
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/disclaimer.rb CHANGED
@@ -1,6 +1,14 @@
1
1
  require "disclaimer/engine"
2
- require 'rails/actionpack/lib/action_controller/base'
2
+ require File.expand_path('rails/actionpack/lib/action_controller/base', File.dirname(__FILE__))
3
3
 
4
4
  module Disclaimer
5
5
  ACCEPTED = :accepted
6
+
7
+ def self.enable_crud?
8
+ @enable_crud
9
+ end
10
+
11
+ def self.enable_crud!
12
+ @enable_crud = true
13
+ end
6
14
  end
@@ -0,0 +1,2 @@
1
+ # Allow CRUD actions from document and segment controllers
2
+ Disclaimer.enable_crud!
@@ -1,5 +1,5 @@
1
1
  Rails.application.routes.draw do
2
-
2
+
3
3
  resources :sample, :only => [:index] do
4
4
  collection do
5
5
  get :bypass_disclaimer
Binary file