resourcelogic 0.12.2 → 0.12.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/Rakefile +3 -10
- data/VERSION.yml +1 -1
- data/lib/resourcelogic/actions.rb +1 -2
- data/lib/resourcelogic/aliases.rb +2 -0
- data/lib/resourcelogic/base.rb +7 -8
- data/lib/resourcelogic/child.rb +0 -5
- data/lib/resourcelogic/parent.rb +46 -32
- data/lib/resourcelogic/scope.rb +1 -1
- data/lib/resourcelogic/self.rb +1 -1
- data/lib/resourcelogic/singleton.rb +3 -3
- data/lib/resourcelogic/urligence.rb +35 -29
- data/resourcelogic.gemspec +6 -5
- metadata +3 -5
- data/CHANGELOG.rdoc +0 -3
- data/lib/resourcelogic/context_options.rb +0 -5
data/README.rdoc
CHANGED
@@ -7,7 +7,7 @@ The purpose of Resourcelogic is to support a development style I created called
|
|
7
7
|
== Helpful links
|
8
8
|
|
9
9
|
* <b>Documentation:</b> http://rdoc.info/projects/binarylogic/resourcelogic
|
10
|
-
* <b>
|
10
|
+
* <b>Issues:</b> http://github.com/binarylogic/resourcelogic/issues
|
11
11
|
|
12
12
|
== Contextual Development
|
13
13
|
|
data/Rakefile
CHANGED
@@ -12,6 +12,7 @@ begin
|
|
12
12
|
gem.rubyforge_project = "resourcelogic"
|
13
13
|
gem.add_dependency "activesupport"
|
14
14
|
end
|
15
|
+
Jeweler::RubyforgeTasks.new
|
15
16
|
rescue LoadError
|
16
17
|
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
18
|
end
|
@@ -36,14 +37,6 @@ rescue LoadError
|
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
39
|
-
task :
|
40
|
+
task :test => :check_dependencies
|
40
41
|
|
41
|
-
|
42
|
-
require 'rake/contrib/sshpublisher'
|
43
|
-
namespace :rubyforge do
|
44
|
-
desc "Release gem to RubyForge"
|
45
|
-
task :release => ["rubyforge:release:gem"]
|
46
|
-
end
|
47
|
-
rescue LoadError
|
48
|
-
puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
|
49
|
-
end
|
42
|
+
task :default => :test
|
data/VERSION.yml
CHANGED
@@ -8,7 +8,6 @@ module Resourcelogic
|
|
8
8
|
ACTIONS.each do |action|
|
9
9
|
class_scoping_reader action, FAILABLE_ACTIONS.include?(action) ? FailableActionOptions.new : ActionOptions.new
|
10
10
|
end
|
11
|
-
class_scoping_reader :context, ContextOptions.new
|
12
11
|
add_acts_as_resource_module(Methods)
|
13
12
|
end
|
14
13
|
end
|
@@ -153,7 +152,7 @@ module Resourcelogic
|
|
153
152
|
end
|
154
153
|
|
155
154
|
def load_parent
|
156
|
-
instance_variable_set "@#{parent_model_name}",
|
155
|
+
instance_variable_set "@#{parent_model_name}", parent if parent?
|
157
156
|
end
|
158
157
|
|
159
158
|
# Used internally to load the member object in to an instance variable @#{model_name} (i.e. @post)
|
@@ -51,6 +51,8 @@ module Resourcelogic
|
|
51
51
|
end
|
52
52
|
|
53
53
|
module Config
|
54
|
+
# This really isn't needed thanks to the new parent_from_params? method.
|
55
|
+
# TODO: review this and remove it if neccessary.
|
54
56
|
def path_alias(alias_name, model_name)
|
55
57
|
current_aliases = path_aliases
|
56
58
|
model_name = model_name.to_sym
|
data/lib/resourcelogic/base.rb
CHANGED
@@ -8,9 +8,8 @@ module Resourcelogic # :nodoc:
|
|
8
8
|
end
|
9
9
|
|
10
10
|
module ClassMethods
|
11
|
-
def acts_as_resource
|
11
|
+
def acts_as_resource
|
12
12
|
resourceful(true)
|
13
|
-
yield self if block_given?
|
14
13
|
acts_as_resource_modules.each { |mod| include mod }
|
15
14
|
init_default_actions
|
16
15
|
end
|
@@ -43,12 +42,12 @@ module Resourcelogic # :nodoc:
|
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
46
|
-
# Since this part of
|
47
|
-
# in
|
48
|
-
# call. For example, you don't want to start adding in email validations and what not into a
|
49
|
-
# nothing to do with
|
45
|
+
# Since this part of Resourcelogic deals with another class, ActionController, we can't just start including things
|
46
|
+
# in ActionController itself. A lot of these module includes need to be triggered by the acts_as_resource method
|
47
|
+
# call. For example, you don't want to start adding in email validations and what not into a controller that has
|
48
|
+
# nothing to do with Resourcelogic.
|
50
49
|
#
|
51
|
-
# That being said, this is your tool for extending
|
50
|
+
# That being said, this is your tool for extending Resourcelogic and "hooking" into the acts_as_resource call.
|
52
51
|
def add_acts_as_resource_module(mod, action = :append)
|
53
52
|
modules = acts_as_resource_modules
|
54
53
|
case action
|
@@ -61,7 +60,7 @@ module Resourcelogic # :nodoc:
|
|
61
60
|
write_inheritable_attribute(:acts_as_resource_modules, modules)
|
62
61
|
end
|
63
62
|
|
64
|
-
# This is the same as
|
63
|
+
# This is the same as add_acts_as_resource_module, except that it removes the module from the list.
|
65
64
|
def remove_acts_as_resource_module(mod)
|
66
65
|
write_inheritable_attribute(:acts_as_resource_modules, acts_as_resource_modules - [mod])
|
67
66
|
acts_as_resource_modules
|
data/lib/resourcelogic/child.rb
CHANGED
@@ -46,11 +46,6 @@ module Resourcelogic
|
|
46
46
|
base_parts.pop if base_parts.last.is_a?(Hash)
|
47
47
|
base_parts
|
48
48
|
end
|
49
|
-
|
50
|
-
#def current_object_to_use(url_params)
|
51
|
-
# result = (url_params.key?("#{model_name}_id".to_sym) && url_params["#{model_name}_id".to_sym]) || (id? && object)
|
52
|
-
# result ? result : nil
|
53
|
-
#end
|
54
49
|
end
|
55
50
|
end
|
56
51
|
end
|
data/lib/resourcelogic/parent.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Resourcelogic
|
2
2
|
module Parent
|
3
|
+
class RequiredParentError < StandardError; end
|
4
|
+
|
3
5
|
def self.included(klass)
|
4
6
|
klass.class_eval do
|
5
7
|
extend Config
|
@@ -7,46 +9,44 @@ module Resourcelogic
|
|
7
9
|
add_acts_as_resource_module(Reflection)
|
8
10
|
end
|
9
11
|
end
|
10
|
-
|
12
|
+
|
11
13
|
module Config
|
12
|
-
def belongs_to(
|
14
|
+
def belongs_to(*args)
|
15
|
+
options = args.extract_options!
|
13
16
|
@belongs_to ||= {}
|
14
|
-
|
15
|
-
|
16
|
-
else
|
17
|
-
@belongs_to[name.to_sym] = options
|
18
|
-
end
|
17
|
+
args.each { |name| @belongs_to[name.to_sym] = options }
|
18
|
+
@belongs_to
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def require_parent(value = nil)
|
22
22
|
rw_config(:require_parent, value, false)
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
module Urls
|
27
27
|
private
|
28
28
|
def parent_url_parts(action = nil, url_params = {})
|
29
29
|
[action] + contexts_url_parts + [url_params]
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def parent_collection_url_parts(*args)
|
33
33
|
parent_url_parts(*args)
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
module Reflection
|
38
38
|
def self.included(klass)
|
39
39
|
klass.class_eval do
|
40
|
-
helper_method :parent?, :parent_model_name, :
|
40
|
+
helper_method :parent?, :parent_model_name, :parent
|
41
41
|
before_filter :require_parent
|
42
42
|
end
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
private
|
46
46
|
def belongs_to
|
47
47
|
self.class.belongs_to
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def parent_path_name
|
51
51
|
return @parent_path_name if defined?(@parent_path_name)
|
52
52
|
path_parts = request.path.split("/")
|
@@ -58,7 +58,7 @@ module Resourcelogic
|
|
58
58
|
end
|
59
59
|
@parent_path_name = nil
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
def parent_route_name
|
63
63
|
return @parent_route_name if defined?(@parent_route_name)
|
64
64
|
path_parts = request.path.split("/")
|
@@ -70,19 +70,19 @@ module Resourcelogic
|
|
70
70
|
end
|
71
71
|
@parent_route_name = parent_model_name
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
# Returns the type of the current parent
|
75
75
|
#
|
76
76
|
def parent_model_name
|
77
77
|
return @parent_model_name if defined?(@parent_model_name)
|
78
|
-
parent_from_path?
|
78
|
+
parent_from_path? || parent_from_params?
|
79
79
|
@parent_model_name
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
def parent_model
|
83
83
|
@parent_model ||= parent_model_name.to_s.camelize.constantize
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
# Returns the type of the current parent extracted form a request path
|
87
87
|
#
|
88
88
|
def parent_from_path?
|
@@ -99,44 +99,58 @@ module Resourcelogic
|
|
99
99
|
end
|
100
100
|
@parent_from_path = false
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
|
+
# Returns the type of the current parent extracted form the request parameters
|
104
|
+
#
|
105
|
+
def parent_from_params?
|
106
|
+
return @parent_from_params if defined?(@parent_from_params)
|
107
|
+
belongs_to.each do |model_name, options|
|
108
|
+
if params["#{model_name}_id".to_sym]
|
109
|
+
@parent_model_name = model_name
|
110
|
+
return @parent_from_params = true
|
111
|
+
end
|
112
|
+
end
|
113
|
+
@parent_from_params = false
|
114
|
+
end
|
115
|
+
|
103
116
|
# Returns true/false based on whether or not a parent is present.
|
104
117
|
#
|
105
118
|
def parent?
|
106
119
|
!parent_model_name.nil?
|
107
120
|
end
|
108
|
-
|
121
|
+
|
109
122
|
# Returns true/false based on whether or not a parent is a singleton.
|
110
123
|
#
|
111
124
|
def parent_singleton?
|
112
125
|
parent? && parent_id.nil?
|
113
126
|
end
|
114
|
-
|
127
|
+
|
115
128
|
# Returns the current parent param, if there is a parent. (i.e. params[:post_id])
|
116
129
|
def parent_id
|
117
130
|
params["#{parent_route_name}_id".to_sym]
|
118
131
|
end
|
119
|
-
|
132
|
+
|
120
133
|
# Returns the current parent object if a parent object is present.
|
121
134
|
#
|
122
|
-
def
|
123
|
-
return @
|
135
|
+
def parent(reload = false)
|
136
|
+
return @parent if !reload && defined?(@parent)
|
124
137
|
if parent?
|
125
138
|
if parent_singleton? && respond_to?("current_#{parent_model_name}", true)
|
126
|
-
@
|
139
|
+
@parent = send("current_#{parent_model_name}")
|
127
140
|
elsif parent_singleton? && parent_scope.respond_to?(parent_model_name)
|
128
|
-
@
|
141
|
+
@parent = parent_scope.send(parent_model_name, reload)
|
129
142
|
else
|
130
|
-
@
|
143
|
+
@parent = parent_scope.find(parent_id)
|
131
144
|
end
|
132
145
|
else
|
133
|
-
@
|
146
|
+
@parent = nil
|
134
147
|
end
|
135
148
|
end
|
136
|
-
|
149
|
+
|
137
150
|
def require_parent
|
138
|
-
raise
|
151
|
+
raise RequiredParentError.new("A parent is required to access this resource and no parent was found") if !parent? && self.class.require_parent == true
|
139
152
|
end
|
140
153
|
end
|
141
154
|
end
|
142
|
-
end
|
155
|
+
end
|
156
|
+
|
data/lib/resourcelogic/scope.rb
CHANGED
data/lib/resourcelogic/self.rb
CHANGED
@@ -15,8 +15,8 @@ module Resourcelogic
|
|
15
15
|
if singleton?
|
16
16
|
if !parent? && respond_to?("current_#{model_name}", true)
|
17
17
|
@object = send("current_#{model_name}")
|
18
|
-
elsif parent? &&
|
19
|
-
@object =
|
18
|
+
elsif parent? && parent.send(model_name)
|
19
|
+
@object = parent.send(model_name)
|
20
20
|
else
|
21
21
|
super
|
22
22
|
end
|
@@ -35,7 +35,7 @@ module Resourcelogic
|
|
35
35
|
|
36
36
|
def scope
|
37
37
|
if singleton? && parent?
|
38
|
-
|
38
|
+
parent
|
39
39
|
else
|
40
40
|
super
|
41
41
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Resourcelogic
|
2
2
|
module Urligence
|
3
3
|
def self.included(klass)
|
4
|
-
klass.helper_method :smart_url, :smart_path, :
|
4
|
+
klass.helper_method :smart_url, :smart_path, :method_missing
|
5
5
|
end
|
6
6
|
|
7
7
|
def smart_url(*url_parts)
|
@@ -18,35 +18,12 @@ module Resourcelogic
|
|
18
18
|
urligence(*url_parts)
|
19
19
|
end
|
20
20
|
|
21
|
-
def hash_for_smart_url(*url_parts)
|
22
|
-
urligence(*url_parts.unshift(:hash_for).push(:url).push({:type => :hash}))
|
23
|
-
end
|
24
|
-
|
25
|
-
def hash_for_smart_path(*url_parts)
|
26
|
-
urligence(*url_parts.unshift(:hash_for).push(:path).push({:type => :hash}))
|
27
|
-
end
|
28
|
-
|
29
21
|
private
|
30
22
|
def urligence(*url_parts)
|
31
23
|
url_parts = cleanup_url_parts(url_parts)
|
32
24
|
method_name_fragments = extract_method_name_fragments(url_parts)
|
33
25
|
method_arguments = extract_method_arguments(url_parts)
|
34
|
-
|
35
|
-
if url_parts.first != :hash_for
|
36
|
-
send method_name_fragments.join("_"), *method_arguments
|
37
|
-
else
|
38
|
-
url_params = method_arguments.extract_options!
|
39
|
-
params = {}
|
40
|
-
method_arguments.each_with_index do |obj, i|
|
41
|
-
key = i == (method_arguments.size - 1) ?
|
42
|
-
:id :
|
43
|
-
(obj.is_a?(Array) ? "#{obj.first}_id".to_sym : "#{obj.class.name.underscore}_id".to_sym)
|
44
|
-
params.merge!((obj.is_a?(Array)) ? {key => obj[1].to_param} : {key => obj.to_param})
|
45
|
-
end
|
46
|
-
|
47
|
-
params.merge!(url_params)
|
48
|
-
send method_name_fragments.join("_"), params
|
49
|
-
end
|
26
|
+
send method_name_fragments.join("_"), *method_arguments
|
50
27
|
end
|
51
28
|
|
52
29
|
# The point of this method is to replace any object if a url param is passed. For example:
|
@@ -81,22 +58,32 @@ module Resourcelogic
|
|
81
58
|
# It's not an array, just copy it over
|
82
59
|
new_url_parts << object
|
83
60
|
else
|
84
|
-
# Let's try to
|
85
61
|
klass = object.first.to_s.camelize.constantize rescue nil
|
86
|
-
#klass_name = klass ? klass.name.underscore : nil
|
87
62
|
params_key = "#{object.first}_id".to_sym
|
63
|
+
|
88
64
|
obj = if url_params.key?(params_key)
|
89
|
-
|
65
|
+
if !klass
|
66
|
+
url_params[params_key]
|
67
|
+
elsif url_params[params_key]
|
68
|
+
klass.find(url_params.delete(params_key)
|
69
|
+
end
|
90
70
|
else
|
91
71
|
object[1]
|
92
72
|
end
|
73
|
+
|
93
74
|
new_url_parts << [object.first, obj]
|
94
|
-
#new_url_parts << (obj.nil? ? object.first.to_s.pluralize.to_sym : [object.first, obj])
|
95
75
|
end
|
96
76
|
end
|
97
77
|
new_url_parts
|
98
78
|
end
|
99
79
|
|
80
|
+
# Extracts the parts from the url_parts that make up the method name
|
81
|
+
#
|
82
|
+
# [:admin, [:user, user_object], :path]
|
83
|
+
#
|
84
|
+
# to:
|
85
|
+
#
|
86
|
+
# [:admin, :user, :path]
|
100
87
|
def extract_method_name_fragments(url_parts)
|
101
88
|
fragments = url_parts.collect do |obj|
|
102
89
|
if obj.is_a?(Symbol)
|
@@ -110,10 +97,29 @@ module Resourcelogic
|
|
110
97
|
fragments.compact
|
111
98
|
end
|
112
99
|
|
100
|
+
# Extracts the parts from url_parts that make up the method arguments
|
101
|
+
#
|
102
|
+
# [:admin, [:user, user_object], :path]
|
103
|
+
#
|
104
|
+
# to:
|
105
|
+
#
|
106
|
+
# [user_object]
|
113
107
|
def extract_method_arguments(url_parts)
|
114
108
|
url_parts.flatten.select { |obj| !obj.is_a?(Symbol) }
|
115
109
|
end
|
116
110
|
|
111
|
+
# Dynamically generate url methods for better flexibility. This allows us to not only call the standard urls:
|
112
|
+
#
|
113
|
+
# edit_object_path
|
114
|
+
# object_path
|
115
|
+
#
|
116
|
+
# but also be able to call custom method paths:
|
117
|
+
#
|
118
|
+
# select_object_path
|
119
|
+
#
|
120
|
+
# Where select is a method added yourself:
|
121
|
+
#
|
122
|
+
# map.resources :users, :member => {:select => :any}
|
117
123
|
def method_missing(method, *args, &block)
|
118
124
|
if method.to_s =~ /^((.*)_)?(child_collection|parent_collection|sibling|sibling_collection)_(path|url)$/ || method.to_s =~ /^((.*)_)?(child|collection|object|parent)_(path|url)$/
|
119
125
|
action = $2.blank? ? nil : $2.to_sym
|
data/resourcelogic.gemspec
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
1
4
|
# -*- encoding: utf-8 -*-
|
2
5
|
|
3
6
|
Gem::Specification.new do |s|
|
4
7
|
s.name = %q{resourcelogic}
|
5
|
-
s.version = "0.12.
|
8
|
+
s.version = "0.12.3"
|
6
9
|
|
7
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
11
|
s.authors = ["Ben Johnson of Binary Logic"]
|
9
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-08-12}
|
10
13
|
s.email = %q{bjohnson@binarylogic.com}
|
11
14
|
s.extra_rdoc_files = [
|
12
15
|
"LICENSE",
|
@@ -14,7 +17,6 @@ Gem::Specification.new do |s|
|
|
14
17
|
]
|
15
18
|
s.files = [
|
16
19
|
".gitignore",
|
17
|
-
"CHANGELOG.rdoc",
|
18
20
|
"LICENSE",
|
19
21
|
"README.rdoc",
|
20
22
|
"Rakefile",
|
@@ -28,7 +30,6 @@ Gem::Specification.new do |s|
|
|
28
30
|
"lib/resourcelogic/base.rb",
|
29
31
|
"lib/resourcelogic/child.rb",
|
30
32
|
"lib/resourcelogic/context.rb",
|
31
|
-
"lib/resourcelogic/context_options.rb",
|
32
33
|
"lib/resourcelogic/failable_action_options.rb",
|
33
34
|
"lib/resourcelogic/parent.rb",
|
34
35
|
"lib/resourcelogic/response_collector.rb",
|
@@ -44,7 +45,7 @@ Gem::Specification.new do |s|
|
|
44
45
|
s.rdoc_options = ["--charset=UTF-8"]
|
45
46
|
s.require_paths = ["lib"]
|
46
47
|
s.rubyforge_project = %q{resourcelogic}
|
47
|
-
s.rubygems_version = %q{1.3.
|
48
|
+
s.rubygems_version = %q{1.3.5}
|
48
49
|
s.summary = %q{Removes the need to namespace controllers by adding context and relative url functions among other things.}
|
49
50
|
|
50
51
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resourcelogic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Johnson of Binary Logic
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-12 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -33,7 +33,6 @@ extra_rdoc_files:
|
|
33
33
|
- README.rdoc
|
34
34
|
files:
|
35
35
|
- .gitignore
|
36
|
-
- CHANGELOG.rdoc
|
37
36
|
- LICENSE
|
38
37
|
- README.rdoc
|
39
38
|
- Rakefile
|
@@ -47,7 +46,6 @@ files:
|
|
47
46
|
- lib/resourcelogic/base.rb
|
48
47
|
- lib/resourcelogic/child.rb
|
49
48
|
- lib/resourcelogic/context.rb
|
50
|
-
- lib/resourcelogic/context_options.rb
|
51
49
|
- lib/resourcelogic/failable_action_options.rb
|
52
50
|
- lib/resourcelogic/parent.rb
|
53
51
|
- lib/resourcelogic/response_collector.rb
|
@@ -82,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
80
|
requirements: []
|
83
81
|
|
84
82
|
rubyforge_project: resourcelogic
|
85
|
-
rubygems_version: 1.3.
|
83
|
+
rubygems_version: 1.3.5
|
86
84
|
signing_key:
|
87
85
|
specification_version: 3
|
88
86
|
summary: Removes the need to namespace controllers by adding context and relative url functions among other things.
|
data/CHANGELOG.rdoc
DELETED