Class: Controller

Inherits:
DomainElement show all
Defined in:
lib/rails_elements.rb

Instance Attribute Summary

Attributes inherited from DomainElement

#file_loc, #name

Instance Method Summary collapse

Methods inherited from DomainElement

#insert_after

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_listObject



104
105
106
# File 'lib/rails_elements.rb', line 104

def actions_list
  @actions.join(' ')
end

#generateObject



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


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_actionsObject



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