agape-red-recipes 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Agape::Red::Recipes
1
+ # Agape Red Recipes
2
2
 
3
- TODO: Write a gem description
3
+ This gem will allow you to run various recipes in your rails apps.
4
4
 
5
5
  ## Installation
6
6
 
@@ -12,13 +12,13 @@ And then execute:
12
12
 
13
13
  $ bundle
14
14
 
15
- Or install it yourself as:
15
+ ## Usage
16
16
 
17
- $ gem install agape-red-recipes
17
+ Once the gem is installed you can install recipes by running
18
18
 
19
- ## Usage
19
+ rails g recipe recipe_name
20
20
 
21
- TODO: Write usage instructions here
21
+ `recipe_name` can be the name of any repo under the organization AgapeRedRecipes.
22
22
 
23
23
  ## Contributing
24
24
 
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "agape-red-recipes"
8
8
  spec.version = AgapeRedRecipes::VERSION
9
9
  spec.authors = ["David Kerber"]
10
- spec.email = ["dave@agape-red-recipes.com"]
10
+ spec.email = ["dave@agapered.com"]
11
11
  spec.description = %q{Allows you to run various recipes against your rails apps. }
12
12
  spec.summary = %q{Automates installing various add ons and plugins for your app.}
13
13
  spec.homepage = ""
@@ -0,0 +1,12 @@
1
+ module AgapeRedRecipes
2
+ module Bundler
3
+ # Generic bundle command
4
+ # Defaults to "install"
5
+ def bundle(command = nil)
6
+ command ||= "install"
7
+ ::Bundler.with_clean_env do
8
+ run "bundle #{command}"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,80 @@
1
+ module AgapeRedRecipes
2
+ module Gemfile
3
+ def gem_group_exists?(*names)
4
+ name = names.map(&:inspect).join(", ")
5
+
6
+ File.open("Gemfile") do |file|
7
+ file.read.include? "\ngroup #{name} do"
8
+ end
9
+ end
10
+
11
+ def gem_group(*names, &block)
12
+ name = names.map(&:inspect).join(", ")
13
+
14
+ if gem_group_exists?(*names)
15
+ @in_group = true
16
+ @current_group = name
17
+ instance_eval(&block)
18
+ @current_group = nil
19
+ @in_group = false
20
+ else
21
+ super(*names, &block)
22
+ end
23
+ end
24
+
25
+ def gem(*args)
26
+ options = args.extract_options!
27
+ name, version = args
28
+
29
+ # Set the message to be shown in logs. Uses the git repo if one is given,
30
+ # otherwise use name (version).
31
+ parts, message = [ name.inspect ], name
32
+ if version ||= options.delete(:version)
33
+ parts << version.inspect
34
+ message << " (#{version})"
35
+ end
36
+ message = options[:git] if options[:git]
37
+
38
+ log :gemfile, message
39
+
40
+ options.each do |option, value|
41
+ parts << "#{option}: #{value.inspect}"
42
+ end
43
+
44
+ @@installed_gem_names ||= Gem::Specification.map &:name
45
+ return if @@installed_gem_names.include? name
46
+
47
+ in_root do
48
+ str = "gem#{parts.join(", ")}"
49
+ str = " " + str if @in_group
50
+ str = "\n" + str
51
+
52
+ if @current_group
53
+ insert_at_end_of_line_containing 'Gemfile', str, "group #{@current_group} do"
54
+ else
55
+ append_file 'Gemfile', str, verbose: false
56
+ end
57
+
58
+ end
59
+ end
60
+
61
+ def insert_at_end_of_line_containing(file_name, insert, contents)
62
+ open(file_name, 'r+') do |file|
63
+
64
+ while !file.eof?
65
+ break if file.readline.include? contents
66
+ end
67
+
68
+ # Move back to the end of the previous line
69
+ file.seek file.pos - 1
70
+
71
+ position = file.pos
72
+ rest_of_file = file.read
73
+ file.seek position
74
+
75
+ file.write insert
76
+ file.write rest_of_file
77
+ end
78
+ end
79
+ end
80
+ end
@@ -1,3 +1,3 @@
1
1
  module AgapeRedRecipes
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,14 +1,37 @@
1
+ require 'agape-red-recipes/modules/bundler'
2
+ require 'agape-red-recipes/modules/gemfile'
3
+
1
4
  class RecipeGenerator < Rails::Generators::Base
5
+ include AgapeRedRecipes::Bundler
6
+ include AgapeRedRecipes::Gemfile
2
7
 
3
8
  argument :recipe_name, type: :string, default: 'list'
4
9
 
5
10
  def generate_recipe
6
-
7
- apply_recipe recipe_name
11
+ if recipe_name == 'list'
12
+ list_repos
13
+ else
14
+ apply_recipe recipe_name
15
+ end
8
16
  end
9
17
 
10
18
  private
19
+ def list_repos
20
+ require 'net/http'
21
+ require 'uri'
22
+
23
+ def open(url)
24
+ Net::HTTP.get(URI.parse(url))
25
+ end
26
+
27
+ page_content = JSON.parse(open('https://api.github.com/users/AgapeRedRecipes/repos'))
28
+ repos = page_content.map{|repo| repo['name']}.select{|repo| repo != 'agape-red-recipes'}
29
+ puts "You can apply the following recipes using `rails g recipe [recipe_name]`"
30
+ repos.each{|r| puts " #{r.downcase}" }
31
+ end
32
+
11
33
  def apply_recipe the_recipe
12
34
  apply "https://raw.github.com/AgapeRedRecipes/#{the_recipe}/master/recipe.rb"
13
35
  end
36
+
14
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agape-red-recipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -45,7 +45,7 @@ dependencies:
45
45
  version: '0'
46
46
  description: ! 'Allows you to run various recipes against your rails apps. '
47
47
  email:
48
- - dave@agape-red-recipes.com
48
+ - dave@agapered.com
49
49
  executables: []
50
50
  extensions: []
51
51
  extra_rdoc_files: []
@@ -56,6 +56,8 @@ files:
56
56
  - README.md
57
57
  - Rakefile
58
58
  - agape-red-recipes.gemspec
59
+ - lib/agape-red-recipes/modules/bundler.rb
60
+ - lib/agape-red-recipes/modules/gemfile.rb
59
61
  - lib/agape-red-recipes/recipes.rb
60
62
  - lib/agape-red-recipes/version.rb
61
63
  - lib/generators/recipe_generator.rb