Class: Controller
- Inherits:
-
DomainElement
- Object
- DomainElement
- Controller
- Defined in:
- lib/rails_elements.rb
Instance Attribute Summary
Attributes inherited from DomainElement
Instance Method Summary collapse
- #actions(*args) ⇒ Object
- #actions_list ⇒ Object
- #generate ⇒ Object
-
#initialize(name) ⇒ Controller
constructor
A new instance of Controller.
- #print_actions ⇒ Object
- #write_actions ⇒ Object
Methods inherited from DomainElement
Constructor Details
#initialize(name) ⇒ Controller
Returns a new instance of Controller.
94 95 96 97 98 |
# File 'lib/rails_elements.rb', line 94 def initialize(name) @file_loc = "app/controllers/#{name.pluralize}_controller.rb" @actions = [] super end |
Instance Method Details
#actions(*args) ⇒ Object
100 101 102 |
# File 'lib/rails_elements.rb', line 100 def actions *args @actions << args.flatten end |
#actions_list ⇒ Object
104 105 106 |
# File 'lib/rails_elements.rb', line 104 def actions_list @actions.join(' ') end |
#generate ⇒ Object
119 120 121 122 |
# File 'lib/rails_elements.rb', line 119 def generate puts "\ngenerating #{name} controller with specs" system "script/generate rspec_controller #{name} #{actions_list}" end |
#print_actions ⇒ Object
108 109 110 111 112 |
# File 'lib/rails_elements.rb', line 108 def print_actions tmp = [] @actions.flatten.each{|a| tmp << "\n\tdef #{a}\n\n\tend\n\n"} tmp.join("\n") end |
#write_actions ⇒ Object
114 115 116 117 |
# File 'lib/rails_elements.rb', line 114 def write_actions puts "#{name}: recording actions" unless actions.empty? insert_after(file_loc, /^class/, print_actions) end |