happy_path 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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjViM2I0ZDk0NTFmMjY2YjFiYTZlOGZhM2Q5ODRkM2MxNDI4ZTNlMQ==
4
+ YWUwYzk5YWRmOGJlNmU2MWU1ZDgxOWRkZmM1OTYxNTdjNGFiNjE0NA==
5
5
  data.tar.gz: !binary |-
6
- ZGI4MGM5NTI4MTRkMGRhNGZhZWRjYjVmYTRiZjZjNTZlYjhhZWMzYQ==
6
+ NWRiYmM0ZmFlNWUzYmNmNGU4ZWU1NzVkYjlmYTIzYTVkNDgwMzM3Ng==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODJhODgzMzc1MGFlYTNhMGRhYmM2ZmQxODYwM2I2YmI0ZjVjYjI0MjhiNWI4
10
- ZTBhNzE2Y2ZmNzE2NzYwMDU2N2I2ZThhNzQ4Zjk5MTVjNDA3NmNmZTcxMzIy
11
- ZjA4YmY0MzYyOGY3MWZmYTA5NThmNzg0OTNkODYxMDA4NWMxZTA=
9
+ NWRlNjc5OGIyMDQzOTAwN2Y2ODA5YzljYWI5NDBhZDgzM2FkNzEzNjFiZTRi
10
+ NGYyOWIzOGRkMjU0ZWJjZTk5Mzc2MWIxMjhkZTRmMDI2NzczZDg0ZDhjNDYy
11
+ YWU0MDAzNGUxNDRmMDRiMmMyOGI5NjY0OTkyMWY2NzExNTdlNjg=
12
12
  data.tar.gz: !binary |-
13
- MmE1M2I5MzAyNzBlNDRhMGEzMTM3YmViYmMzNDUxYjJmMDE5NzFjMTZmYzg4
14
- M2FiMmFhNzNlNmE0OTE4OWRhMjYyZjlkZjM3YjAzZGZkNmYwZTJjNTg4ZDk2
15
- MjcyZjhjODc0NTA2NTM3ZmFkN2RmNGZhZmNmMjI5OTNmM2NjYzc=
13
+ YjE3OTQ3YjJmYTExN2FkMDIyMzA5OWYxZGQ4OTA4MjhkZTA2YmVjZjdlODdj
14
+ NmQwMjlmN2U4NDYzYTJjOWNmMGJlZGE4ZTFjMmE1YTRiZTg2OGMwYmJhNmYx
15
+ Y2RlYTAzZTdhZWE2NDU1OGY1OGQ2OWIxOGYzNjE4NjZkN2M3MjM=
data/README.md CHANGED
@@ -1,6 +1,24 @@
1
+ [![Gem Version](https://badge.fury.io/rb/happy_path.svg)](http://badge.fury.io/rb/happy_path)
1
2
  # HappyPath
2
3
 
3
- TODO: Write a gem description
4
+ 1. Navigate to your `posts/new` form.
5
+ 2. Fill it out, hit create.
6
+ 3. Go do other stuff.
7
+ 4. Navigate back to your last post.
8
+ 5. But wait what was the id of that post?
9
+ 6. Go to command line
10
+ 7. `rails c` your way into typing `Post.last.id`
11
+ 8. Go to `posts/id`
12
+ 9. Tedious.
13
+
14
+ With HappyPath, you can just do:
15
+
16
+ 1. Navigate to your `posts/new` form.
17
+ 2. Fill it out, hit create.
18
+ 3. Go do other stuff.
19
+ 4. Navigate back to your last post with `/posts/last`.
20
+
21
+ This is enabled for `/last` and `/first`.
4
22
 
5
23
  ## Installation
6
24
 
@@ -16,9 +34,11 @@ Or install it yourself as:
16
34
 
17
35
  $ gem install happy_path
18
36
 
19
- ## Usage
37
+ ## How Do the Things?
38
+
39
+ After installation, put `extend HappyPath` in your `ApplicationController` and then any controllers you want this functionality to work in such as `posts_controller.rb`.
20
40
 
21
- TODO: Write usage instructions here
41
+ Then put `setup_happy_path` in ApplicationController, and `follow_happy_paths` in each other controller and you are good to go.
22
42
 
23
43
  ## Contributing
24
44
 
@@ -1,3 +1,3 @@
1
1
  module HappyPath
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/happy_path.rb CHANGED
@@ -1,16 +1,17 @@
1
1
  module HappyPath
2
- extend ActiveSupport::Concern
3
2
  PATHS = ['first', 'last']
4
3
 
5
4
  def setup_happy_path
6
- rescue_from ActiveRecord::RecordNotFound, with: :happy_paths
5
+ rescue_from ActiveRecord::RecordNotFound do |e|
6
+ class_constant = controller_name.classify.constantize
7
+ raise e unless self.respond_to?(:happy_paths) && self.respond_to?(:show) && HappyPath::PATHS.include?(params[:id]) && !class_constant.count.zero?
8
+ self.happy_paths(e, class_constant)
9
+ end
7
10
  end
8
11
 
9
12
  def follow_happy_paths
10
- define_method (:happy_paths) do |exception|
11
- class_constant = controller_name.classify.constantize
12
- raise exception unless self.respond_to?(:show) && HappyPath::PATHS.include?(params[:id]) && !class_constant.count.zero?
13
- redirect_to action: :show, id: class_constant.send(params[:id]).id
13
+ define_method (:happy_paths) do |exception, class_constant|
14
+ redirect_to action: params[:action], id: class_constant.send(params[:id]).id
14
15
  end
15
16
  end
16
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: happy_path
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - danReynolds
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-06 00:00:00.000000000 Z
11
+ date: 2014-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler