Class: Towsta::Vertical

Inherits:
Object
  • Object
show all
Defined in:
lib/towsta/vertical.rb

Class Method Summary collapse

Class Method Details

.clearObject



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