resource_awareness 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,8 @@
1
+ require 'builder'
2
+
1
3
  module Rails
2
4
  class Resource
3
- attr_accessor :id, :name, :singular_name, :controller_name, :name_prefix, :path_prefix, :home_route
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.controller_name = home_route.requirements[:controller]
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 attributes
21
- {
22
- :id => id,
23
- :name => name,
24
- :singular_name => singular_name,
25
- :path_prefix => path_prefix,
26
- :path => path,
27
- :controller_name => controller_name
28
- }
29
- end
30
-
31
- def to_xml
32
- attributes.to_xml
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
@@ -1,3 +1,4 @@
1
+ require 'rails/resource'
1
2
  module Rails
2
3
  class SingletonResource < Resource
3
4
  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.controller_name == self.controller_name }
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
- - 5
9
- version: 0.0.5
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-25 00:00:00 +02:00
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