Class: Rails::Resource
- Inherits:
-
Object
- Object
- Rails::Resource
- Defined in:
- lib/rails/resource.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#controller_path ⇒ Object
Returns the value of attribute controller_path.
-
#home_route ⇒ Object
Returns the value of attribute home_route.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#name_prefix ⇒ Object
Returns the value of attribute name_prefix.
-
#path_prefix ⇒ Object
Returns the value of attribute path_prefix.
-
#prefix_parameters ⇒ Object
Returns the value of attribute prefix_parameters.
-
#singular_name ⇒ Object
Returns the value of attribute singular_name.
Instance Method Summary collapse
- #controller ⇒ Object
-
#initialize(entity, scope, options) ⇒ Resource
constructor
A new instance of Resource.
- #path ⇒ Object
- #singleton? ⇒ Boolean
- #to_xml(options = {}) ⇒ Object
Constructor Details
#initialize(entity, scope, options) ⇒ Resource
Returns a new instance of Resource.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rails/resource.rb', line 7 def initialize(entity, scope, ) self.name_prefix = scope[:as] self.name = entity.to_s self.singular_name = name.singularize self.id = [name_prefix, name].compact.join('_') self.home_route = Rails.application.routes.named_routes[id] self.path_prefix = home_route.path.sub("/#{name}(.:format)", '') self.path_prefix = nil if path_prefix.blank? self.prefix_parameters = home_route.segment_keys.find_all{|sk| sk.to_s.match(/_id\Z/)}.to_set self.controller_path = home_route.requirements[:controller] end |
Instance Attribute Details
#controller_path ⇒ Object
Returns the value of attribute controller_path.
5 6 7 |
# File 'lib/rails/resource.rb', line 5 def controller_path @controller_path end |
#home_route ⇒ Object
Returns the value of attribute home_route.
5 6 7 |
# File 'lib/rails/resource.rb', line 5 def home_route @home_route end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/rails/resource.rb', line 5 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/rails/resource.rb', line 5 def name @name end |
#name_prefix ⇒ Object
Returns the value of attribute name_prefix.
5 6 7 |
# File 'lib/rails/resource.rb', line 5 def name_prefix @name_prefix end |
#path_prefix ⇒ Object
Returns the value of attribute path_prefix.
5 6 7 |
# File 'lib/rails/resource.rb', line 5 def path_prefix @path_prefix end |
#prefix_parameters ⇒ Object
Returns the value of attribute prefix_parameters.
5 6 7 |
# File 'lib/rails/resource.rb', line 5 def prefix_parameters @prefix_parameters end |
#singular_name ⇒ Object
Returns the value of attribute singular_name.
5 6 7 |
# File 'lib/rails/resource.rb', line 5 def singular_name @singular_name end |
Instance Method Details
#controller ⇒ Object
23 24 25 |
# File 'lib/rails/resource.rb', line 23 def controller @controller ||= (controller_path + '_controller').classify.constantize end |
#path ⇒ Object
19 20 21 |
# File 'lib/rails/resource.rb', line 19 def path path_prefix ? "#{path_prefix}/#{name}" : "/#{name}" end |
#singleton? ⇒ Boolean
27 28 29 |
# File 'lib/rails/resource.rb', line 27 def singleton? false end |
#to_xml(options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rails/resource.rb', line 31 def to_xml( = {}) [:indent] ||= 2 xml = [:builder] ||= Builder::XmlMarkup.new(:indent => [:indent]) xml.instruct! unless [:skip_instruct] xml.resource do xml.id id xml.type self.class xml.name name xml.singular_name singular_name xml.path_prefix path_prefix xml.path path xml.controller_path controller_path end end |