roda-action 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +68 -8
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32f09854e0f79ab4da1c0fa5b20686b2894abb11
4
- data.tar.gz: 1e1ec879bb44e6fa005247c6859cbc43ddf0c918
3
+ metadata.gz: 7d75dac923931fb09b1f939b98ccb0d49cb2b012
4
+ data.tar.gz: c5633b96f98290978a256e1fba19d59b623e53f9
5
5
  SHA512:
6
- metadata.gz: 636022647521cc888bc4ae8e64ba0d0cf4bfe4990ba16e5f1e58268d066cfd6db6a6e67d5163ea81534830cb4d88dc6befc9e106646e76d9581077b431d232aa
7
- data.tar.gz: 69a8a7e3700aa77c982c4b99180a6c05249cf182fc8ce5bc11bb17d01c38813331396a542001339b8c68e5d75ff92c416f779ce80df99612623104f6012e83cd
6
+ metadata.gz: 4f4049f11ec8896ad165c9156cc34db34b7d552a08126e10c061b8d011dcdaca425037dacd6995c870457e4b86535a98d35708fad8dba5b170af28de7b3f35f3
7
+ data.tar.gz: 97a311a592bc1d34a943c4e09b90e6e3a11778830af949124ee43867dce05621048c012ca4d54629d40f9efb8c1237e0f27695e9f696ec614bed762e63205e31
data/README.md CHANGED
@@ -5,13 +5,14 @@ A plugin for Roda to resolve actions from roda-container
5
5
  ## Installation
6
6
 
7
7
  ```ruby
8
- gem 'roda-action', '0.0.1'
8
+ gem 'roda-action', '0.0.2'
9
9
  ```
10
10
 
11
11
  ## Usage
12
12
 
13
13
  ```ruby
14
14
  class MyApplication < Roda
15
+ plugin :json
15
16
  plugin :action
16
17
  end
17
18
 
@@ -23,22 +24,22 @@ class UsersController
23
24
  end
24
25
 
25
26
  def index
26
- repository.values
27
+ repository
27
28
  end
28
29
 
29
30
  def show(user_id)
30
- repository[user_id]
31
+ repository[user_id.to_i - 1]
31
32
  end
32
33
  end
33
34
 
34
35
  MyApplication.register(:users_controller) do
35
- UsersController.new({
36
- '1' => { name: 'Jack' },
37
- '2' => { name: 'Gill' }
38
- })
36
+ UsersController.new([
37
+ { name: 'Jack' },
38
+ { name: 'Gill' }
39
+ ])
39
40
  end
40
41
 
41
- route do |r|
42
+ MyApplication.route do |r|
42
43
  r.on 'users' do
43
44
  r.is do
44
45
  r.get(&MyApplication.action(:users_controller, :index))
@@ -51,6 +52,65 @@ route do |r|
51
52
  end
52
53
  ```
53
54
 
55
+ If you wish to have access to the usual Roda application instance methods in your registered controllers, it is recommended that you register the application and resolve it for use in your controllers:
56
+
57
+ ```ruby
58
+ class MyApplication < Roda
59
+ plugin :json
60
+ plugin :action
61
+ end
62
+
63
+ class UsersController
64
+ attr_reader :app, :repository
65
+
66
+ def initialize(app, repository = [])
67
+ @app, @repository = app, repository
68
+ end
69
+
70
+ def index
71
+ repository
72
+ end
73
+
74
+ def show(user_id)
75
+ repository[user_id.to_i - 1]
76
+ end
77
+
78
+ def create
79
+ id = repository.length.next
80
+
81
+ if (name = app.request.params['name'].to_s).length > 0
82
+ repository << { name: name }
83
+ puts repository.inspect
84
+ app.response.redirect "/users/#{id}"
85
+ end
86
+ end
87
+ end
88
+
89
+ MyApplication.register(:users_repository, [
90
+ { name: 'Jack' },
91
+ { name: 'Gill' }
92
+ ])
93
+
94
+ MyApplication.register(:users_controller) do
95
+ UsersController.new(MyApplication.resolve(:app), MyApplication.resolve(:users_repository))
96
+ end
97
+
98
+ MyApplication.route do |r|
99
+ MyApplication.register(:app, self, call: false)
100
+
101
+ r.on 'users' do
102
+ r.is do
103
+ r.get(&MyApplication.action(:users_controller, :index))
104
+ r.post(&MyApplication.action(:users_controller, :create))
105
+ end
106
+
107
+ r.is :id do |id|
108
+ r.get(&MyApplication.action(:users_controller, :show).bind_arguments(id))
109
+ end
110
+ end
111
+ end
112
+ ```
113
+
54
114
  ## Contributing
55
115
 
56
116
  1. Fork it ( https://github.com/AMHOL/roda-action )
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda-action
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Holland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-30 00:00:00.000000000 Z
11
+ date: 2015-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: roda-container
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.1
19
+ version: 0.0.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.1
26
+ version: 0.0.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement