fig_rake 0.9.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2b3c1fbb3cd0b20b7905f493dccc383d103d5583
4
+ data.tar.gz: 39c3c3dac9d95db2f0e56fabd11cc773f7951349
5
+ SHA512:
6
+ metadata.gz: e0f127fcf4bff09d5c5547ea14b2f9cada69656d8870538169443176327c984df96fa47750f44c354b63644618880c4b6c1e56153174fc203d295efd7985d78d
7
+ data.tar.gz: 8f54c28ce8c9a36ec284eb48ce9cf6ec0bf4c037c1d0c167a4417218614582879f48579be4ec296254bad9a1725ddd3a122a035febc3fe8cab2d136261a793a4
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fig_rake.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Edward Paget
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # FigRake
2
+
3
+ Allows you to use rake and rails commands transparently with a dev environment set up using [fig](http://fig.sh).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fig_rake', require: false
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fig_rake
18
+
19
+ ## Usage
20
+
21
+ Fig Rake offers two ways to use it: the `frake` and `frails` commands and by monkey-patching Rake and the Rails command line.
22
+
23
+ ### frake
24
+
25
+ `frake` and `frails` are probably the easiest and least dangerous (and ulitmately least satisifying) ways to use FigRake. Simply execute `frake` or `frails` followed by rake or rails commads as you would normally use rake or the rails command line, ie `rake db:migrate`, `frake spec`, `frails console`. FigRake will automatically determine which container to run the commands on by looking for the one with a `build: .` in your `fig.yml` file.
26
+
27
+ You can configure the container fig_rake is run on by passing its name as to the `--container-name` argument, by setting a `FRAKE_DEFAULT` environment variable, or by adding its name to a `.frake` file in the project's root directory.
28
+
29
+ For more information type `frake --help` or `frails --help`
30
+
31
+ ### Monkey Patching
32
+
33
+ I don't think there's anything wrong with monkey patching, so let's do it.
34
+
35
+ Just add `require 'fig_rake/rake'` to your Rakefile or `require 'fig_rake/rails'` and frake will automatically intercept your rake and rails commands and run them against its default container. The default container will be determined in the same manner as the `frake` command. You can optionally call `FigRake::Rake.default_container "name"` in your Rakefile or `FigRake::Rails.default_container "name"` in your config/application.rb to set the default container name there.
36
+
37
+ If you need to run rake commands locally after installing FigRake, add `FIG_RAKE=off` to the end of your rake command or as a shell environment variable to disable FigRake for that command.
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it ( https://github.com/edpaget/fig_rake/fork )
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/frails ADDED
@@ -0,0 +1,9 @@
1
+ #! /usr/bin/env ruby
2
+ #-* mode: ruby *-
3
+
4
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
5
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
6
+
7
+ require 'fig_rake/cli'
8
+
9
+ FigRake::Cli.new(:rails, ARGV).exec
data/bin/frake ADDED
@@ -0,0 +1,9 @@
1
+ #! /usr/bin/env ruby
2
+ #-* mode: ruby *-
3
+
4
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
5
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
6
+
7
+ require 'fig_rake/cli'
8
+
9
+ FigRake::Cli.new(:rake, ARGV).exec
data/fig_rake.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fig_rake/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fig_rake"
8
+ spec.version = FigRake::VERSION
9
+ spec.authors = ["Edward Paget"]
10
+ spec.email = ["edward@cassetteta.pe"]
11
+ spec.summary = %q{Utilities to make using Rake with a fig dev environment easier}
12
+ spec.description = %q{It kinda just does that see the README}
13
+ spec.homepage = "https://github.com/edpaget/fig_rake"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,42 @@
1
+ require 'optparse'
2
+ require 'fig_rake/configuration'
3
+ require 'fig_rake/command'
4
+
5
+ module FigRake
6
+ class Cli
7
+ def initialize(command, arguments)
8
+ @options = Configuration.new
9
+ parse_arguments(command, arguments)
10
+ @command = Command.new(command, @options.container_name, @options.rake_args)
11
+ end
12
+
13
+ def exec
14
+ @command.exec
15
+ end
16
+
17
+ private
18
+
19
+ def parse_arguments(command, args)
20
+ OptionParser.new do |opts|
21
+ opts.banner = "Usage: f#{command} [options] [arguments]"
22
+
23
+ opts.on('-c', '--container-name [NAME]', String,
24
+ "Name of Container to exec rake in") do |name|
25
+ @options.container_name = name
26
+ end
27
+
28
+ opts.on('-h', '--help', "Show this message") do
29
+ puts opts
30
+ exit
31
+ end
32
+
33
+ opts.on('-v', '--version', 'Show Version') do
34
+ puts VERSION
35
+ exit
36
+ end
37
+ end.parse!(args)
38
+
39
+ @options.rake_args = args
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,14 @@
1
+ module FigRake
2
+ class Command
3
+ attr_accessor :container_name, :rake_args, :command
4
+
5
+ def initialize(command, container_name, rake_args)
6
+ @command, @container_name, @rake_args = command, container_name, rake_args
7
+ end
8
+
9
+ def exec
10
+ p "fig run --rm --entrypoint=#{command} #{container_name} #{rake_args.join(' ')}"
11
+ exit system("fig run --rm --entrypoint=#{command} #{container_name} #{rake_args.join(' ')}")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,36 @@
1
+ require 'yaml'
2
+
3
+ module FigRake
4
+ class Configuration
5
+ attr_accessor :container_name, :rake_args
6
+
7
+ def initialize(name=nil)
8
+ @container_name = name ||= name_from_defaults
9
+ end
10
+
11
+ def name_from_defaults
12
+ name_from_environment ||
13
+ name_from_frake_configuration ||
14
+ name_from_fig
15
+ end
16
+
17
+ def name_from_environment
18
+ ENV['FRAKE_DEFAULT']
19
+ end
20
+
21
+ def name_from_frake_configuration
22
+ File.read('.frake')
23
+ rescue Errno::ENOENT
24
+ nil
25
+ end
26
+
27
+ def name_from_fig
28
+ container_config = YAML.load(File.read('fig.yml')).to_a.select do |(_, opts)|
29
+ opts.has_key?("build")
30
+ end
31
+ container_config.first.first
32
+ rescue Errno::ENOENT
33
+ nil
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,11 @@
1
+ require 'fig_rake/configuration'
2
+ require 'fig_rake/command'
3
+
4
+ module FigRake
5
+ module Mixin
6
+ def run_in_fig(args)
7
+ configuration = Configuration.new(default_name)
8
+ Command.new(command, configuration.container_name, args).exec
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,39 @@
1
+ require 'rails/commands/commands_tasks'
2
+ require 'fig_rake/mixin'
3
+
4
+ module FigRake
5
+ module Rails
6
+ include FigRake::Mixin
7
+
8
+ def self.default_container(name=nil)
9
+ return @name unless name
10
+ @name = name
11
+ end
12
+
13
+ def default_name
14
+ FigRake::Rails.default_container
15
+ end
16
+
17
+ def command
18
+ :rails
19
+ end
20
+ end
21
+ end
22
+
23
+ module Rails
24
+ class CommandsTasks
25
+ include FigRake::Rails
26
+
27
+ %i(console server dbconsole runner).each do |method|
28
+ m = self.instance_method(method)
29
+
30
+ define_method method do
31
+ if ENV['FIG_RAKE'] == 'off'
32
+ m.bind(self).call
33
+ else
34
+ run_in_fig(argv.unshift(method))
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,37 @@
1
+ require 'rake/application'
2
+ require 'fig_rake/mixin'
3
+
4
+ module FigRake
5
+ module Rake
6
+ include FigRake::Mixin
7
+
8
+ def self.default_container(name=nil)
9
+ return @name unless name
10
+ @name = name
11
+ end
12
+
13
+ def default_name
14
+ FigRake::Rails.default_container
15
+ end
16
+
17
+ def command
18
+ :rake
19
+ end
20
+ end
21
+ end
22
+
23
+ module Rake
24
+ class Application
25
+ include FigRake::Rake
26
+
27
+ tl = self.instance_method(:top_level)
28
+
29
+ define_method :top_level do
30
+ if ENV['FIG_RAKE'] == 'off'
31
+ tl.bind(self).call
32
+ else
33
+ run_in_fig(ARGV)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module FigRake
2
+ VERSION = "0.9.0"
3
+ end
data/lib/fig_rake.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "fig_rake/version"
2
+
3
+ module FigRake
4
+ # Your code goes here...
5
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fig_rake
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Edward Paget
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: It kinda just does that see the README
42
+ email:
43
+ - edward@cassetteta.pe
44
+ executables:
45
+ - frails
46
+ - frake
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/frails
56
+ - bin/frake
57
+ - fig_rake.gemspec
58
+ - lib/fig_rake.rb
59
+ - lib/fig_rake/cli.rb
60
+ - lib/fig_rake/command.rb
61
+ - lib/fig_rake/configuration.rb
62
+ - lib/fig_rake/mixin.rb
63
+ - lib/fig_rake/rails.rb
64
+ - lib/fig_rake/rake.rb
65
+ - lib/fig_rake/version.rb
66
+ homepage: https://github.com/edpaget/fig_rake
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.2.2
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Utilities to make using Rake with a fig dev environment easier
90
+ test_files: []