Class: Spider::SetupTask

Inherits:
Object show all
Defined in:
lib/spiderfw/setup/setup_task.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#appObject

Returns the value of attribute app.



5
6
7
# File 'lib/spiderfw/setup/setup_task.rb', line 5

def app
  @app
end

#downObject

Returns the value of attribute down.



5
6
7
# File 'lib/spiderfw/setup/setup_task.rb', line 5

def down
  @down
end

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/spiderfw/setup/setup_task.rb', line 4

def path
  @path
end

#upObject

Returns the value of attribute up.



5
6
7
# File 'lib/spiderfw/setup/setup_task.rb', line 5

def up
  @up
end

#versionObject (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

.tasksObject



8
9
10
# File 'lib/spiderfw/setup/setup_task.rb', line 8

def tasks
    @tasks ||= {}
end

Instance Method Details

#do_downObject



51
52
53
# File 'lib/spiderfw/setup/setup_task.rb', line 51

def do_down
    instance_eval(&@down)
end

#do_upObject



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_schemaObject



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)
        options = models.pop
    else
        options = {}
    end
    if models.empty?
        models = @app.models.reject{ |m| !(m < Spider::Model::Managed) }
    end
    Spider::Model.sync_schema(
        model, options[:force], 
        :drop_fields => options[:drop_fields], 
        :update_sequences => options[:update_sequences], 
        :no_foreign_key_constraints => options[: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)
        options = models.pop
    else
        options = {}
    end
    options[:force] = true
    args = models + [options]
    sync_schema(*args)
end