Class: Shoes::Setup

Inherits:
Object
  • Object
show all
Defined in:
lib/shoes/setup.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script, &blk) ⇒ Setup

Returns a new instance of Setup



84
85
86
87
88
89
90
91
# File 'lib/shoes/setup.rb', line 84

def initialize(script, &blk)
  @steps = []
  @script = script
  instance_eval &blk
  unless no_steps?
    app = self.class.setup_app(self)
  end
end

Instance Attribute Details

#scriptObject

Returns the value of attribute script



82
83
84
# File 'lib/shoes/setup.rb', line 82

def script
  @script
end

#stepsObject

Returns the value of attribute steps



82
83
84
# File 'lib/shoes/setup.rb', line 82

def steps
  @steps
end

Class Method Details

.gem_resetObject



30
31
32
33
# File 'lib/shoes/setup.rb', line 30

def self.gem_reset
  Gem.use_paths(GEM_DIR, [GEM_DIR, GEM_CENTRAL_DIR])
  Gem.source_index.refresh!
end

.initObject



25
26
27
28
# File 'lib/shoes/setup.rb', line 25

def self.init
  gem_reset
  install_sources if Gem.source_index.find_name('sources').empty?
end

.install_sourcesObject



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/shoes/setup.rb', line 189

def self.install_sources
  require 'base64'
  sources_gem = File.join(LIB_DIR, "sources-0.0.1.gem")
  File.open(sources_gem, "wb") do |f|
    f << Base64.decode64( <<-GEM.gsub(/^ +/, '') )
      ZGF0YS50YXIuZ3oAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      AAAAAAAAAAAAADAwMDA2NDQAMDAwMDAwMAAwMDAwMDAwADAwMDAwMDAwMjYw
      ADAwMDAwMDAwMDAwADA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      AAAAAAAAAAAAAAAA
    GEM
  end
  Gem::Installer.new(sources_gem).install()
end

.setup_app(setup) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/shoes/setup.rb', line 35

def self.setup_app(setup)
  appt = "Setting up for #{setup.script}"
  Shoes.app :width => 370, :height => 158, :resizable => false, :title => appt do
    background "#EEE".."#9AA"
    image :top => 0, :left => 0 do
      stroke "#FFF"; strokewidth 0.1
      (0..158).step(3) { |i| line 0, i, 370, i }
    end
    @pulse = stack :top => 0, :left => 0
    @logo = image "#{DIR}/static/shoes-icon-blue.png", :top => -20, :right => -20
    stack :margin => 18 do
      title "Shoes Setup", :size => 12, :weight => "bold", :margin => 0
      para "Preparing #{setup.script}", :size => 8, :margin => 0, :margin_top => 8, :width => 220
      @pr = progress :width => 1.0, :top => 70, :height => 20
      button "Cancel", :top => 98, :left => 0.4 do
        self.close
      end

      start do
        @th = 
          Thread.start(self.app) do |app|
            begin
              setup.start(app)
            rescue => e
              puts e.message
            end
          end
      end
    end

    animate 10 do |i|
      i %= 10
      @pulse.clear do
        fill black(0.2 - (i * 0.02))
        strokewidth(3.0 - (i * 0.2))
        stroke rgb(0.7, 0.7, 0.9, 1.0 - (i * 0.1))
        oval(@logo.left - i, @logo.top - i, @logo.width + (i * 2)) 
      end
      @pr.fraction = $fraction
      if @script
        Shoes.visit(@script)
        close
      end
    end
  end
end

Instance Method Details

#activate_gem(name, version) ⇒ Object



111
112
113
114
# File 'lib/shoes/setup.rb', line 111

def activate_gem(name, version)
  gem = Gem.source_index.find_name(name, version).first
  Gem.activate(gem.name, "= #{gem.version}")
end

#gem(name, version = nil) ⇒ Object



97
98
99
100
101
102
103
104
105
# File 'lib/shoes/setup.rb', line 97

def gem name, version = nil
  arg = "#{name} #{version}".strip
  name, version = arg.split(/\s+/, 2)
  if Gem.source_index.find_name(name, version).empty?
    @steps << [:gem, arg]
  else
    activate_gem(name, version)
  end
end

#no_steps?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/shoes/setup.rb', line 93

def no_steps?
  (@steps.map { |s| s[0] }.uniq - [:source]).empty?
end

#source(uri) ⇒ Object



107
108
109
# File 'lib/shoes/setup.rb', line 107

def source uri
  @steps << [:source, uri]
end

#start(app) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/shoes/setup.rb', line 116

def start(app)
  old_ui = Gem::DefaultUserInteraction.ui
  ui = Gem::DefaultUserInteraction.ui = Gem::ShoesFace.new(app)
  count, total = 0.5, @steps.length
  ui.progress count, total

  steps.each do |act, arg|
    case act
    when :gem
      name, version = arg.split(/\s+/, 2)
      count += 1
      ui.say "Looking for #{name}"
      if Gem.source_index.find_name(name, version).empty?
        ui.title "Installing #{name}"
        installer = Gem::DependencyInstaller.new
        begin
          installer.install(name, version || Gem::Requirement.default)
          self.class.gem_reset
          activate_gem(name, version)
          ui.say "Finished installing #{name}"
        rescue Object => e
          ui.error "while installing #{name}", e
          raise e
        end
      end
    when :source
      ui.title "Switching Gem servers"
      ui.say "Pulling from #{arg}"
      Gem.sources.clear << arg
      self.class.gem_reset
    end
    ui.progress count, total
  end
  Gem::DefaultUserInteraction.ui = old_ui
  app.instance_variable_set("@script", @script)
end

#svn(dir, save_as = nil, &blk) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/shoes/setup.rb', line 153

def svn(dir, save_as = nil, &blk)
  dir.gsub! /(.)\/*$/, '\1/'
  if save_as.nil? or save_as.empty?
    save_as = File.join(GEM_DIR, 'svn', '1')
    save_as.succ! while File.exists? save_as
  elsif save_as.index(GEM_DIR) != 0
    save_as = File.join(GEM_DIR, 'svn', save_as)
  end
  mkdir_p(save_as)
  puts "** Pulling down #{dir}..."
  svnuri = URI.parse(dir)
  case svnuri.scheme
  when "http", "https"
    REXML::Document.new(svnuri.open { |f| f.read }).
      each_element("/svn/index/*") do |ele|
        fname, href = ele.attributes['name'], ele.attributes['href']
        case ele.name
        when "file"
          puts "- #{dir}#{href}"
          URI.parse("#{dir}#{href}").open do |f|
            File.open(File.join(save_as, fname), 'wb') do |f2|
              f2 << f.read(16384) until f.eof?
            end
          end
        when "dir"
          svn("#{dir}#{href}", File.join(save_as, fname))
        end
      end
  else
    raise NotSupportedByShoes, "Only HTTP addresses are supported by Shoes's Subversion module."
  end
  if blk
    Dir.chdir(save_as, &blk)
  end
end