rails-new 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2419251bc8c4e86dbda404f654170dd0644a3be7
4
- data.tar.gz: 7aee242dd7279709d898e1c2ab676d52981c61c3
3
+ metadata.gz: 42df0666b0fe511c259d52c15ad0e9043997d8dd
4
+ data.tar.gz: 667b2704058d7c64a50e891eed25e3f8345ec90e
5
5
  SHA512:
6
- metadata.gz: 732a9232be70aa01326fceef6f434c2d5844909006b07ddada5b97914e63708bf1d930c776a68ed7f5279dc8ca0f57edb2e4f19c610a9814967193946f6821cf
7
- data.tar.gz: a10a0e30a078e00aa2ab22f3677e31dd0ead715c92d87d42342b70b37bfd0052e3e427617d5243084609ec714cbaa1fcf7d3f57b64cd2c2ba380033e8267a1e7
6
+ metadata.gz: c8f488c8d73d6c219e7eb162638137a4e8e050f6e5fd257f00ce9f48265d1c3ebd239c85b43aff4e76d45b17af1d8f60b25a703edf86911664c21434d09c0263
7
+ data.tar.gz: c1745ef8cdea41fa44867884d7b667345734e7fd228ca9c14d9b2f2d50df0122c7c49f4e5a08c2a43a1ae7ed83da5eb10acb0d52914e5991d1eac87041e92b64
@@ -1,32 +1,77 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require "thor"
4
+ require "thor/group"
3
5
  require 'httparty'
4
6
  require 'tmpdir'
5
7
 
6
- template, app_name = [ARGV[0], ARGV[1]]
8
+ class RailsNewWrapper < Thor::Group
9
+ desc "run `rails new` with the requirements of the template"
7
10
 
8
- template_data_request = HTTParty.get(
9
- "https://rails-new.herokuapp.com/api/v1/templates/#{template}.json"
10
- )
11
+ argument :template_key,
12
+ :type => :string,
13
+ :desc => "The template key in the format user/template",
14
+ :required => true
11
15
 
12
- def build_arguments_array(arguments)
13
- arguments.map do |arg|
14
- tokens = [arg['key']]
15
- tokens << [arg['value']] if arg['has_value']
16
- tokens
17
- end.flatten
18
- end
16
+ argument :app_name,
17
+ :type => :string,
18
+ :desc => "The application name to pass to Rails",
19
+ :required => true
20
+
21
+ TEMPLATE_URL = -> template_key do
22
+ "https://rails-new.herokuapp.com/api/v1/templates/#{template_key}.json"
23
+ end
24
+
25
+ def request_template_data
26
+ url = TEMPLATE_URL[template_key]
19
27
 
20
- if template_data_request.code == 200
21
- template_data = JSON.parse(template_data_request.body)['template']
22
- git_repository = template_data['git_repository']
23
- main_file_location = template_data["main_file_location"]
24
- arguments = build_arguments_array(template_data['arguments'])
28
+ say "Fetching template data from ", :green, false
29
+ say url, :blue
25
30
 
26
- Dir.mktmpdir do |temp_dir|
27
- template_location = Pathname.new(temp_dir).join(main_file_location).to_s
31
+ @response = HTTParty.get(url)
32
+ if @response.code != 200
33
+ raise "The response of the server to #{@response.request.uri} was not 200."
34
+ end
35
+ end
28
36
 
29
- Kernel.system "git clone #{git_repository} #{temp_dir}"
30
- Kernel.system "rails", "new", app_name, "-m", template_location, *arguments
37
+ def parse_template_data
38
+ @template_data = JSON.parse(@response.body)['template']
39
+ @git_repository = @template_data['git_repository']
40
+ @main_file_location = @template_data["main_file_location"]
41
+ @arguments = build_arguments_array(@template_data['arguments'])
42
+ end
43
+
44
+ def run_template
45
+ Dir.mktmpdir do |temp_dir|
46
+ template_location = Pathname.new(temp_dir).join(@main_file_location).to_s
47
+
48
+ say "Cloning git repository ", :green, false
49
+ say @git_repository, :blue
50
+ Kernel.system "git clone #{@git_repository} #{temp_dir}"
51
+
52
+ command = [
53
+ "rails", "new", @app_name, "-m", template_location, *@arguments, *extra_rails_arguments
54
+ ]
55
+
56
+ say "Running rails command ", :green, false
57
+ say command.join(' '), :blue
58
+ Kernel.system *command
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def build_arguments_array(arguments)
65
+ arguments.map do |arg|
66
+ tokens = [arg['key']]
67
+ tokens << [arg['value']] if arg['has_value']
68
+ tokens
69
+ end.flatten
70
+ end
71
+
72
+ def extra_rails_arguments
73
+ @extra_rails_arguments ||= ARGV[2..-1]
31
74
  end
32
75
  end
76
+
77
+ RailsNewWrapper.start(ARGV)
@@ -1,7 +1,7 @@
1
1
  module Rails
2
2
  module New
3
3
  module Gem
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
@@ -20,5 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_dependency "httparty", "0.13.3"
23
+ spec.add_dependency "httparty", "~> 0.13"
24
+ spec.add_dependency "thor", "~> 0.19"
24
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-new
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - juliogarciag
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-06 00:00:00.000000000 Z
11
+ date: 2015-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,16 +42,30 @@ dependencies:
42
42
  name: httparty
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '='
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 0.13.3
47
+ version: '0.13'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '='
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.19'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
53
67
  - !ruby/object:Gem::Version
54
- version: 0.13.3
68
+ version: '0.19'
55
69
  description: A Rails template installation command.
56
70
  email:
57
71
  - julioggonz@gmail.com