Class: ResourceLayout
- Inherits:
-
Object
- Object
- ResourceLayout
- Defined in:
- lib/resource_layout.rb
Class Method Summary collapse
- .add_to_routes_definition(line, scope) ⇒ Object
- .load(root) ⇒ Object
- .resources ⇒ Object
- .routes_definition ⇒ Object
Instance Method Summary collapse
-
#initialize(&block) ⇒ ResourceLayout
constructor
A new instance of ResourceLayout.
- #many(resource, attributes = {}) ⇒ Object
- #one(resource, attributes = {}) ⇒ Object
Constructor Details
#initialize(&block) ⇒ ResourceLayout
Returns a new instance of ResourceLayout.
3 4 5 6 |
# File 'lib/resource_layout.rb', line 3 def initialize(&block) @scope = [] self.instance_exec(&block) end |
Class Method Details
.add_to_routes_definition(line, scope) ⇒ Object
19 20 21 |
# File 'lib/resource_layout.rb', line 19 def add_to_routes_definition(line, scope) routes_definition << ' '*(scope.length+2) + line + "\n" end |
.load(root) ⇒ Object
23 24 25 |
# File 'lib/resource_layout.rb', line 23 def load(root) require root + '/config/resource_layout' end |
.resources ⇒ Object
11 12 13 |
# File 'lib/resource_layout.rb', line 11 def resources @@resources ||= [] end |
.routes_definition ⇒ Object
15 16 17 |
# File 'lib/resource_layout.rb', line 15 def routes_definition @@route_definition ||= "\n" end |
Instance Method Details
#many(resource, attributes = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/resource_layout.rb', line 28 def many(resource, attributes={}) current_scope = @scope.dup self.class.resources << [resource.to_s, attributes, {:scope => current_scope, :singleton => false}] if block_given? @scope << resource.to_s self.class.add_to_routes_definition "resources :#{resource}, :controller => '#{current_scope.collect{|s| s.to_s.singularize + '_'}.join}#{resource.to_s.pluralize}' do", current_scope yield self.class.add_to_routes_definition "end", current_scope @scope = current_scope else self.class.add_to_routes_definition "resources :#{resource}, :controller => '#{current_scope.collect{|s| s.to_s.singularize + '_'}.join}#{resource.to_s.pluralize}'", current_scope end end |
#one(resource, attributes = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/resource_layout.rb', line 42 def one(resource, attributes={}) current_scope = @scope.dup self.class.resources << [resource.to_s, attributes, {:scope => current_scope, :singleton => true}] if block_given? @scope << resource.to_s self.class.add_to_routes_definition "resource :#{resource}, :controller => '#{current_scope.collect{|s| s.to_s.singularize + '_'}.join}#{resource.to_s.singularize}' do", current_scope yield self.class.add_to_routes_definition "end", current_scope @scope = current_scope else self.class.add_to_routes_definition "resource :#{resource}, :controller => '#{current_scope.collect{|s| s.to_s.singularize + '_'}.join}#{resource.to_s.singularize}'", current_scope end end |