resource_awareness 0.0.5 → 0.0.6
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.
data/lib/rails/resource.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
require 'builder'
|
2
|
+
|
1
3
|
module Rails
|
2
4
|
class Resource
|
3
|
-
attr_accessor :id, :name, :singular_name, :
|
5
|
+
attr_accessor :id, :name, :singular_name, :controller_path, :name_prefix, :path_prefix, :home_route
|
4
6
|
|
5
7
|
def initialize(entity, scope, options)
|
6
8
|
self.name_prefix = scope[:name_prefix]
|
@@ -10,26 +12,26 @@ module Rails
|
|
10
12
|
self.home_route = Rails.application.routes.named_routes[id]
|
11
13
|
self.path_prefix = home_route.path.sub("/#{name}(.:format)", '')
|
12
14
|
self.path_prefix = nil if path_prefix.blank?
|
13
|
-
self.
|
15
|
+
self.controller_path = home_route.requirements[:controller]
|
14
16
|
end
|
15
17
|
|
16
18
|
def path
|
17
19
|
path_prefix ? "#{path_prefix}/#{name}" : "/#{name}"
|
18
20
|
end
|
19
21
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
22
|
+
def to_xml(options = {})
|
23
|
+
options[:indent] ||= 2
|
24
|
+
xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
|
25
|
+
xml.instruct! unless options[:skip_instruct]
|
26
|
+
xml.resource do
|
27
|
+
xml.id id
|
28
|
+
xml.type self.class
|
29
|
+
xml.name name
|
30
|
+
xml.singular_name singular_name
|
31
|
+
xml.path_prefix path_prefix
|
32
|
+
xml.path path
|
33
|
+
xml.controller_name controller_name
|
34
|
+
end
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -2,6 +2,6 @@ require 'action_controller/base'
|
|
2
2
|
|
3
3
|
class ActionController::Base
|
4
4
|
def resource
|
5
|
-
@resource ||= Rails.application.resources.find { |r| r.
|
5
|
+
@resource ||= Rails.application.resources.find { |r| r.controller_path == self.controller_path }
|
6
6
|
end
|
7
7
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 6
|
9
|
+
version: 0.0.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ingo Weiss
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-26 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -30,6 +30,19 @@ dependencies:
|
|
30
30
|
version: "3.0"
|
31
31
|
type: :runtime
|
32
32
|
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: builder
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 2
|
42
|
+
- 1
|
43
|
+
version: "2.1"
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
33
46
|
description: |
|
34
47
|
Makes information about a Rails application's resources (as defined via the 'resource(s)' routing DSL methods) available via Rails.application.resources
|
35
48
|
|