quandl_utility 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ # Disable encoding requirement
2
+ Encoding:
3
+ Enabled: false
4
+ # Don't force aligment for thor method listing.
5
+ AlignParameters:
6
+ Enabled: true
7
+ Exclude:
8
+ - lib/quandl/utility/thor_tasks/*
9
+ LineLength:
10
+ Max: 100
11
+ MethodLength:
12
+ Max: 20
data/README.md CHANGED
@@ -44,3 +44,84 @@ rake gem_name:bump:patch # Perform patch bump to gem_name
44
44
  $ rake gem_name:bump:minor && rake release
45
45
  ```
46
46
 
47
+ ## Thor Tasks
48
+
49
+ Quandl::Utility Thor tasks are available in two ways:
50
+
51
+ * Using the executable 'qutil'
52
+
53
+ ```bash
54
+ qutil notify slack 'general' 'ping!'
55
+ ```
56
+
57
+ * Including in your Thorfile
58
+
59
+ ```ruby
60
+ require 'quandl/utility/thor_tasks'
61
+
62
+ desc 'my_task'
63
+ def my_task
64
+ invoke 'qutil:slack:notify', ['general', 'ping!']
65
+ end
66
+ ```
67
+
68
+ ### Lint
69
+
70
+ Linting tasks. Currently supports Rubocop and Foodcritic for linting Ruby projects and Chef cookbooks.
71
+
72
+ ```bash
73
+ qutil lint help
74
+ ```
75
+
76
+ #### ruby
77
+
78
+ Run Rubocop linting on project.
79
+
80
+ ```bash
81
+ qutil lint ruby
82
+ ```
83
+
84
+ #### init_ruby
85
+
86
+ Initialize Rubocop linting on project. Create two files: an organization base YAML config of linting rules, and an empty project YAML config
87
+ that inherits from the organization config.
88
+
89
+ ```bash
90
+ qutil lint init_ruby
91
+ ```
92
+
93
+ #### cookbook
94
+
95
+ ```bash
96
+ qutil lint cookbook
97
+ ```
98
+
99
+ ### CI
100
+
101
+ Task for the Continuous Integration server.
102
+
103
+ ```bash
104
+ qutil ci help
105
+ ```
106
+
107
+ #### notify_slack
108
+
109
+ Notify slack of build status. Uses various tddium ENV variables to build a message that is sent to slack.
110
+
111
+ ```bash
112
+ qutil ci notify_slack
113
+ ```
114
+
115
+ ### Notify
116
+
117
+ Task for notifications. Currently supports sending messages to Slack.
118
+
119
+ ```bash
120
+ qutil notify help
121
+ ```
122
+
123
+ #### slack
124
+
125
+ ```bash
126
+ qutil notify slack MESSAGE CHANNEL
127
+ ```
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ RSpec::Core::RakeTask.new(:spec) do |task|
14
14
  end
15
15
 
16
16
  Quandl::Utility::Tasks.configure do |c|
17
- c.name = 'quandl_utility'
17
+ c.name = 'quandl'
18
18
  c.tag_prefix = 'v'
19
19
  c.version_path = File.join( Quandl::Utility.root_path, 'VERSION' )
20
20
  c.changelog_path = File.join( Quandl::Utility.root_path, 'UPGRADE.md' )
@@ -0,0 +1,6 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+
3
+ require 'bundler'
4
+ require 'thor'
5
+ require 'thor/rake_compat'
6
+ require 'quandl/utility/thor_tasks'
data/UPGRADE.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.1.2
2
+
3
+
4
+
5
+
6
+
1
7
  ## 0.1.1
2
8
 
3
9
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
4
+ require 'quandl/utility/cli'
5
+ Quandl::Utility::CLI.start
@@ -1,11 +1,11 @@
1
- require "quandl/utility/version"
2
- require "quandl/utility/configuration"
3
- require "quandl/utility/tasks"
1
+ require 'quandl/utility/version'
2
+ require 'quandl/utility/configuration'
3
+ require 'quandl/utility/tasks'
4
4
 
5
5
  module Quandl
6
- module Utility
7
- def self.root_path
8
- @root_path ||= File.expand_path(File.join(File.dirname(__FILE__), '../../'))
6
+ module Utility
7
+ def self.root_path
8
+ @root_path ||= File.expand_path(File.join(File.dirname(__FILE__), '../../'))
9
+ end
9
10
  end
10
11
  end
11
- end
@@ -0,0 +1,22 @@
1
+ require 'thor'
2
+ require 'quandl/utility/thor_tasks/lint'
3
+ require 'quandl/utility/thor_tasks/notify'
4
+ require 'quandl/utility/thor_tasks/ci'
5
+
6
+ module Quandl
7
+ module Utility
8
+ # Quand Utility Command Line
9
+ class CLI < Thor
10
+ namespace 'qutil'
11
+
12
+ desc 'lint', 'Linting subcommands'
13
+ subcommand 'lint', Quandl::Utility::ThorTasks::Lint
14
+
15
+ desc 'notify', 'Notification subcommands'
16
+ subcommand 'notify', Quandl::Utility::ThorTasks::Notify
17
+
18
+ desc 'ci', 'CI Server subcommands'
19
+ subcommand 'ci', Quandl::Utility::ThorTasks::CI
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ require_relative 'thor_tasks/lint'
2
+ require_relative 'thor_tasks/notify'
3
+ require_relative 'thor_tasks/ci'
@@ -0,0 +1,95 @@
1
+ require 'thor'
2
+
3
+ module Quandl
4
+ module Utility
5
+ module ThorTasks
6
+ # Tasks to run on CI Server
7
+ class CI < Thor
8
+ namespace 'qutil:ci'
9
+
10
+ desc 'notify_slack', 'Notify Quandl of build status of CI'
11
+ def notify_slack
12
+ invoke 'qutil:notify:slack',
13
+ [ci_build_message, slack_channel],
14
+ emoji: slack_emoji
15
+ end
16
+
17
+ private
18
+
19
+ # Generate a message for the CI build that will be sent to Quandl
20
+ #
21
+ # Returns string
22
+ def ci_build_message
23
+ "#{current_project} (#{git_branch}) *#{tddium_build_status}* - #{tddium_report_url}"
24
+ end
25
+
26
+ # Which slack channel to send build status to.
27
+ # Defaults to 'development', but it can be overriden in tddium.yml
28
+ #
29
+ # Returns string
30
+ def slack_channel
31
+ ENV.fetch('SLACK_CHANNEL', 'development')
32
+ end
33
+
34
+ # The URL for the build that just ran
35
+ #
36
+ # Returns string
37
+ def tddium_report_url
38
+ "https://#{tddium_api_server}/1/reports/#{tddium_session_id}"
39
+ end
40
+
41
+ def tddium_build_status
42
+ ENV['TDDIUM_BUILD_STATUS']
43
+ end
44
+
45
+ def tddium_api_server
46
+ ENV['TDDIUM_API_SERVER']
47
+ end
48
+
49
+ def tddium_session_id
50
+ ENV['TDDIUM_SESSION_ID']
51
+ end
52
+
53
+ def current_project
54
+ ENV['QUANDL_PROJECT']
55
+ end
56
+
57
+ def git_branch
58
+ @git_branch ||= `git branch`.chomp.gsub(/\*/, '').strip
59
+ end
60
+
61
+ # Use tddium environment variables to determine status of build
62
+ #
63
+ # Returns boolean
64
+ def failed?
65
+ ENV['TDDIUM_BUILD_STATUS'] == 'failed'
66
+ end
67
+
68
+ # Use different emojis for build statuses.
69
+ #
70
+ # Returns string
71
+ def slack_emoji
72
+ failed? ? fail_emoji : pass_emoji
73
+ end
74
+
75
+ # Return the emoji to use for a failed build
76
+ # Can be overriden with environment variables in tddium.yml.
77
+ # Default is :scream_cat:
78
+ #
79
+ # Returns string
80
+ def fail_emoji
81
+ ENV.fetch('SLACK_FAIL_EMOJI', ':scream_cat:')
82
+ end
83
+
84
+ # Return the emoji to use for a successful build
85
+ # Can be overriden with environment variables in tddium.yml.
86
+ # Default is :thumbsup:
87
+ #
88
+ # Returns string
89
+ def pass_emoji
90
+ ENV.fetch('SLACK_PASS_EMOJI', ':thumbsup:')
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,60 @@
1
+ require 'rubocop'
2
+ require 'thor'
3
+ require 'thor/foodcritic'
4
+
5
+ module Quandl
6
+ module Utility
7
+ module ThorTasks
8
+ # Linting Tasks
9
+ class Lint < Thor
10
+ namespace 'qutil:lint'
11
+ include Thor::Actions
12
+
13
+ def self.source_root
14
+ File.expand_path('../../../../../support/templates', __FILE__)
15
+ end
16
+
17
+ desc 'cookbook', 'stuff'
18
+ def cookbook
19
+ invoke 'foodcritic:lint'
20
+ end
21
+
22
+ method_option :paths,
23
+ type: :array,
24
+ default: %w( . ),
25
+ required: true,
26
+ aliases: '-p'
27
+ desc 'ruby', 'Lint project for Ruby style with Rubocop'
28
+ def ruby
29
+ result = Rubocop::CLI.new.run(options[:paths])
30
+ if result == 0
31
+ say('No Rubocop warnings', :green)
32
+ else
33
+ exit(result)
34
+ end
35
+ end
36
+
37
+ method_option :default_directory,
38
+ type: :string,
39
+ default: '.quandl.rubocop',
40
+ aliases: '-d',
41
+ required: true,
42
+ banner: 'DIRECTORY'
43
+ desc 'init_ruby', 'Start Rubocop linting for project'
44
+ def init_ruby
45
+ return unless yes?('Do you want to setup Rubocop linting?', :yellow)
46
+ # Get directory and file for base rubocop
47
+ dir = options[:default_directory]
48
+ file_path = File.join(dir, '.rubocop.yml')
49
+ # Create empty directory if it does not exist
50
+ empty_directory(dir)
51
+ # Create base rubocop with common rules. Let Thor handle conflicts.
52
+ template('quandl.rubocop.yml', file_path)
53
+ # Create project template. Let Thor handle conflicts
54
+ @base_directory = dir
55
+ template('project.rubocop.yml.erb', '.rubocop.yml')
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,43 @@
1
+ require 'slack-notifier'
2
+
3
+ module Quandl
4
+ module Utility
5
+ module ThorTasks
6
+ # Tasks for sending notifications
7
+ class Notify < Thor
8
+ namespace 'qutil:notify'
9
+
10
+ method_option :emoji,
11
+ type: :string,
12
+ aliases: '-e',
13
+ required: false,
14
+ banner: 'EMOJI'
15
+ method_option :token,
16
+ type: :string,
17
+ aliases: '-t',
18
+ required: true,
19
+ default: ENV['SLACK_TOKEN'],
20
+ banner: 'TOKEN'
21
+ method_option :team,
22
+ type: :string,
23
+ aliases: '-m',
24
+ required: true,
25
+ default: 'quandl',
26
+ banner: 'TEAM'
27
+ method_option :botname,
28
+ type: :string,
29
+ aliases: '-b',
30
+ required: false,
31
+ default: ENV['SLACK_BOTNAME'],
32
+ banner: 'BOTNAME'
33
+ desc 'slack message channel', 'Send notification to slack'
34
+ def slack(message, channel)
35
+ slack_client = Slack::Notifier.new(options[:team], options[:token])
36
+ slack_client.channel = channel
37
+ slack_client.username = options[:botname]
38
+ slack_client.ping(message, icon_emoji: options[:emoji])
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,5 +1,5 @@
1
1
  module Quandl
2
- module Utility
3
- VERSION = File.read(File.expand_path(File.join(File.dirname(__FILE__), '../../../VERSION'))).strip.rstrip
2
+ module Utility
3
+ VERSION = File.read(File.expand_path(File.join(File.dirname(__FILE__), '../../../VERSION'))).strip.rstrip
4
+ end
4
5
  end
5
- end
@@ -16,10 +16,14 @@ Gem::Specification.new do |s|
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib", 'tasks']
19
-
19
+
20
20
  s.add_runtime_dependency "activesupport", ">= 3.0.0"
21
21
  s.add_runtime_dependency "rake"
22
-
22
+ s.add_runtime_dependency 'thor'
23
+ s.add_runtime_dependency 'thor-foodcritic'
24
+ s.add_runtime_dependency 'rubocop'
25
+ s.add_runtime_dependency 'slack-notifier'
26
+
23
27
  s.add_development_dependency "rspec", "~> 2.13"
24
28
  s.add_development_dependency "fivemat", "~> 1.2"
25
29
  s.add_development_dependency "pry"
@@ -0,0 +1,4 @@
1
+ inherit_from: <%= @base_directory %>/.rubocop.yml
2
+
3
+ # Genereated automatically by Quandl::Utility at <%= Time.now %>
4
+ # Project specific rules go here...
@@ -0,0 +1,12 @@
1
+ AllCops:
2
+ Exclude:
3
+ - db/**
4
+ - config/boot.rb
5
+ - !ruby/regexp /rgloader/
6
+ - !ruby/regexp /.*tddium.*\.rb$/
7
+ Encoding:
8
+ Enabled: false
9
+ LineLength:
10
+ Max: 100
11
+ MethodLength:
12
+ Max: 20
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quandl_utility
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-10 00:00:00.000000000 Z
12
+ date: 2014-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -43,6 +43,70 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: thor
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: thor-foodcritic
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rubocop
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: slack-notifier
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
46
110
  - !ruby/object:Gem::Dependency
47
111
  name: rspec
48
112
  requirement: !ruby/object:Gem::Requirement
@@ -142,24 +206,35 @@ dependencies:
142
206
  description: Tools for making our lives easier.
143
207
  email:
144
208
  - blake@hilscher.ca
145
- executables: []
209
+ executables:
210
+ - qutil
146
211
  extensions: []
147
212
  extra_rdoc_files: []
148
213
  files:
149
214
  - .gitignore
215
+ - .rubocop.yml
150
216
  - Gemfile
151
217
  - LICENSE
152
218
  - README.md
153
219
  - Rakefile
220
+ - Thorfile
154
221
  - UPGRADE.md
155
222
  - VERSION
223
+ - bin/qutil
156
224
  - lib/quandl/utility.rb
225
+ - lib/quandl/utility/cli.rb
157
226
  - lib/quandl/utility/configuration.rb
158
227
  - lib/quandl/utility/rake_tasks.rb
159
228
  - lib/quandl/utility/tasks.rb
229
+ - lib/quandl/utility/thor_tasks.rb
230
+ - lib/quandl/utility/thor_tasks/ci.rb
231
+ - lib/quandl/utility/thor_tasks/lint.rb
232
+ - lib/quandl/utility/thor_tasks/notify.rb
160
233
  - lib/quandl/utility/version.rb
161
234
  - quandl_utility.gemspec
162
235
  - spec/spec_helper.rb
236
+ - support/templates/project.rubocop.yml.erb
237
+ - support/templates/quandl.rubocop.yml
163
238
  - tasks/utility.rake
164
239
  homepage: http://blake.hilscher.ca/
165
240
  licenses:
@@ -175,12 +250,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
175
250
  - - ! '>='
176
251
  - !ruby/object:Gem::Version
177
252
  version: '0'
253
+ segments:
254
+ - 0
255
+ hash: 2688062014087562059
178
256
  required_rubygems_version: !ruby/object:Gem::Requirement
179
257
  none: false
180
258
  requirements:
181
259
  - - ! '>='
182
260
  - !ruby/object:Gem::Version
183
261
  version: '0'
262
+ segments:
263
+ - 0
264
+ hash: 2688062014087562059
184
265
  requirements: []
185
266
  rubyforge_project:
186
267
  rubygems_version: 1.8.23