roda-action 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +64 -0
  4. data/lib/roda/plugins/action.rb +82 -0
  5. metadata +131 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 32f09854e0f79ab4da1c0fa5b20686b2894abb11
4
+ data.tar.gz: 1e1ec879bb44e6fa005247c6859cbc43ddf0c918
5
+ SHA512:
6
+ metadata.gz: 636022647521cc888bc4ae8e64ba0d0cf4bfe4990ba16e5f1e58268d066cfd6db6a6e67d5163ea81534830cb4d88dc6befc9e106646e76d9581077b431d232aa
7
+ data.tar.gz: 69a8a7e3700aa77c982c4b99180a6c05249cf182fc8ce5bc11bb17d01c38813331396a542001339b8c68e5d75ff92c416f779ce80df99612623104f6012e83cd
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Janko Marohnić
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # roda-action
2
+
3
+ A plugin for Roda to resolve actions from roda-container
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem 'roda-action', '0.0.1'
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ruby
14
+ class MyApplication < Roda
15
+ plugin :action
16
+ end
17
+
18
+ class UsersController
19
+ attr_reader :repository
20
+
21
+ def initialize(repository = {})
22
+ @repository = repository
23
+ end
24
+
25
+ def index
26
+ repository.values
27
+ end
28
+
29
+ def show(user_id)
30
+ repository[user_id]
31
+ end
32
+ end
33
+
34
+ MyApplication.register(:users_controller) do
35
+ UsersController.new({
36
+ '1' => { name: 'Jack' },
37
+ '2' => { name: 'Gill' }
38
+ })
39
+ end
40
+
41
+ route do |r|
42
+ r.on 'users' do
43
+ r.is do
44
+ r.get(&MyApplication.action(:users_controller, :index))
45
+ end
46
+
47
+ r.is :id do |id|
48
+ r.get(&MyApplication.action(:users_controller, :show).bind_arguments(id))
49
+ end
50
+ end
51
+ end
52
+ ```
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it ( https://github.com/AMHOL/roda-action )
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create a new Pull Request
61
+
62
+ ## License
63
+
64
+ [MIT](LICENSE.txt)
@@ -0,0 +1,82 @@
1
+ class Roda
2
+ module RodaPlugins
3
+ # The action plugin loads the container plugin and adds
4
+ # the "action" class method to your Roda application.
5
+ #
6
+ # You can then register your controllers with the
7
+ # app container and resolve a method on your controller
8
+ # to pass as the matcher block.
9
+ #
10
+ # Example:
11
+ #
12
+ # plugin :action
13
+ #
14
+ # class UsersController
15
+ # attr_reader :repository
16
+ #
17
+ # def initialize(repository = {})
18
+ # @repository = repository
19
+ # end
20
+ #
21
+ # def index
22
+ # repository.values
23
+ # end
24
+ #
25
+ # def show(user_id)
26
+ # repository[user_id]
27
+ # end
28
+ # end
29
+ #
30
+ # MyApplication.register(:users_controller) do
31
+ # UsersController.new({
32
+ # '1' => { name: 'Jack' },
33
+ # '2' => { name: 'Gill' }
34
+ # })
35
+ # end
36
+ #
37
+ # route do |r|
38
+ # r.on 'users' do
39
+ # r.is do
40
+ # r.get(&MyApplication.action(:users_controller, :index))
41
+ # end
42
+ #
43
+ # r.is :id do |id|
44
+ # r.get(&MyApplication.action(:users_controller, :show).bind_arguments(id))
45
+ # end
46
+ # end
47
+ # end
48
+ module Action
49
+ # Action wrapper - allows binding of arguments that are already
50
+ # loaded in parent matchers.
51
+ class Action
52
+ def initialize(action)
53
+ @action = action.to_proc
54
+ end
55
+
56
+ def bind_arguments(*bindings)
57
+ method = @action
58
+ action = proc { |*args| method.call(*(bindings + args)) }
59
+ @action = action
60
+ end
61
+
62
+ def to_proc
63
+ @action
64
+ end
65
+ end
66
+
67
+ # Load the container plugin, since the action plugin
68
+ # depends on it.
69
+ def self.load_dependencies(app, _opts = nil)
70
+ app.plugin :container
71
+ end
72
+
73
+ module ClassMethods
74
+ def action(controller_key, action)
75
+ Action.new(resolve(controller_key).method(action))
76
+ end
77
+ end
78
+ end
79
+
80
+ register_plugin(:action, Action)
81
+ end
82
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roda-action
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andy Holland
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: roda-container
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: roda
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '10.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '10.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '3.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '3.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-test
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A plugin for Roda to resolve actions from roda-container
98
+ email:
99
+ - andyholland1991@aol.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - LICENSE.txt
105
+ - README.md
106
+ - lib/roda/plugins/action.rb
107
+ homepage: https://github.com/AMHOL/roda-action
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.6
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: A plugin for Roda to resolve actions from roda-container
131
+ test_files: []