wrake 0.0.1

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 972f2f0bce0b17584a67e9ece00141d31a09d31f
4
+ data.tar.gz: 716bf8153e6be36a92ec7ed09484b8e2009d5ea0
5
+ SHA512:
6
+ metadata.gz: d7689966fb80e510f266543429b0da59e325ca1009675a18e016ca0a1c5df1468ad86c9cf2e59f30d15359618066bc4ef2692a03e32940c801dc21b7d3af84df
7
+ data.tar.gz: 10fcd32080b5094485f4fad3225590b2c00cbaf887736b177f4f6c09e175a3e37dcacd34e9316cd174b9e52a8e626b305b6b9e81eab05b7b25e2c1f5a403ca98
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,98 @@
1
+ # Wrake
2
+
3
+ A web partner of Rake. Runs wrake via web api.
4
+
5
+ [![Build Status](https://travis-ci.org/mjacobus/wrake.png?branch=master)](https://travis-ci.org/mjacobus/wrake)
6
+ [![Coverage Status](https://coveralls.io/repos/mjacobus/wrake/badge.png)](https://coveralls.io/r/mjacobus/wrake)
7
+ [![Code Climate](https://codeclimate.com/github/mjacobus/wrake.png)](https://codeclimate.com/github/mjacobus/wrake)
8
+ [![Dependency Status](https://gemnasium.com/mjacobus/wrake.png)](https://gemnasium.com/mjacobus/wrake)
9
+ [![Gem Version](https://badge.fury.io/rb/wrake.png)](http://badge.fury.io/rb/wrake)
10
+
11
+ ## But why?
12
+
13
+ When you run rake inside rails, you have to load the entire application. By running wrake,
14
+ rake will be callled via web API, through your aready loaded rails app.
15
+
16
+ ## Instalation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ gem 'wrake'
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+ $ rails g wrake:install
26
+
27
+ This will create the following files:
28
+
29
+ - ```config/wrake.yml``` - the configuration file is self explicative.
30
+ - ```config/initializers/wrake.rb``` - the configuration file is self explicative.
31
+
32
+ Also, you wil need to mount the engine:
33
+
34
+ ```ruby
35
+ # config/routes.rb
36
+
37
+ mount Wrake::Engine, at: 'wrake'
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ ### Using API
43
+ ```ruby
44
+ api = Wrake::Api.new(url: base_url, username: username, password: password)
45
+
46
+ # or to get the api with default configuration
47
+
48
+ api = Wrake.api
49
+
50
+ response = api.invoke_task('some:task', { args: 'a b c' })
51
+ # or
52
+ response = api.invoke_task('some:task', args: ['a', 'b', 'c'])
53
+
54
+ puts response.code, response.headers, response.body, response.message
55
+
56
+ ```
57
+
58
+ ### Using the CLI
59
+
60
+ ```bash
61
+ wrake cache:clean -c path/to/wrake.yml -e development
62
+
63
+ wrake mail:welcome new@user.com -c path/to/wrake.yml
64
+ ```
65
+
66
+ ### Password protecting the API
67
+
68
+ By default, the API is protected by Basic Auth. You could change the default behavior
69
+ by overwriting the wrake_authorization method:
70
+
71
+ ```ruby
72
+ class ApplicationController < ActionController::Base
73
+ def wrake_authorization
74
+ authenticate_or_request_with_http_basic do |username, password|
75
+ User.with_wrake_privileges.where(email: username, password: password).first!
76
+ end
77
+ end
78
+ end
79
+ ```
80
+
81
+
82
+ ## TODO
83
+
84
+ - [Next features](https://github.com/mjacobus/wrake/issues?labels=enhancement&page=1&state=open)
85
+
86
+ ## Authors
87
+
88
+ - [Marcelo Jacobus](https://github.com/mjacobus)
89
+
90
+ ## Contributing
91
+
92
+ 1. Fork it
93
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
94
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
95
+ 4. Push to the branch (`git push origin my-new-feature`)
96
+ 5. Create new Pull Request
97
+
98
+ ** Do not forget to write tests**
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Wrake'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ module Wrake
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,43 @@
1
+ require_dependency "wrake/application_controller"
2
+ require_relative "../../../spec/support/task_tester"
3
+
4
+ module Wrake
5
+ class TasksController < ApplicationController
6
+
7
+ before_filter :load_tasks
8
+ before_filter :wrake_authorization
9
+
10
+ def invoke
11
+ @task_name = task_name
12
+ @args = args
13
+ @return = Rake::Task[task_name].invoke(*args)
14
+ end
15
+
16
+ def wrake_authorization
17
+ config = Wrake.config
18
+
19
+ authenticate_or_request_with_http_basic do |username, password|
20
+ username == config.username && password == config.password
21
+ end
22
+ end
23
+
24
+ protected
25
+ def args
26
+ data = params[:args].presence || []
27
+
28
+ if data.is_a?(String)
29
+ data = data.split(' ')
30
+ end
31
+
32
+ data
33
+ end
34
+
35
+ def task_name
36
+ params[:task_name]
37
+ end
38
+
39
+ def load_tasks
40
+ Rails.application.load_tasks
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,4 @@
1
+ module Wrake
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Wrake</title>
5
+ <%= stylesheet_link_tag "wrake/application", media: "all" %>
6
+ <%= javascript_include_tag "wrake/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,5 @@
1
+ <h1><%= @task_name %></h1>
2
+ <h2>Arguments</h2>
3
+ <div><%= @args.join(' ') %></div>
4
+ <h2>Output</h2>
5
+ <pre><%= @output %></pre>
@@ -0,0 +1,3 @@
1
+ Wrake::Engine.routes.draw do
2
+ match '/tasks/:task_name' => 'tasks#invoke', via: [:get, :post]
3
+ end
@@ -0,0 +1,9 @@
1
+ Description:
2
+ Install config files
3
+
4
+ Example:
5
+ rails generate wrake:install
6
+
7
+ This will create:
8
+ config/initializers/wrake.rb
9
+ config/wrake.yml
@@ -0,0 +1,12 @@
1
+ class Wrake::InstallGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def copy_initializer
5
+ template "initializer.rb", "config/initializers/wrake.rb"
6
+ end
7
+
8
+ def copy_config_file
9
+ template "wrake.yml", "config/wrake.yml"
10
+ end
11
+
12
+ end
@@ -0,0 +1,3 @@
1
+ Wrake.configure do |config|
2
+ config.from_file Rails.root.join('config/wrake.yml')
3
+ end
@@ -0,0 +1,5 @@
1
+ test:
2
+ url: http://example.com
3
+ username: jondoe
4
+ password: secret
5
+
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :wrake do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,24 @@
1
+ require "wrake/engine" if defined?(Rails)
2
+ require "wrake/api"
3
+ require "wrake/configuration"
4
+ require "wrake/authorization/access_denied"
5
+
6
+ module Wrake
7
+
8
+ def self.config
9
+ @@config ||= Configuration.new
10
+ end
11
+
12
+ def self.configure(&block)
13
+ yield config
14
+ end
15
+
16
+ def self.api
17
+ @@api ||= Api.new(
18
+ url: config.url,
19
+ username: config.username,
20
+ password: config.password
21
+ )
22
+ end
23
+
24
+ end
@@ -0,0 +1,45 @@
1
+ require 'wrake/api/request'
2
+ require 'wrake/api/response'
3
+
4
+ module Wrake
5
+ class Api
6
+
7
+ def initialize(params = { })
8
+ @params = params
9
+ end
10
+
11
+ def url
12
+ @params.fetch(:url)
13
+ end
14
+
15
+ def invoke_task(task, data = {})
16
+ perform_request(url_for("tasks/#{task}"), data)
17
+ end
18
+
19
+ def prepare_data(data)
20
+ { query: data, basic_auth: { username: username, password: password } }
21
+ end
22
+
23
+ private
24
+
25
+ def perform_request(path, data)
26
+ Request.new(path, prepare_data(data)).perform
27
+ end
28
+
29
+ def url_for(path = '/')
30
+ "#{url}/#{path}"
31
+ end
32
+
33
+ def params
34
+ @params
35
+ end
36
+
37
+ def username
38
+ params[:username]
39
+ end
40
+
41
+ def password
42
+ params[:password]
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,20 @@
1
+ require 'httparty'
2
+
3
+ module Wrake
4
+ class Api
5
+ class Request
6
+
7
+ attr_reader :url, :data
8
+
9
+ def initialize(url, data = {})
10
+ @url = url
11
+ @data = data
12
+ end
13
+
14
+ def perform
15
+ Response.new(HTTParty.post(url, data))
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ module Wrake
2
+ class Api
3
+ class Response
4
+
5
+ def initialize(response)
6
+ @response = response
7
+ end
8
+
9
+ def body
10
+ @response.body
11
+ end
12
+
13
+ def code
14
+ @response.code
15
+ end
16
+
17
+ def message
18
+ @response.message
19
+ end
20
+
21
+ def headers
22
+ @response.headers
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,6 @@
1
+ module Wrake
2
+ module Authorization
3
+ class AccessDenied < StandardError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,14 @@
1
+ module Wrake
2
+ class Command
3
+ attr_reader :options
4
+
5
+ def initialize(options)
6
+ @options = options
7
+ Wrake.config.from_file(options.config_file, options.env)
8
+ end
9
+
10
+ def execute
11
+ Wrake.api.invoke_task(options.task_name, args: options.task_args)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,60 @@
1
+ require 'optparse'
2
+
3
+ module Wrake
4
+ class Command
5
+ class Options
6
+ class Error < StandardError; end
7
+
8
+ attr_reader :config_file, :env, :task_args, :task_name
9
+
10
+ def initialize(options = [])
11
+ @env = 'production'
12
+ parse(options)
13
+ end
14
+
15
+ private
16
+ def parse(options)
17
+ @parser = OptionParser.new do |opts|
18
+ opts.banner = "Usage: wrake task_name [params] [options]"
19
+ parse_config_file(opts)
20
+ parse_environment(opts)
21
+
22
+ opts.on_tail("-h", "--help", "Show this message") do
23
+ puts opts
24
+ exit
25
+ end
26
+ end
27
+
28
+ @parser.parse!(options)
29
+ parse_task_name(options)
30
+ parse_task_args(options)
31
+ rescue OptionParser::InvalidOption => e
32
+ raise_error(e.message)
33
+ end
34
+
35
+ def raise_error(message)
36
+ raise Error, message + "\n\n#{@parser}"
37
+ end
38
+
39
+ def parse_task_name(options)
40
+ @task_name = options.shift
41
+ end
42
+
43
+ def parse_task_args(options)
44
+ @task_args = options
45
+ end
46
+
47
+ def parse_config_file(opts)
48
+ opts.on('-c', '--config-file CONFIG_FILE', "Set the config file to read from.") do |file|
49
+ @config_file = file
50
+ end
51
+ end
52
+
53
+ def parse_environment(opts)
54
+ opts.on('-e', '--env ', "Set the environment. Defaults to 'production'") do |file|
55
+ @env = file
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,14 @@
1
+ module Wrake
2
+ class Configuration
3
+ attr_accessor :username, :password, :url
4
+
5
+ def from_file(file, env = nil)
6
+ env ||= defined?(Rails) ? Rails.env : 'production'
7
+ config = YAML::load(File.open(file))[env]
8
+
9
+ config.each do |key, value|
10
+ send("#{key}=", value)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ module Wrake
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Wrake
4
+
5
+ config.generators do |g|
6
+ g.test_framework :rspec
7
+ g.integration_tool :rspec
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Wrake
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wrake
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marcelo Jacobus
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ - - <=
21
+ - !ruby/object:Gem::Version
22
+ version: 5.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ - - <=
31
+ - !ruby/object:Gem::Version
32
+ version: 5.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: httparty
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec-rails
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: simplecov
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: coveralls
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: fakeweb
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ description: Runs rake without having to load the entire rais app
104
+ email:
105
+ - marcelo.jacobus@gmail.com
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - MIT-LICENSE
111
+ - README.md
112
+ - Rakefile
113
+ - app/assets/stylesheets/wrake/application.css
114
+ - app/controllers/wrake/application_controller.rb
115
+ - app/controllers/wrake/tasks_controller.rb
116
+ - app/helpers/wrake/application_helper.rb
117
+ - app/views/layouts/wrake/application.html.erb
118
+ - app/views/wrake/tasks/invoke.html.erb
119
+ - config/routes.rb
120
+ - lib/generators/wrake/install/USAGE
121
+ - lib/generators/wrake/install/install_generator.rb
122
+ - lib/generators/wrake/install/templates/initializer.rb
123
+ - lib/generators/wrake/install/templates/wrake.yml
124
+ - lib/tasks/wrake_tasks.rake
125
+ - lib/wrake.rb
126
+ - lib/wrake/api.rb
127
+ - lib/wrake/api/request.rb
128
+ - lib/wrake/api/response.rb
129
+ - lib/wrake/authorization/access_denied.rb
130
+ - lib/wrake/command.rb
131
+ - lib/wrake/command/options.rb
132
+ - lib/wrake/configuration.rb
133
+ - lib/wrake/engine.rb
134
+ - lib/wrake/version.rb
135
+ homepage: http://github.com/mjacobus/wrake
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.2.1
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Web Api for Rake
159
+ test_files: []