puppet-herald 0.2.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +5 -13
  2. data/.gitignore +3 -0
  3. data/.jshintrc +19 -0
  4. data/Gemfile +25 -12
  5. data/Gemfile.local.example +3 -0
  6. data/Guardfile +57 -0
  7. data/README.md +1 -1
  8. data/Rakefile +100 -20
  9. data/db/migrate/20141218200108_remove_no_of_reports_from_nodes.rb +7 -0
  10. data/lib/puppet-herald.rb +95 -65
  11. data/lib/puppet-herald/app/api.rb +79 -12
  12. data/lib/puppet-herald/app/configuration.rb +47 -15
  13. data/lib/puppet-herald/app/frontend.rb +6 -6
  14. data/lib/puppet-herald/app/views/app.erb +14 -20
  15. data/lib/puppet-herald/app/views/err500.erb +8 -5
  16. data/lib/puppet-herald/application.rb +9 -1
  17. data/lib/puppet-herald/cli.rb +5 -11
  18. data/lib/puppet-herald/database.rb +1 -7
  19. data/lib/puppet-herald/javascript.rb +16 -10
  20. data/lib/puppet-herald/models.rb +47 -0
  21. data/lib/puppet-herald/models/log-entry.rb +2 -0
  22. data/lib/puppet-herald/models/node.rb +49 -2
  23. data/lib/puppet-herald/models/report.rb +33 -9
  24. data/lib/puppet-herald/project.js +46 -0
  25. data/lib/puppet-herald/public/app.js +11 -9
  26. data/lib/puppet-herald/public/bower.json +10 -3
  27. data/lib/puppet-herald/public/components/artifact/artifact-directive.js +4 -0
  28. data/lib/puppet-herald/public/components/artifact/artifact.js +1 -3
  29. data/lib/puppet-herald/public/components/directives/directives.js +5 -1
  30. data/lib/puppet-herald/public/components/directives/status-button.html +1 -1
  31. data/lib/puppet-herald/public/components/directives/status-button.js +11 -11
  32. data/lib/puppet-herald/public/components/filters/filters.js +6 -2
  33. data/lib/puppet-herald/public/components/page.js +2 -2
  34. data/lib/puppet-herald/public/components/pagination.js +142 -0
  35. data/lib/puppet-herald/public/components/settings.js +25 -0
  36. data/lib/puppet-herald/public/css/herald.css +100 -3
  37. data/lib/puppet-herald/public/general/app.html +73 -0
  38. data/lib/puppet-herald/public/img/shield97-white.svg +53 -0
  39. data/lib/puppet-herald/public/img/shield97.png +0 -0
  40. data/lib/puppet-herald/public/node/node.html +27 -9
  41. data/lib/puppet-herald/public/node/node.js +43 -15
  42. data/lib/puppet-herald/public/nodes/nodes.html +25 -7
  43. data/lib/puppet-herald/public/nodes/nodes.js +29 -14
  44. data/lib/puppet-herald/public/report/report.html +60 -13
  45. data/lib/puppet-herald/public/report/report.js +21 -14
  46. data/lib/puppet-herald/public/router.js +55 -0
  47. data/lib/puppet-herald/purgecronjob.rb +35 -0
  48. data/lib/puppet-herald/version.rb +2 -2
  49. data/package.json +14 -16
  50. data/puppet-herald.gemspec +12 -7
  51. data/spec/integration/app/configuration_spec.rb +33 -0
  52. data/spec/integration/application_spec.rb +139 -20
  53. data/spec/integration/fixtures/nodes.yml +13 -0
  54. data/spec/integration/fixtures/pending-notify.yaml +346 -0
  55. data/spec/integration/fixtures/reports.yml +61 -0
  56. data/spec/integration/models/node_spec.rb +12 -3
  57. data/spec/integration/models/report_spec.rb +60 -4
  58. data/spec/spec_helper.rb +6 -10
  59. data/spec/support/active_record.rb +1 -0
  60. data/spec/support/fixtures.rb +16 -0
  61. data/spec/unit/puppet-herald/cli_spec.rb +4 -4
  62. data/spec/unit/puppet-herald/database_spec.rb +5 -3
  63. data/spec/unit/puppet-herald/purgecronjob_spec.rb +37 -0
  64. data/test/javascript/.bowerrc +3 -0
  65. data/test/javascript/bower.json +21 -0
  66. data/test/javascript/karma.conf.js +17 -22
  67. data/test/javascript/src/app_test.js +10 -61
  68. data/test/javascript/src/components/directives/status-button_test.js +10 -10
  69. data/test/javascript/src/components/paginate_test.js +183 -0
  70. data/test/javascript/src/node/node_test.js +16 -6
  71. data/test/javascript/src/nodes/nodes_test.js +14 -2
  72. data/test/javascript/src/report/report_test.js +6 -6
  73. data/test/javascript/src/router_test.js +79 -0
  74. metadata +642 -23
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NWQxYTc4MjVkZGQ2NzM5MTk4ZTUxNDUzY2I5MzYzMjMwNDA0ZTk0Ng==
5
- data.tar.gz: !binary |-
6
- ZTdkYTA0MDU0OWM1ZGRhZTZmZTg0NzUzOTkzOWE3MTE4NjA0Y2IyNw==
2
+ SHA1:
3
+ metadata.gz: 2ee304896b40f495005c9736912edbd4be29c3af
4
+ data.tar.gz: 98065e6b110c281a4fc48d07481891860e4aba33
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NDhjYTZiNDkyN2M0YzFlZWNkMzkwOGU4NTUzYjc1MDA0MDFjNjY5MzI0M2Q2
10
- ZjhhYWVhMmMxOTNkM2Q1MzM0OWU5YWYyYzIyMGVkYmNjM2NiNGFiMDFlMTQ2
11
- MGMxMjVjODY0N2JjZDU4ZGRlNzliNDk3MmFjNTVkYjg3NWJkYzQ=
12
- data.tar.gz: !binary |-
13
- MDRjOGZkMGFmZmU2ZWUyMWFiYzJkZGNjMWI1YmNhNGI0ODVmYzgzNDQ3M2Vj
14
- YjUxNWM2YWQzYzY1ZjIwMWYxOTBmYWVkOWFhMzcwMWM4Mzk5NDE4MzJmYWMw
15
- NjBhZTRiMjliNzE4ODg5NzU2NjhkMWUyMGZiYzExNTQxMDdjMmU=
6
+ metadata.gz: f8cb0f887979c0ef58ebe1fa92b1d78d9de35cb93a1ee01b05157ea3c2f13653060afc100a6ab414768bd587193800129bb8d25df17f3361bf305288eb31cffd
7
+ data.tar.gz: 9e6af822fbf2070d6b5075185ded7f6fc4d67c5444eda55dab2a49c9e200dff6fd0605afc900b26668f17f9e9c8e8cdf75386c8f707845e69a36b454fc02e406
data/.gitignore CHANGED
@@ -22,4 +22,7 @@
22
22
  /tmp
23
23
  /node_modules
24
24
  /npm-*.log
25
+
25
26
  /Gemfile.local
27
+ bower_components
28
+ *.gem
data/.jshintrc ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "bitwise": true,
3
+ "curly": true,
4
+ "eqeqeq": true,
5
+ "forin": true,
6
+ "immed": true,
7
+ "latedef": true,
8
+ "newcap": true,
9
+ "noarg": true,
10
+ "noempty": true,
11
+ "nonew": true,
12
+ "plusplus": true,
13
+ "regexp": true,
14
+ "undef": true,
15
+ "strict": true,
16
+ "trailing": true,
17
+ "browser": true,
18
+ "predef": ["angular"]
19
+ }
data/Gemfile CHANGED
@@ -3,24 +3,37 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :test do
6
- gem 'rake', '~> 10.4'
7
- gem 'rspec', '~> 3.1'
8
- gem 'rspec-its', '~> 1.1'
9
- gem 'webmock', '~> 1.20'
10
- gem 'coveralls', '~> 0.7'
11
- gem 'simplecov', '~> 0.9'
12
- gem 'sqlite3', '~> 1.3'
13
- gem 'rubocop', '~> 0.28'
6
+ gem 'rake', '~> 10.4.0', require: false
7
+ gem 'rspec', '~> 3.2.0', require: false
8
+ gem 'rspec-its', '~> 1.2.0', require: false
9
+ gem 'webmock', '~> 1.21.0', require: false
10
+ gem 'simplecov-lcov', '~> 0.4.0', require: false
11
+ gem 'simplecov', '~> 0.9.0', require: false
12
+ gem 'sqlite3', '~> 1.3.0', require: false
13
+ gem 'rubocop', '~> 0.30.0', require: false
14
+ gem 'rspec-activerecord', '~> 0.0.2', require: false
15
+ gem 'ox', '~> 2.1.0', require: false
16
+ gem 'jshintrb', '~> 0.3.0', require: false
17
+ gem 'inch', '~> 0.5.0', require: false
14
18
  end
15
19
 
16
20
  group :development do
17
- gem 'inch', '~> 0.5'
18
- gem 'travis', '~> 1.6'
19
- gem 'pry-byebug', '~> 2.0' if RUBY_VERSION >= '2.0.0'
20
- gem 'pry-debugger', '~> 0.2' if RUBY_VERSION < '2.0.0'
21
+ gem 'guard', '~> 2.12.0', require: false
22
+ gem 'guard-bundler', '~> 2.1.0', require: false
23
+ gem 'guard-rspec', '~> 4.5.0', require: false
24
+ gem 'guard-rake', '~> 1.0.0', require: false
25
+ gem 'guard-shell', '~> 0.7.0', require: false
26
+ gem 'guard-rubocop', '~> 1.2.0', require: false
27
+ gem 'pry-byebug', '~> 3.1.0', require: false if RUBY_VERSION > '2.0.0'
21
28
  end
22
29
 
23
30
  local_gemfile = File.join(File.dirname(__FILE__), 'Gemfile.local')
24
31
  eval_gemfile local_gemfile if File.exist?(local_gemfile)
25
32
 
33
+ begin
34
+ npmbin = `npm bin`.strip
35
+ ENV['PATH'] = "#{npmbin}:#{ENV['PATH']}"
36
+ rescue # rubocop:disable Lint/HandleExceptions
37
+ # nothing
38
+ end
26
39
  # vim:ft=ruby
@@ -3,5 +3,8 @@ gem 'pg'
3
3
  gem 'puma'
4
4
  # gem 'thin'
5
5
 
6
+ # Until released without support for 1.8
7
+ gem 'travis', '<= 1.6.11', require: false
8
+
6
9
 
7
10
  # vim:ft=ruby
data/Guardfile ADDED
@@ -0,0 +1,57 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ directories %w(lib test spec bin)
6
+
7
+ ## Uncomment to clear the screen before every task
8
+ clearing :on
9
+
10
+ ignore /coverage/, /bower_components/
11
+
12
+ guard :rspec, cmd: "bundle exec rspec" do
13
+ require "guard/rspec/dsl"
14
+ dsl = Guard::RSpec::Dsl.new(self)
15
+
16
+ # Feel free to open issues for suggestions and improvements
17
+
18
+ # RSpec files
19
+ rspec = dsl.rspec
20
+ watch(rspec.spec_helper) { rspec.spec_dir }
21
+ watch(rspec.spec_support) { rspec.spec_dir }
22
+ watch(rspec.spec_files)
23
+
24
+ # Ruby files
25
+ ruby = dsl.ruby
26
+ dsl.watch_spec_files_for(ruby.lib_files)
27
+
28
+ # Turnip features and steps
29
+ watch(%r{^spec/acceptance/(.+)\.feature$})
30
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
31
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
32
+ end
33
+ end
34
+
35
+ guard :bundler do
36
+ watch('Gemfile')
37
+ # Uncomment next line if Gemfile contain `gemspec' command
38
+ watch(/^.+\.gemspec/)
39
+ end
40
+
41
+ guard :rake, :task => 'inch', :all_on_start => false do
42
+ watch(%r{^lib/(.+).rb$})
43
+ end
44
+
45
+ guard :rake, :task => 'js:test', :all_on_start => false do
46
+ watch(%r{^lib/puppet-herald/public/(.+).js$})
47
+ watch(%r{^test/javascript/src/(.+)_test.js$})
48
+ watch(%r{^test/javascript/karma.conf.js$})
49
+ watch(%r{^test/javascript/bower.json$})
50
+ watch(%r{^package.json$})
51
+ end
52
+
53
+ guard :rubocop do
54
+ watch(%{^Rakefile$})
55
+ watch(%r{.+\.rb$})
56
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
57
+ end
data/README.md CHANGED
@@ -197,7 +197,7 @@ npm install
197
197
  And then test Javascript code with:
198
198
 
199
199
  ```shell
200
- bundle exec rake js
200
+ bundle exec rake js:test
201
201
  ```
202
202
 
203
203
  Check your code for quality with:
data/Rakefile CHANGED
@@ -1,9 +1,26 @@
1
-
1
+ require 'jshintrb/jshinttask'
2
2
  require 'sinatra/activerecord/rake'
3
3
  require 'rspec/core/rake_task'
4
4
  require 'rubocop/rake_task'
5
5
  require 'rubocop'
6
6
  require 'fileutils'
7
+ require 'rainbow'
8
+ require 'inch/rake'
9
+
10
+ def cobertura_attrs
11
+ require 'ox'
12
+ f = File.open 'coverage/javascript/cobertura.xml'
13
+ Ox.parse(f.read).root.attributes
14
+ end
15
+
16
+ def verify_js_coverage(line_expected = 0.9, branch_expected = 0.9)
17
+ attrs = cobertura_attrs
18
+ fail "Line coverage is #{attrs[:'line-rate'].to_f * 100}%, " \
19
+ "that don't meet minimum requirements of #{line_expected * 100}%." if attrs[:'line-rate'].to_f < line_expected
20
+
21
+ fail "Branch coverage is #{attrs[:'branch-rate'].to_f * 100}%, " \
22
+ "that don't meet minimum requirements of #{branch_expected * 100}%." if attrs[:'branch-rate'].to_f < branch_expected
23
+ end
7
24
 
8
25
  namespace :spec do
9
26
  desc 'Run all spec tests at once.'
@@ -24,29 +41,65 @@ namespace :spec do
24
41
  end
25
42
  end
26
43
 
27
- desc 'Run javascript Jasmine/Karma tests on PhantomJS.'
28
- task :js do
29
- FileUtils.rm_rf 'coverage/javascript'
30
- sh 'node_modules/karma/bin/karma start --browsers PhantomJS test/javascript/karma.conf.js'
31
- path = Pathname.glob('coverage/javascript/PhantomJS*/text.txt').first
32
- puts 'Coverage for Javascript:'
33
- puts File.read(path)
34
- end
44
+ namespace :js do
45
+ desc 'Install NPM dependencies'
46
+ task :install do
47
+ sh 'npm install'
48
+ end
49
+ task :bower_standalone do
50
+ Dir.chdir 'lib/puppet-herald/public' do
51
+ sh 'bower install -p'
52
+ end
53
+ Dir.chdir 'test/javascript' do
54
+ sh 'bower install'
55
+ end
56
+ end
57
+ task :test_standalone do
58
+ FileUtils.rm_rf 'coverage/javascript'
59
+ sh 'node_modules/karma/bin/karma start --browsers PhantomJS test/javascript/karma.conf.js'
60
+ path = Pathname.glob('coverage/javascript/text.txt').first
61
+ puts Rainbow("\nCoverage for Javascript:\n").blue
62
+ puts File.read(path)
63
+ begin
64
+ verify_js_coverage
65
+ rescue StandardError => ex
66
+ $stderr.puts Rainbow("\n#{ex.message} Write more tests!\n").red.bright
67
+ exit 2
68
+ end
69
+ end
70
+ Jshintrb::JshintTask.new :hint do |t|
71
+ t.pattern = 'lib/puppet-herald/public/**/*.js'
72
+ t.exclude_pattern = 'lib/puppet-herald/public/bower_components/**/*'
73
+ t.options = :jshintrc
74
+ end
35
75
 
36
- tests = [
37
- :'spec:all',
38
- :js,
39
- :rubocop
40
- ]
76
+ desc 'Install bower JS dependencies.'
77
+ task bower: [:'js:install', :'js:bower_standalone']
78
+ desc 'Run javascript Jasmine/Karma tests on PhantomJS.'
79
+ task test: [:'js:install', :'js:bower', :'js:hint', :'js:test_standalone']
80
+ end
41
81
 
42
- begin
43
- require 'inch/rake'
44
- Inch::Rake::Suggest.new :inch, '--pedantic'
45
- tests << :inch
46
- rescue LoadError # rubocop:disable all
47
- # nothing here
82
+ namespace :console do
83
+ desc 'Start a console with loaded ActiveRecord models on dev database'
84
+ task :db do
85
+ require 'pry'
86
+ require 'puppet-herald'
87
+ PuppetHerald.environment = :dev
88
+ home = File.expand_path('~')
89
+ defaultdb = "sqlite://#{home}/pherald.db"
90
+ defaultdbpass = "#{home}/.pherald.pass"
91
+ PuppetHerald.database.dbconn = defaultdb
92
+ PuppetHerald.database.passfile = defaultdbpass
93
+ PuppetHerald.database.spec
94
+ require 'puppet-herald/app/configuration'
95
+ PuppetHerald::App::Configuration.configure_app(cron: false)
96
+ require 'puppet-herald/models/node'
97
+ pry
98
+ end
48
99
  end
49
100
 
101
+ Inch::Rake::Suggest.new :inch, '--pedantic'
102
+
50
103
  RuboCop::RakeTask.new(:rubocop) do |task|
51
104
  # don't abort rake on failure
52
105
  task.fail_on_error = true
@@ -68,7 +121,34 @@ namespace :rubocop do
68
121
  end
69
122
  end
70
123
 
124
+ desc 'Combine and POST covarage result to coveralls.io'
125
+ task :coveralls do
126
+ root = File.dirname(File.expand_path(__FILE__))
127
+ rlcov = File.read('./coverage/ruby/lcov/gem-puppet-herald.lcov').gsub("#{root}/", './')
128
+ File.write('./coverage/ruby/lcov/lcov.info', rlcov)
129
+ sh "./node_modules/.bin/lcov-result-merger 'coverage/*/lcov/lcov.info' | ./node_modules/coveralls/bin/coveralls.js"
130
+ end
131
+
132
+ tests = [
133
+ :'js:test',
134
+ :'spec:all',
135
+ :rubocop,
136
+ :inch
137
+ ]
138
+ tests << :coveralls if ENV['TRAVIS']
139
+
71
140
  desc 'Run lint, and all spec tests.'
72
141
  task test: tests
73
142
 
143
+ desc 'Installs all dependencies.'
144
+ task install: [:'js:install', :'js:bower']
145
+
146
+ desc 'Build a gem package.'
147
+ task :gem do
148
+ sh 'gem build puppet-herald.gemspec'
149
+ end
150
+
151
+ desc 'Builds, and test package'
152
+ task build: [:install, :test, :gem]
153
+
74
154
  task default: :test
@@ -0,0 +1,7 @@
1
+ # Migration
2
+ class RemoveNoOfReportsFromNodes < ActiveRecord::Migration
3
+ # Migration
4
+ def change
5
+ remove_column :nodes, :no_of_reports, :integer
6
+ end
7
+ end
data/lib/puppet-herald.rb CHANGED
@@ -5,83 +5,113 @@ rescue LoadError # rubocop:disable Lint/HandleExceptions
5
5
  end
6
6
 
7
7
  require 'puppet-herald/database'
8
+ require 'logger'
8
9
 
9
10
  # A module for Herald
10
11
  module PuppetHerald
11
12
  @root = File.dirname(File.dirname(File.realpath(__FILE__)))
12
13
  @database = PuppetHerald::Database.new
14
+ @logger = Logger.new STDOUT
15
+ @errlogger = Logger.new STDERR
13
16
 
14
- # A database object
15
- # @return [PuppetHerald::Database] a database object
16
- def self.database # rubocop:disable Style/TrivialAccessors
17
- @database
18
- end
17
+ class << self
18
+ # Logger for CLI interface (error)
19
+ # @return [Logger] logger for CLI
20
+ attr_reader :errlogger
19
21
 
20
- # Calculates a replative directory inside the project
21
- #
22
- # @param dir [String] a sub directory
23
- # @return [String] a full path to replative dir
24
- def self.relative_dir(dir)
25
- File.realpath(File.join @root, dir)
26
- end
22
+ # Logger for CLI interface
23
+ # @return [Logger] logger for CLI
24
+ attr_reader :logger
27
25
 
28
- def self.environment=(environment)
29
- rackenv = :production
30
- envsymbol = environment.to_s.to_sym
31
- case envsymbol
32
- when :dev, :development
33
- rackenv = :development
34
- when :test, :ci
35
- rackenv = :test
36
- else
37
- rackenv = :production
38
- envsymbol = :production
26
+ # A database object
27
+ # @return [PuppetHerald::Database] a database object
28
+ def database # rubocop:disable Style/TrivialAccessors
29
+ @database
39
30
  end
40
- ENV['PUPPET_HERALD_ENV'] = envsymbol.to_s
41
- ENV['RACK_ENV'] = rackenv.to_s
42
- end
43
31
 
44
- # Gets the environment set for Herald
45
- # @return [Symbol] an environment
46
- def self.environment
47
- env = :production
48
- env = ENV['PUPPET_HERALD_ENV'].to_sym unless ENV['PUPPET_HERALD_ENV'].nil?
49
- ENV['RACK_ENV'] = env.to_s
50
- env
51
- end
32
+ # Calculates a replative directory inside the project
33
+ #
34
+ # @param dir [String] a sub directory
35
+ # @return [String] a full path to replative dir
36
+ def relative_dir(dir)
37
+ File.realpath(File.join @root, dir)
38
+ end
52
39
 
53
- # Checks is running in DEVELOPMENT kind of environment (dev, ci, test)
54
- #
55
- # @return [Boolean] true if runs in development
56
- def self.in_dev?
57
- [:development, :dev, :test, :ci].include? environment
58
- end
40
+ def environment=(newenv)
41
+ envsymbol = newenv.to_s.to_sym
42
+ ENV['PUPPET_HERALD_ENV'] = envsymbol.to_s
43
+ rackenv
44
+ setup_logger
45
+ end
59
46
 
60
- # Checks is running in production environment
61
- #
62
- # @return [Boolean] true if runs in production
63
- def self.in_prod?
64
- !in_dev?
65
- end
47
+ # Setups logger's level
48
+ #
49
+ # @return [nil]
50
+ def setup_logger
51
+ logger.level = self.in_dev? ? Logger::DEBUG : Logger::INFO
52
+ errlogger.level = logger.level
53
+ nil
54
+ end
66
55
 
67
- # Reports a bug in desired format
68
- #
69
- # @param ex [Exception] an exception that was thrown
70
- # @return [Hash] a hash with info about bug to be displayed to user
71
- def self.bug(ex)
72
- file = Tempfile.new(['puppet-herald-bug', '.log'])
73
- filepath = file.path
74
- file.close
75
- file.unlink
76
- message = "v#{PuppetHerald::VERSION}-#{ex.class}: #{ex.message}"
77
- contents = message + "\n\n" + ex.backtrace.join("\n") + "\n"
78
- File.write(filepath, contents)
79
- bugo = {
80
- message: message,
81
- homepage: PuppetHerald::HOMEPAGE,
82
- bugfile: filepath,
83
- help: "Please report this bug to #{PuppetHerald::HOMEPAGE} by passing contents of bug file: #{filepath}"
84
- }
85
- bugo
56
+ # Gets the environment set for Herald
57
+ #
58
+ # @return [Symbol] an environment
59
+ def environment
60
+ ENV['PUPPET_HERALD_ENV'] = :production.to_s if ENV['PUPPET_HERALD_ENV'].nil?
61
+ ENV['PUPPET_HERALD_ENV'].to_sym
62
+ end
63
+
64
+ # Rack environment
65
+ #
66
+ # @return [Symbol] Rack environment
67
+ def rackenv
68
+ case environment
69
+ when :dev, :development
70
+ rackenv = :development
71
+ when :test, :ci
72
+ rackenv = :test
73
+ else
74
+ rackenv = :production
75
+ end
76
+ ENV['RACK_ENV'] = rackenv.to_s
77
+ rackenv
78
+ end
79
+
80
+ # Checks is running in DEVELOPMENT kind of environment (dev, ci, test)
81
+ #
82
+ # @return [Boolean] true if runs in development
83
+ def in_dev?
84
+ [:development, :dev, :test, :ci].include? environment
85
+ end
86
+
87
+ # Checks is running in production environment
88
+ #
89
+ # @return [Boolean] true if runs in production
90
+ def in_prod?
91
+ !in_dev?
92
+ end
93
+
94
+ # Reports a bug in desired format
95
+ #
96
+ # @param ex [Exception] an exception that was thrown
97
+ # @return [Hash] a hash with info about bug to be displayed to user
98
+ def bug(ex)
99
+ file = Tempfile.new(['puppet-herald-bug', '.log'])
100
+ filepath = file.path
101
+ file.close
102
+ file.unlink
103
+ message = "v#{PuppetHerald::VERSION}-#{ex.class}: #{ex.message}"
104
+ contents = message + "\n\n" + ex.backtrace.join("\n") + "\n"
105
+ File.write(filepath, contents)
106
+ bugo = {
107
+ message: message,
108
+ homepage: PuppetHerald::HOMEPAGE,
109
+ bugfile: filepath,
110
+ help: "Please report this bug to #{PuppetHerald::HOMEPAGE} by passing contents of bug file: #{filepath}"
111
+ }
112
+ bugo
113
+ end
86
114
  end
115
+ PuppetHerald.rackenv
116
+ PuppetHerald.setup_logger
87
117
  end