Class: Resource

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

Constant Summary

Constants included from FileBase

FileBase::Home

Instance Attribute Summary collapse

Attributes inherited from DomainElement

#file_loc, #name

Instance Method Summary collapse

Methods included from FileBase

#copy, #destroy, #exists?, #file_path, #has_location?, #home, #location, #make_dir, #mkdir, #move, #path, #reset_location, #set_home, #set_location, #write

Methods inherited from DomainElement

#insert_after

Constructor Details

#initialize(name) ⇒ Resource

Returns a new instance of Resource.



130
131
132
133
134
# File 'lib/rails_elements.rb', line 130

def initialize(name)
  super
  @model = Model.new name
  @controller = Controller.new name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &blk) ⇒ Object



145
146
147
148
149
150
151
152
153
154
# File 'lib/rails_elements.rb', line 145

def method_missing(method, *args, &blk)
  case
  when model.respond_to?(method) then
  model.send(method, *args, &blk)
  when controller.respond_to?(method) then
  controller.send(method, *args, &blk)
  else
  super
  end
end

Instance Attribute Details

#controllerObject

Returns the value of attribute controller.



128
129
130
# File 'lib/rails_elements.rb', line 128

def controller
  @controller
end

#modelObject

Returns the value of attribute model.



128
129
130
# File 'lib/rails_elements.rb', line 128

def model
  @model
end

Instance Method Details

#generateObject



136
137
138
139
140
141
142
143
# File 'lib/rails_elements.rb', line 136

def generate
  puts "\n#- - - - - - - - - - - - - - - - - - -#\n"
  puts "generating #{name} resource with specs\n"
  system "script/generate rspec_resource #{name} #{attribute_string}\n"
  model.write_associations
  model.write_plugin_methods
  controller.write_actions
end