Class: Palmade::Cableguy::Migration
- Inherits:
-
Object
- Object
- Palmade::Cableguy::Migration
- Defined in:
- lib/palmade/cableguy/migration.rb
Instance Attribute Summary collapse
-
#cabler ⇒ Object
readonly
Returns the value of attribute cabler.
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Instance Method Summary collapse
- #boot ⇒ Object
- #delete_key(key, group = nil) ⇒ Object
- #globals(&block) ⇒ Object
- #group(group, &block) ⇒ Object
-
#initialize(cabler) ⇒ Migration
constructor
A new instance of Migration.
- #migrate! ⇒ Object
- #prefix(prefix, &block) ⇒ Object
- #set(key, value, set = nil) ⇒ Object
- #sort_directories ⇒ Object
- #update(key, value) ⇒ Object
Constructor Details
Instance Attribute Details
#cabler ⇒ Object (readonly)
Returns the value of attribute cabler.
3 4 5 |
# File 'lib/palmade/cableguy/migration.rb', line 3 def cabler @cabler end |
#db ⇒ Object (readonly)
Returns the value of attribute db.
4 5 6 |
# File 'lib/palmade/cableguy/migration.rb', line 4 def db @db end |
Instance Method Details
#boot ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/palmade/cableguy/migration.rb', line 14 def boot @db.create_table_if_needed file_stack = [] sort_directories.each do |p| path = File.join(@cabling_path, p) if p == 'targets' if !@cabler.location.nil? && @cabler.location != @cabler.target f = File.join(path, "#{@cabler.target}_#{@cabler.location}.rb") else f = File.join(path, "#{@cabler.target}.rb") end if File.exists?(f) require f file_stack.push(f) else raise "File #{f} doesn't exist!" end elsif p == '.' if File.exist?(File.join(path, 'custom.rb')) f = Dir["#{path}/custom.rb"].shift require f file_stack.push(f) end else Dir["#{path}/*.rb"].each do |d| require d file_stack.push(d) end end file_stack.each do |f| class_name = File.basename(f).chomp(".rb") camelized_class_name = (@utils.camelize(class_name)) klass = Palmade::Cableguy::Migrations.const_get(camelized_class_name) k = klass.new(@cabler) k.migrate! end file_stack.clear end end |
#delete_key(key, group = nil) ⇒ Object
84 85 86 |
# File 'lib/palmade/cableguy/migration.rb', line 84 def delete_key(key, group = nil) @db.delete_key(key, group) end |
#globals(&block) ⇒ Object
76 77 78 |
# File 'lib/palmade/cableguy/migration.rb', line 76 def globals(&block) @db.globals(&block) end |
#group(group, &block) ⇒ Object
71 72 73 74 |
# File 'lib/palmade/cableguy/migration.rb', line 71 def group(group, &block) @group = group @db.group(@group, &block) end |
#migrate! ⇒ Object
63 64 65 |
# File 'lib/palmade/cableguy/migration.rb', line 63 def migrate! raise "class #{self.class.name} doesn't have a migrate method. Override!" end |
#prefix(prefix, &block) ⇒ Object
80 81 82 |
# File 'lib/palmade/cableguy/migration.rb', line 80 def prefix(prefix, &block) @db.prefix(prefix, &block) end |
#set(key, value, set = nil) ⇒ Object
67 68 69 |
# File 'lib/palmade/cableguy/migration.rb', line 67 def set(key, value, set = nil) @db.set(key, value, set) end |
#sort_directories ⇒ Object
59 60 61 |
# File 'lib/palmade/cableguy/migration.rb', line 59 def sort_directories dir_stack = ["base", "targets", '.'] end |
#update(key, value) ⇒ Object
88 89 90 |
# File 'lib/palmade/cableguy/migration.rb', line 88 def update(key, value) @db.update(key, value) end |