Class: Towsta::Vertical
- Inherits:
-
Object
- Object
- Towsta::Vertical
- Defined in:
- lib/towsta/vertical.rb
Class Method Summary collapse
- .clear ⇒ Object
- .create(args) ⇒ Object
- .populate(classname, horizontals, count, occurrences = []) ⇒ Object
Class Method Details
.clear ⇒ Object
22 23 24 25 |
# File 'lib/towsta/vertical.rb', line 22 def self.clear Vertical.all.each {|vertical| Object.instance_eval{ remove_const vertical.to_s.to_sym }} Vertical.all = [] end |
.create(args) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/towsta/vertical.rb', line 5 def self.create args model_file = Towsta.models_path + args[:name].underscore + '.rb' File.open(model_file, 'w') {|f| f.write("class #{args[:name]} < Towsta::Core\nend")} unless File.exists? model_file || Towsta.env == 'production' klass = Object.const_get args[:name] args[:slices].each { |attr, kind| klass.define_attribute attr, kind } klass.all = [] end |
.populate(classname, horizontals, count, occurrences = []) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/towsta/vertical.rb', line 13 def self.populate classname, horizontals, count, occurrences = [] klass = Kernel.const_get classname.to_s klass.all = [] klass.count = count horizontals.each {|horizontal| klass.new(horizontal)} occurrences.each {|occurrence| klass.add_occurrence(occurrence)} puts " class #{classname} was populated with #{horizontals.size} instances" end |