Class: Spider::SetupTask
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#down ⇒ Object
Returns the value of attribute down.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#up ⇒ Object
Returns the value of attribute up.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.load(path) ⇒ Object
def inherited(subclass) @last_class = subclass end.
- .tasks ⇒ Object
Instance Method Summary collapse
- #do_down ⇒ Object
- #do_up ⇒ Object
-
#initialize(path, up = nil, down = nil) ⇒ SetupTask
constructor
A new instance of SetupTask.
- #no_sync_schema ⇒ Object
- #sync_schema(*models) ⇒ Object
- #sync_schema!(*models) ⇒ Object
Constructor Details
#initialize(path, up = nil, down = nil) ⇒ SetupTask
Returns a new instance of SetupTask.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/spiderfw/setup/setup_task.rb', line 31 def initialize(path, up=nil, down=nil) @path = path name = File.basename(path, '.rb') if (name =~ /^((?:\d\.?){1,3})/) version = $1 version = version[0..-2] if version[-1].chr == '.' desc = name[(version.length+1)..-1] else version = name desc = nil end @version = Gem::Version.new(version) @desc = desc end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
5 6 7 |
# File 'lib/spiderfw/setup/setup_task.rb', line 5 def app @app end |
#down ⇒ Object
Returns the value of attribute down.
5 6 7 |
# File 'lib/spiderfw/setup/setup_task.rb', line 5 def down @down end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/spiderfw/setup/setup_task.rb', line 4 def path @path end |
#up ⇒ Object
Returns the value of attribute up.
5 6 7 |
# File 'lib/spiderfw/setup/setup_task.rb', line 5 def up @up end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
4 5 6 |
# File 'lib/spiderfw/setup/setup_task.rb', line 4 def version @version end |
Class Method Details
.load(path) ⇒ Object
def inherited(subclass)
@last_class = subclass
end
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/spiderfw/setup/setup_task.rb', line 16 def load(path) crit = Thread.critical Thread.critical = true unless crit Kernel.load(path) obj = self.new(path) obj.up = Setup.up obj.down = Setup.down #obj = @last_class.new(path) # Kernel.send(:remove_const, @last_class.name) #@last_class = nil Thread.critical = crit return obj end |
.tasks ⇒ Object
8 9 10 |
# File 'lib/spiderfw/setup/setup_task.rb', line 8 def tasks @tasks ||= {} end |
Instance Method Details
#do_down ⇒ Object
51 52 53 |
# File 'lib/spiderfw/setup/setup_task.rb', line 51 def do_down instance_eval(&@down) end |
#do_up ⇒ Object
46 47 48 49 |
# File 'lib/spiderfw/setup/setup_task.rb', line 46 def do_up intance_eval(&@up) sync_schema unless @no_sync || @sync_done end |
#no_sync_schema ⇒ Object
55 56 57 |
# File 'lib/spiderfw/setup/setup_task.rb', line 55 def no_sync_schema @no_sync = true end |
#sync_schema(*models) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/spiderfw/setup/setup_task.rb', line 59 def sync_schema(*models) if models[-1].is_a?(Hash) = models.pop else = {} end if models.empty? models = @app.models.reject{ |m| !(m < Spider::Model::Managed) } end Spider::Model.sync_schema( model, [:force], :drop_fields => [:drop_fields], :update_sequences => [:update_sequences], :no_foreign_key_constraints => [:no_foreign_key_constraints] ) @sync_done = true end |
#sync_schema!(*models) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/spiderfw/setup/setup_task.rb', line 77 def sync_schema!(*models) if models[-1].is_a?(Hash) = models.pop else = {} end [:force] = true args = models + [] sync_schema(*args) end |