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
249
250
# 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

  desc "Load a console"
  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>', "  <script type=\"text/javascript\">\nvar _gaq = _gaq || [];\n_gaq.push(['_setAccount', 'UA-1667526-20']);\n_gaq.push(['_trackPageview']);\n\n(function() {\n  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n})();\n  </script>\n  <style type=\"text/css\">\ntd.docs h1 {\n  margin-top: 0;\n}\n@media print {\n  .code pre {\n    white-space: pre-wrap;\n  }\n  .code {\n    padding-left: 0 !important;\n    padding-right: 0 !important;\n  }\n  .code .highlight {\n    margin-left: 15px;\n    margin-right: 15px;\n  }\n}\n  </style>\n</head>\n      HTML\n        File.open \"docs/lib/\#{gemname}/impact_model.html\", 'w' do |f|\n          f.puts source\n        end\n      end\n    end\n\n    desc 'Update rocco docs on gh-pages branch'\n    task :pages => ['pages:sync', :google_analyzed_rocco] do\n      rev = `git rev-parse --short HEAD`.strip\n      html = File.read \"docs/lib/\#{gemname}/impact_model.html\"\n\n      puts `git checkout gh-pages`\n      File.open 'impact_model.html', 'w' do |f|\n        f.puts html\n      end\n\n      puts `git add *.html`\n\n      puts \"Commiting with message 'Rebuild pages from \#{rev}'\"\n      git \"commit -m 'Rebuild pages from \#{rev}'\" do |ok,res|\n        if ok\n          puts \"Pushing to origin\"\n          git 'push origin gh-pages' unless ENV['NO_PUSH']\n        end\n      end\n\n      git 'checkout master'\n    end\n\n    namespace :pages do\n      task 'sync' => ['.git/refs/heads/gh-pages'] do |f|\n        git 'fetch origin'\n        git 'checkout gh-pages'\n        git 'reset --hard origin/gh-pages'\n        git 'checkout master'\n      end\n\n      file '.git/refs/heads/gh-pages' do |f|\n        unless File.exist? f.name\n          git 'branch gh-pages'\n        end\n      end\n    end\n\n    CLOBBER.include 'docs/'\n  end\n\n  if cucumber\n    require 'cucumber'\n    require 'cucumber/rake/task'\n\n    desc 'Run all cucumber tests'\n    Cucumber::Rake::Task.new(:features) do |t|\n      if ENV['CUCUMBER_FORMAT']\n        t.cucumber_opts = \"features --format \#{ENV['CUCUMBER_FORMAT']}\"\n      else\n        t.cucumber_opts = 'features --format pretty'\n      end\n    end\n\n    if coverage\n      task :features_with_coverage => [:simplecov, :features]\n    end\n  end\n\n  if rspec\n    require 'rspec/core/rake_task'\n  \n    desc \"Run all rspec examples\"\n    RSpec::Core::RakeTask.new('examples') do |c|\n      if ENV['RSPEC_FORMAT']\n        c.rspec_opts = \"-Ispec --format \#{ENV['RSPEC_FORMAT']}\"\n      else\n        c.rspec_opts = '-Ispec --format documentation'\n      end\n    end\n\n    if coverage\n      task :examples_with_coverage => [:simplecov, :examples]\n    end\n  end\n\n  directory 'log/'\n\n  test_tasks = ['log/']\n  test_tasks << :examples if rspec\n  test_tasks << :features if cucumber\n  unless test_tasks.empty?\n    desc \"Run tests\"\n    task :test => test_tasks\n    task :default => :test\n  end\n\n  RDoc::Task.new do |rdoc|\n    version = File.exist?('VERSION') ? File.read('VERSION') : \"\"\n\n    rdoc.rdoc_dir = 'rdoc'\n    rdoc.title = \"\#{gemname} \#{version}\"\n    rdoc.rdoc_files.include('README*')\n    rdoc.rdoc_files.include('lib/**/*.rb')\n  end\n\n  if bueller\n    require 'bueller'\n    Bueller::Tasks.new\n  end\n\n  if watchr\n    namespace :watch do\n      task :tests do\n        require 'watchr'\n        path = File.expand_path(Sniff.path(%w{lib sniff watcher.rb}))\n        script = Watchr::Script.new Pathname(path)\n        Watchr::Controller.new(script, Watchr.handler.new).run\n      end\n    end\n  end\n\n  require 'sniff'\n  sniff = Sniff.new Dir.pwd\n  namespace :sniff do\n    task :init do\n      sniff.connect\n    end\n    task :migrate => :init do\n      sniff.migrate!\n    end\n    task :seed => :init do\n      sniff.seed!\n    end\n  end\n\n  require 'earth/tasks'\n  Earth::Tasks.new\n  Rake::Task['earth:db:seed'].clear\n  task 'db:migrate' => 'sniff:migrate'\n  task 'db:seed' => 'sniff:seed'\nend\n"

#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