Class: Sniff::RakeTasks

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/sniff/rake_tasks.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ RakeTasks

Returns a new instance of RakeTasks.

Yields:

  • (_self)

Yield Parameters:



17
18
19
20
21
22
23
24
25
# File 'lib/sniff/rake_tasks.rb', line 17

def initialize
  self.cucumber = true
  self.rspec = false
  self.coverage = true
  self.rocco = true
  self.bueller = true
  self.watchr = true
  yield self if block_given?
end

Instance Attribute Details

#buellerObject

Returns the value of attribute bueller.



15
16
17
# File 'lib/sniff/rake_tasks.rb', line 15

def bueller
  @bueller
end

#coverageObject

Returns the value of attribute coverage.



15
16
17
# File 'lib/sniff/rake_tasks.rb', line 15

def coverage
  @coverage
end

#cucumberObject

Returns the value of attribute cucumber.



15
16
17
# File 'lib/sniff/rake_tasks.rb', line 15

def cucumber
  @cucumber
end

#roccoObject

Returns the value of attribute rocco.



15
16
17
# File 'lib/sniff/rake_tasks.rb', line 15

def rocco
  @rocco
end

#rspecObject

Returns the value of attribute rspec.



15
16
17
# File 'lib/sniff/rake_tasks.rb', line 15

def rspec
  @rspec
end

#watchrObject

Returns the value of attribute watchr.



15
16
17
# File 'lib/sniff/rake_tasks.rb', line 15

def watchr
  @watchr
end

Class Method Details

.define_tasks(&blk) ⇒ Object



11
12
13
# File 'lib/sniff/rake_tasks.rb', line 11

def self.define_tasks(&blk)
  new(&blk).define_tasks
end

Instance Method Details

#define_tasksObject



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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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
152
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
188
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
# File 'lib/sniff/rake_tasks.rb', line 46

def define_tasks
  if coverage
    task :simplecov do
      require 'simplecov' 

      SimpleCov.start do
        add_filter '/spec/'
        add_filter '/features/'
        add_filter '/vendor/'
      end
    end
  end

  task :console do
    require 'sniff'
    sniff = Sniff.new Dir.pwd
    sniff.connect

    require 'irb'
    ARGV.clear
    IRB.start
  end

  if rocco
    require 'rocco'
    require 'rocco/tasks'

    directory 'docs/'

    Rocco::make 'docs/', "lib/#{gemname}/impact_model.rb"

    task :google_analyzed_rocco => ['docs/', :rocco] do
      source = File.read "docs/lib/#{gemname}/impact_model.html"
      unless source =~ /_gaq/
        source.sub! '</head>', <<-HTML
  <script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1667526-20']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
  </script>
  <style type="text/css">
td.docs h1 {
  margin-top: 0;
}
@media print {
  .code pre {
    white-space: pre-wrap;
  }
  .code {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }
  .code .highlight {
    margin-left: 15px;
    margin-right: 15px;
  }
}
  </style>
</head>
      HTML
        File.open "docs/lib/#{gemname}/impact_model.html", 'w' do |f|
          f.puts source
        end
      end
    end

    desc 'Update rocco docs on gh-pages branch'
    task :pages => ['pages:sync', :google_analyzed_rocco] do
      rev = `git rev-parse --short HEAD`.strip
      html = File.read "docs/lib/#{gemname}/impact_model.html"

      puts `git checkout gh-pages`
      File.open 'impact_model.html', 'w' do |f|
        f.puts html
      end

      puts `git add *.html`

      puts "Commiting with message 'Rebuild pages from #{rev}'"
      git "commit -m 'Rebuild pages from #{rev}'" do |ok,res|
        if ok
          puts "Pushing to origin"
          git 'push origin gh-pages' unless ENV['NO_PUSH']
        end
      end

      git 'checkout master'
    end

    namespace :pages do
      task 'sync' => ['.git/refs/heads/gh-pages'] do |f|
        git 'fetch origin'
        git 'checkout gh-pages'
        git 'reset --hard origin/gh-pages'
        git 'checkout master'
      end

      file '.git/refs/heads/gh-pages' do |f|
        unless File.exist? f.name
          git 'branch gh-pages'
        end
      end
    end

    CLOBBER.include 'docs/'
  end

  if cucumber
    require 'cucumber'
    require 'cucumber/rake/task'

    desc 'Run all cucumber tests'
    Cucumber::Rake::Task.new(:features) do |t|
      if ENV['CUCUMBER_FORMAT']
        t.cucumber_opts = "features --format #{ENV['CUCUMBER_FORMAT']}"
      else
        t.cucumber_opts = 'features --format pretty'
      end
    end

    if coverage
      task :features_with_coverage => [:simplecov, :features]
    end
  end

  if rspec
    require 'rspec/core/rake_task'

    desc "Run all examples"
    RSpec::Core::RakeTask.new('examples') do |c|
      if ENV['RSPEC_FORMAT']
        c.rspec_opts = "-Ispec --format #{ENV['RSPEC_FORMAT']}"
      else
        c.rspec_opts = '-Ispec --format documentation'
      end
    end

    if coverage
      task :examples_with_coverage => [:simplecov, :examples]
    end
  end

  directory 'log/'

  test_tasks = ['log/']
  test_tasks << :examples if rspec
  test_tasks << :features if cucumber
  unless test_tasks.empty?
    task :test => test_tasks
    task :default => :test
  end

  RDoc::Task.new do |rdoc|
    version = File.exist?('VERSION') ? File.read('VERSION') : ""

    rdoc.rdoc_dir = 'rdoc'
    rdoc.title = "#{gemname} #{version}"
    rdoc.rdoc_files.include('README*')
    rdoc.rdoc_files.include('lib/**/*.rb')
  end

  if bueller
    require 'bueller'
    Bueller::Tasks.new
  end

  if watchr
    namespace :watch do
      task :tests do
        require 'watchr'
        path = File.expand_path(Sniff.path(%w{lib sniff watcher.rb}))
        script = Watchr::Script.new Pathname(path)
        Watchr::Controller.new(script, Watchr.handler.new).run
      end
    end
  end

  require 'sniff'
  sniff = Sniff.new Dir.pwd
  namespace :sniff do
    task :init do
      sniff.connect
    end
    task :migrate => :init do
      sniff.migrate!
    end
    task :seed => :init do
      sniff.seed!
    end
  end

  require 'earth/tasks'
  Earth::Tasks.new
  Rake::Task['earth:db:seed'].clear
  task 'db:migrate' => 'sniff:migrate'
  task 'db:seed' => 'sniff:seed'
end

#gemnameObject



35
36
37
# File 'lib/sniff/rake_tasks.rb', line 35

def gemname
  @gemname ||= File.basename(Dir.glob(File.join(Dir.pwd, '*.gemspec')).first, '.gemspec')
end

#git(cmd, dir = nil, &blk) ⇒ Object



39
40
41
42
43
44
# File 'lib/sniff/rake_tasks.rb', line 39

def git(cmd, dir = nil, &blk)
  full_cmd = ''
  full_cmd << "cd #{dir} && " if dir
  full_cmd << "unset GIT_DIR && unset GIT_INDEX_FILE && unset GIT_WORK_TREE && git #{cmd}"
  sh full_cmd, &blk
end

#ruby18?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/sniff/rake_tasks.rb', line 27

def ruby18?
  RUBY_VERSION =~ /^1\.8/ ? true : false
end

#simplecov=(val) ⇒ Object



31
32
33
# File 'lib/sniff/rake_tasks.rb', line 31

def simplecov=(val)
  self.coverage = val
end