objectify 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -2
- data/Gemfile.lock +40 -42
- data/README.md +9 -9
- data/lib/objectify.rb +5 -2
- data/lib/objectify/rails/railtie.rb +2 -2
- data/lib/objectify/rails/routing.rb +19 -20
- data/lib/objectify/version.rb +1 -1
- data/objectify.gemspec +1 -1
- metadata +17 -17
data/.gitignore
CHANGED
@@ -14,6 +14,12 @@ doc
|
|
14
14
|
# built gems
|
15
15
|
*.gem
|
16
16
|
|
17
|
+
# rvm
|
18
|
+
.rvmrc
|
19
|
+
|
20
|
+
# http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/
|
21
|
+
Gemfile.lock
|
22
|
+
|
17
23
|
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
18
24
|
#
|
19
25
|
# * Create a file at ~/.gitignore
|
@@ -38,8 +44,8 @@ doc
|
|
38
44
|
#\#*
|
39
45
|
#.\#*
|
40
46
|
|
41
|
-
|
42
|
-
|
47
|
+
For vim:
|
48
|
+
*.swp
|
43
49
|
|
44
50
|
# For redcar:
|
45
51
|
#.redcar
|
data/Gemfile.lock
CHANGED
@@ -1,42 +1,41 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
|
4
|
+
objectify (0.0.6)
|
5
5
|
i18n
|
6
6
|
rails (>= 3.0.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actionmailer (3.
|
12
|
-
actionpack (= 3.
|
13
|
-
mail (~> 2.
|
14
|
-
actionpack (3.
|
15
|
-
activemodel (= 3.
|
16
|
-
activesupport (= 3.
|
11
|
+
actionmailer (3.2.3)
|
12
|
+
actionpack (= 3.2.3)
|
13
|
+
mail (~> 2.4.4)
|
14
|
+
actionpack (3.2.3)
|
15
|
+
activemodel (= 3.2.3)
|
16
|
+
activesupport (= 3.2.3)
|
17
17
|
builder (~> 3.0.0)
|
18
18
|
erubis (~> 2.7.0)
|
19
|
-
|
20
|
-
rack (~> 1.
|
21
|
-
rack-cache (~> 1.
|
22
|
-
rack-mount (~> 0.8.2)
|
19
|
+
journey (~> 1.0.1)
|
20
|
+
rack (~> 1.4.0)
|
21
|
+
rack-cache (~> 1.2)
|
23
22
|
rack-test (~> 0.6.1)
|
24
|
-
sprockets (~> 2.
|
25
|
-
activemodel (3.
|
26
|
-
activesupport (= 3.
|
23
|
+
sprockets (~> 2.1.2)
|
24
|
+
activemodel (3.2.3)
|
25
|
+
activesupport (= 3.2.3)
|
27
26
|
builder (~> 3.0.0)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
arel (~> 2.2.1)
|
27
|
+
activerecord (3.2.3)
|
28
|
+
activemodel (= 3.2.3)
|
29
|
+
activesupport (= 3.2.3)
|
30
|
+
arel (~> 3.0.2)
|
33
31
|
tzinfo (~> 0.3.29)
|
34
|
-
activeresource (3.
|
35
|
-
activemodel (= 3.
|
36
|
-
activesupport (= 3.
|
37
|
-
activesupport (3.
|
32
|
+
activeresource (3.2.3)
|
33
|
+
activemodel (= 3.2.3)
|
34
|
+
activesupport (= 3.2.3)
|
35
|
+
activesupport (3.2.3)
|
36
|
+
i18n (~> 0.6)
|
38
37
|
multi_json (~> 1.0)
|
39
|
-
arel (
|
38
|
+
arel (3.0.2)
|
40
39
|
bourne (1.0)
|
41
40
|
mocha (= 0.9.8)
|
42
41
|
builder (3.0.0)
|
@@ -49,8 +48,9 @@ GEM
|
|
49
48
|
bundler (~> 1.0)
|
50
49
|
git (>= 1.2.5)
|
51
50
|
rake
|
51
|
+
journey (1.0.3)
|
52
52
|
json (1.7.3)
|
53
|
-
mail (2.
|
53
|
+
mail (2.4.4)
|
54
54
|
i18n (>= 0.4.0)
|
55
55
|
mime-types (~> 1.16)
|
56
56
|
treetop (~> 1.4.8)
|
@@ -59,26 +59,24 @@ GEM
|
|
59
59
|
rake
|
60
60
|
multi_json (1.3.5)
|
61
61
|
polyglot (0.3.3)
|
62
|
-
rack (1.
|
62
|
+
rack (1.4.1)
|
63
63
|
rack-cache (1.2)
|
64
64
|
rack (>= 0.4)
|
65
|
-
rack-mount (0.8.3)
|
66
|
-
rack (>= 1.0.0)
|
67
65
|
rack-ssl (1.3.2)
|
68
66
|
rack
|
69
67
|
rack-test (0.6.1)
|
70
68
|
rack (>= 1.0)
|
71
|
-
rails (3.
|
72
|
-
actionmailer (= 3.
|
73
|
-
actionpack (= 3.
|
74
|
-
activerecord (= 3.
|
75
|
-
activeresource (= 3.
|
76
|
-
activesupport (= 3.
|
69
|
+
rails (3.2.3)
|
70
|
+
actionmailer (= 3.2.3)
|
71
|
+
actionpack (= 3.2.3)
|
72
|
+
activerecord (= 3.2.3)
|
73
|
+
activeresource (= 3.2.3)
|
74
|
+
activesupport (= 3.2.3)
|
77
75
|
bundler (~> 1.0)
|
78
|
-
railties (= 3.
|
79
|
-
railties (3.
|
80
|
-
actionpack (= 3.
|
81
|
-
activesupport (= 3.
|
76
|
+
railties (= 3.2.3)
|
77
|
+
railties (3.2.3)
|
78
|
+
actionpack (= 3.2.3)
|
79
|
+
activesupport (= 3.2.3)
|
82
80
|
rack-ssl (~> 1.3.2)
|
83
81
|
rake (>= 0.8.7)
|
84
82
|
rdoc (~> 3.4)
|
@@ -94,10 +92,10 @@ GEM
|
|
94
92
|
rspec-expectations (2.4.0)
|
95
93
|
diff-lcs (~> 1.1.2)
|
96
94
|
rspec-mocks (2.4.0)
|
97
|
-
sprockets (2.
|
95
|
+
sprockets (2.1.3)
|
98
96
|
hike (~> 1.2)
|
99
97
|
rack (~> 1.0)
|
100
|
-
tilt (
|
98
|
+
tilt (~> 1.1, != 1.3.0)
|
101
99
|
thor (0.14.6)
|
102
100
|
tilt (1.3.3)
|
103
101
|
treetop (1.4.10)
|
@@ -109,9 +107,9 @@ PLATFORMS
|
|
109
107
|
ruby
|
110
108
|
|
111
109
|
DEPENDENCIES
|
112
|
-
bitlove-objectify!
|
113
110
|
bourne (= 1.0)
|
114
|
-
bundler (
|
111
|
+
bundler (>= 1.0.0)
|
115
112
|
jeweler (~> 1.6.4)
|
116
113
|
mocha (= 0.9.8)
|
114
|
+
objectify!
|
117
115
|
rspec (~> 2.4.0)
|
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# objectify
|
2
2
|
|
3
|
-
Objectify is a framework that codifies good object oriented design practices for building maintainable rails applications.
|
3
|
+
Objectify is a framework that codifies good object oriented design practices for building maintainable rails applications. For more on the motivations that led to objectify, check out this blog post: http://jamesgolick.com/2012/5/22/objectify-a-better-way-to-build-rails-applications.html
|
4
4
|
|
5
5
|
## How it works
|
6
6
|
|
7
7
|
Objectify has two primary components:
|
8
8
|
|
9
|
-
1. A request execution framework that separates the responsibilities that are typically jammed together in rails controller actions in to 3 types of components: Policies, Services, and Responders. Properly separating and assigning these responsibilities makes
|
9
|
+
1. A request execution framework that separates the responsibilities that are typically jammed together in rails controller actions in to 3 types of components: Policies, Services, and Responders. Properly separating and assigning these responsibilities makes code far more testable, and facilitates better reuse of components.
|
10
10
|
|
11
11
|
The flow of an objectify request is as follows:
|
12
12
|
|
@@ -20,7 +20,7 @@ Objectify has two primary components:
|
|
20
20
|
|
21
21
|
Objectify currently only supports resourceful actions, but that's just a temporary thing.
|
22
22
|
|
23
|
-
1. The policy chain is resolved (based on the various levels of configuration) and executed. Objectify calls the
|
23
|
+
1. The policy chain is resolved (based on the various levels of configuration) and executed. Objectify calls the `#allowed?(...)` method on each policy in the chain. If one of the policies fails, the chain short-circuits at that point, and objectify executes the configured responder for that policy.
|
24
24
|
|
25
25
|
An example Policy:
|
26
26
|
|
@@ -68,7 +68,7 @@ Objectify has two primary components:
|
|
68
68
|
end
|
69
69
|
```
|
70
70
|
|
71
|
-
3. Finally, the responder is executed. Following with our Pictures#create example:
|
71
|
+
3. Finally, the responder is executed. Following with our `Pictures#create` example:
|
72
72
|
|
73
73
|
```ruby
|
74
74
|
class PicturesCreateResponder
|
@@ -86,12 +86,12 @@ Objectify has two primary components:
|
|
86
86
|
end
|
87
87
|
```
|
88
88
|
|
89
|
-
2. A dependency injection framework. Objectify automatically injects dependencies
|
89
|
+
2. A dependency injection framework. Objectify automatically injects dependencies into objects it manages based on parameter names. So, if you have a service method signature like `PictureCreationService#call(params)`, objectify will automatically inject the request's params when it calls that method. It's very simple to create custom injections by implementing Resolver classes. More on that below.
|
90
90
|
|
91
91
|
|
92
92
|
## What if I have a bunch of existing rails code?
|
93
93
|
|
94
|
-
Objectify has a legacy mode that allows you to execute the policy chain as a before_filter in your ApplicationController. You can also configure policies (and skip_policies) for your "legacy" actions. That way, access control code is shared between the legacy and objectified components of your application.
|
94
|
+
Objectify has a legacy mode that allows you to execute the policy chain as a `before_filter` in your ApplicationController. You can also configure policies (and `skip_policies`) for your "legacy" actions. That way, access control code is shared between the legacy and objectified components of your application.
|
95
95
|
|
96
96
|
I completely rewrote our legacy authentication system as a set of objectify policies, resolvers, and services - I'm gonna package that up and release it soon.
|
97
97
|
|
@@ -140,7 +140,7 @@ end
|
|
140
140
|
|
141
141
|
## Custom Injections
|
142
142
|
|
143
|
-
Several of the above methods have parameters named
|
143
|
+
Several of the above methods have parameters named `current_user`. By default, objectify won't know how to inject a parameter by that name, so it'll raise an error when it encounters one. Here's how to create a custom resolver for it that'll automatically get found by name.
|
144
144
|
|
145
145
|
```ruby
|
146
146
|
# app/resolvers/current_user_resolver.rb
|
@@ -181,9 +181,9 @@ end
|
|
181
181
|
|
182
182
|
Objectify has two major impacts on your views.
|
183
183
|
|
184
|
-
1. You can only pass one variable from an objectified action to the controller. You do that by calling renderer.data(the_object_you_want_to_pass)
|
184
|
+
1. You can only pass one variable from an objectified action to the controller. You do that by calling `renderer.data(the_object_you_want_to_pass)`. Then, you call `objectify_data` in the view to fetch the data. If it's not there, it'll raise an error. Use a presenter or some kind of other struct object to pass multiple objects to your views.
|
185
185
|
|
186
|
-
2. You can reuse your policies in your views. require "objectify/rails/helpers" and add Objectify::Rails::Helpers to your helpers list, and you'll get a helper called
|
186
|
+
2. You can reuse your policies in your views. `require "objectify/rails/helpers"` and add `Objectify::Rails::Helpers` to your helpers list, and you'll get a helper called `#policy_allowed?(policy_name)`. Yay code reuse.
|
187
187
|
|
188
188
|
## Installation
|
189
189
|
|
data/lib/objectify.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Objectify
|
2
2
|
module Rails
|
3
|
-
class Railtie < Rails::Railtie
|
3
|
+
class Railtie < ::Rails::Railtie
|
4
4
|
initializer "objectify.reloader" do
|
5
5
|
ActionDispatch::Callbacks.to_prepare do
|
6
|
-
Rails.application.objectify.reload
|
6
|
+
::Rails.application.objectify.reload
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -24,19 +24,9 @@ module Objectify
|
|
24
24
|
rails_options = options.merge(:controller => controller)
|
25
25
|
|
26
26
|
args.each do |resource_name|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
@rails_mapper.resources(resource_name, with_defaults)
|
31
|
-
|
32
|
-
RESOURCE_ACTIONS.each do |action_name|
|
33
|
-
action = @action_factory.new(resource_name,
|
34
|
-
action_name,
|
35
|
-
objectify_options,
|
36
|
-
@application.objectify.policies)
|
37
|
-
|
38
|
-
@application.objectify.append_action(action)
|
39
|
-
end
|
27
|
+
merged_defaults = objectify_defaults(resource_name, rails_options)
|
28
|
+
@rails_mapper.resources(resource_name, merged_defaults)
|
29
|
+
RESOURCE_ACTIONS.each { |action_name| append_action(resource_name, action_name, objectify_options) }
|
40
30
|
end
|
41
31
|
end
|
42
32
|
|
@@ -53,13 +43,7 @@ module Objectify
|
|
53
43
|
end
|
54
44
|
|
55
45
|
def legacy_action(controller, actions, options)
|
56
|
-
[*actions].each
|
57
|
-
action = @action_factory.new(controller,
|
58
|
-
action_name,
|
59
|
-
options,
|
60
|
-
@application.objectify.policies)
|
61
|
-
@application.objectify.append_action(action)
|
62
|
-
end
|
46
|
+
[*actions].each { |action_name| append_action(controller, action_name, options) }
|
63
47
|
end
|
64
48
|
|
65
49
|
private
|
@@ -68,6 +52,21 @@ module Objectify
|
|
68
52
|
[key, options.delete(key)] if options.include?(key)
|
69
53
|
end.compact.flatten]
|
70
54
|
end
|
55
|
+
|
56
|
+
def objectify_defaults(resource_name, rails_options)
|
57
|
+
defaults = {:objectify => {:resource => resource_name}}
|
58
|
+
defaults = (rails_options[:defaults] || {}).merge(defaults)
|
59
|
+
defaults = rails_options.merge(:defaults => defaults)
|
60
|
+
end
|
61
|
+
|
62
|
+
def append_action(resource_name, action_name, options)
|
63
|
+
action = @action_factory.new(resource_name,
|
64
|
+
action_name,
|
65
|
+
options,
|
66
|
+
@application.objectify.policies)
|
67
|
+
|
68
|
+
@application.objectify.append_action(action)
|
69
|
+
end
|
71
70
|
end
|
72
71
|
|
73
72
|
class Mapper < ActionDispatch::Routing::Mapper
|
data/lib/objectify/version.rb
CHANGED
data/objectify.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
# specify any dependencies here; for example:
|
22
22
|
s.add_development_dependency "rspec", "~> 2.4.0"
|
23
|
-
s.add_development_dependency "bundler", "
|
23
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
24
24
|
s.add_development_dependency "jeweler", "~> 1.6.4"
|
25
25
|
s.add_development_dependency "bourne", "1.0"
|
26
26
|
s.add_development_dependency "mocha", "0.9.8"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: objectify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70332392343920 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,21 +21,21 @@ dependencies:
|
|
21
21
|
version: 2.4.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70332392343920
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70332392343200 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
|
-
- -
|
30
|
+
- - ! '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 1.0.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70332392343200
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: jeweler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70332400562900 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.6.4
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70332400562900
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bourne
|
49
|
-
requirement: &
|
49
|
+
requirement: &70332400562340 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - =
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '1.0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70332400562340
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: mocha
|
60
|
-
requirement: &
|
60
|
+
requirement: &70332400561620 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - =
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 0.9.8
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70332400561620
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rails
|
71
|
-
requirement: &
|
71
|
+
requirement: &70332400560740 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 3.0.0
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70332400560740
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: i18n
|
82
|
-
requirement: &
|
82
|
+
requirement: &70332400559120 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70332400559120
|
91
91
|
description: Objects on rails.
|
92
92
|
email:
|
93
93
|
- jamesgolick@gmail.com
|