medea-generators 0.2.0 → 0.2.6
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.
- data/.rvmrc +32 -0
- data/Gemfile.lock +12 -2
- data/lib/generators/medea/init/init_generator.rb +96 -10
- data/medea-generators.gemspec +3 -2
- metadata +19 -5
data/.rvmrc
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# adapted from: http://rvm.beginrescueend.com/workflow/rvmrc/
|
4
|
+
|
5
|
+
ruby_string="1.9.2"
|
6
|
+
gemset_name="medea-generators"
|
7
|
+
|
8
|
+
if rvm list strings | grep -q "${ruby_string}" ; then
|
9
|
+
|
10
|
+
# Load or create the specified environment
|
11
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
12
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/${ruby_string}@${gemset_name}" ]] ; then
|
13
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/${ruby_string}@${gemset_name}"
|
14
|
+
else
|
15
|
+
rvm --create "${ruby_string}@${gemset_name}"
|
16
|
+
fi
|
17
|
+
|
18
|
+
else
|
19
|
+
|
20
|
+
# Notify the user to install the desired interpreter before proceeding.
|
21
|
+
echo "${ruby_string} was not found, please run 'rvm install ${ruby_string}' and then cd back into the project directory."
|
22
|
+
|
23
|
+
fi
|
24
|
+
|
25
|
+
#turn on the prompt in PS1
|
26
|
+
#RVM prompt
|
27
|
+
if [ -z "$RVM_PROMPT" ]
|
28
|
+
then
|
29
|
+
RVM_PROMPT=true
|
30
|
+
PS1="[\$(/usr/local/bin/rvm-prompt v g)] $PS1"
|
31
|
+
fi
|
32
|
+
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
medea-generators (0.
|
4
|
+
medea-generators (0.2.1)
|
5
|
+
medea
|
6
|
+
rest-client
|
5
7
|
|
6
8
|
GEM
|
7
9
|
remote: http://rubygems.org/
|
@@ -38,11 +40,16 @@ GEM
|
|
38
40
|
erubis (2.6.6)
|
39
41
|
abstract (>= 1.0.0)
|
40
42
|
i18n (0.5.0)
|
43
|
+
json (1.4.6)
|
41
44
|
mail (2.2.14)
|
42
45
|
activesupport (>= 2.3.6)
|
43
46
|
i18n (>= 0.4.0)
|
44
47
|
mime-types (~> 1.16)
|
45
48
|
treetop (~> 1.4.8)
|
49
|
+
medea (0.5.4)
|
50
|
+
json
|
51
|
+
rest-client
|
52
|
+
uuidtools
|
46
53
|
mime-types (1.16)
|
47
54
|
polyglot (0.3.1)
|
48
55
|
rack (1.2.1)
|
@@ -64,14 +71,17 @@ GEM
|
|
64
71
|
rake (>= 0.8.7)
|
65
72
|
thor (~> 0.14.4)
|
66
73
|
rake (0.8.7)
|
74
|
+
rest-client (1.6.1)
|
75
|
+
mime-types (>= 1.16)
|
67
76
|
thor (0.14.6)
|
68
77
|
treetop (1.4.9)
|
69
78
|
polyglot (>= 0.3.1)
|
70
79
|
tzinfo (0.3.24)
|
80
|
+
uuidtools (2.1.1)
|
71
81
|
|
72
82
|
PLATFORMS
|
73
83
|
ruby
|
74
84
|
|
75
85
|
DEPENDENCIES
|
76
86
|
medea-generators!
|
77
|
-
rails (~> 3.0.
|
87
|
+
rails (~> 3.0.3)
|
@@ -2,36 +2,122 @@ require 'generators/medea'
|
|
2
2
|
require 'rails/generators/generated_attribute'
|
3
3
|
require 'medea'
|
4
4
|
|
5
|
+
require 'rest_client'
|
6
|
+
|
5
7
|
module Medea
|
6
8
|
module Generators
|
7
9
|
class InitGenerator < Base
|
8
|
-
no_tasks {
|
9
|
-
|
10
|
-
|
11
|
-
def random_string length = 25
|
12
|
-
rand(32**length).to_s(32)
|
13
|
-
end
|
14
|
-
}
|
15
|
-
argument :jason_topic, :type => :string, :required => true, :banner => "Topic"
|
10
|
+
no_tasks { attr_accessor :topic, :user, :pass }
|
11
|
+
argument :jason_topic, :type => :string, :required => false, :banner => "Topic"
|
16
12
|
argument :username, :type => :string, :required => false, :banner => "username"
|
17
|
-
argument :password, :type => :string, :required => false, :banner => "
|
13
|
+
argument :password, :type => :string, :required => false, :banner => "password"
|
14
|
+
|
15
|
+
class_option :skip_topics, :desc => 'Don\'t automatically create topics.', :type => :boolean
|
18
16
|
|
19
17
|
def initialize(*args, &block)
|
20
18
|
super
|
21
19
|
|
22
20
|
@topic = jason_topic
|
21
|
+
if not @topic
|
22
|
+
@topic ||= random_string 10
|
23
|
+
if @topic[0] =~ /[0-9]/
|
24
|
+
@topic[0] = "abcdefghij"[@topic[0].to_i]
|
25
|
+
end
|
26
|
+
end
|
23
27
|
@user = username
|
24
28
|
@user ||= random_string
|
25
29
|
@pass = password
|
26
30
|
@pass ||= random_string
|
27
31
|
end
|
28
32
|
|
29
|
-
def
|
33
|
+
def init
|
30
34
|
#we can't create the topic, but we can create database.yml
|
31
35
|
template "database.yml", "config/database.yml"
|
32
36
|
template "jasondb.rb", "config/initializers/jasondb.rb"
|
37
|
+
create_topics
|
38
|
+
end
|
39
|
+
|
40
|
+
def patch_application
|
41
|
+
new_requires = <<-END
|
42
|
+
require 'action_controller/railtie'
|
43
|
+
require 'action_mailer/railtie'
|
44
|
+
require 'active_resource/railtie'
|
45
|
+
require 'rails/test_unit/railtie'
|
46
|
+
END
|
47
|
+
|
48
|
+
#open up application.rb
|
49
|
+
application_rb = File.new("#{Rails.root}/config/application.rb")
|
50
|
+
lines = application_rb.readlines
|
51
|
+
application_rb.close
|
52
|
+
|
53
|
+
changes = false
|
54
|
+
#find the line that reads require 'rails/all'
|
55
|
+
lines.each do |line|
|
56
|
+
#replace that line with the new four
|
57
|
+
changes = true if line.gsub!(/require 'rails\/all'/, new_requires)
|
58
|
+
end
|
33
59
|
|
60
|
+
if changes
|
61
|
+
application_rb = File.new("#{Rails.root}/config/application.rb", "w")
|
62
|
+
lines.each do |line|
|
63
|
+
application_rb.write line
|
64
|
+
end
|
65
|
+
|
66
|
+
application_rb.close
|
67
|
+
say_status "patched", "config/application.rb", :green
|
68
|
+
else
|
69
|
+
say_status "checked", "config/application.rb", :blue
|
70
|
+
end
|
34
71
|
end
|
72
|
+
|
73
|
+
protected
|
74
|
+
|
75
|
+
def random_string length = 25
|
76
|
+
rand(32**length).to_s(32)
|
77
|
+
end
|
78
|
+
|
79
|
+
def create_topic topic
|
80
|
+
payload = {
|
81
|
+
"..USERNAME" => @user,
|
82
|
+
"..PASSWORD" => @pass,
|
83
|
+
"..CONFIRM_PASSWORD" => @pass,
|
84
|
+
"..PERMISSIONS" => "S",
|
85
|
+
"..CHECKSUM" => "FALSE",
|
86
|
+
"..DOMAIN" => %({"domain":"http://rest.jasondb.com/#{topic}"}),
|
87
|
+
"..STATE" => "0 EQ 0 THEN ..NEW THEN ..NEW",
|
88
|
+
"..A_new_domain" => "Your new domain #{topic} has been created"
|
89
|
+
}
|
90
|
+
success = true
|
91
|
+
begin
|
92
|
+
resp = RestClient.post "https://rest.jasondb.com/#{topic}", payload
|
93
|
+
if resp.code == 201
|
94
|
+
#success!
|
95
|
+
else
|
96
|
+
success = false
|
97
|
+
end
|
98
|
+
rescue
|
99
|
+
success = false
|
100
|
+
end
|
101
|
+
|
102
|
+
if success
|
103
|
+
say_status "create", "Topic created."
|
104
|
+
else
|
105
|
+
if topic[0] =~ /[0-9]/
|
106
|
+
say_status "Error", "An error occurred while creating the Topic. It must start with a letter", :red
|
107
|
+
else
|
108
|
+
say_status "Warning", "An error occurred while creating the Topic. Does it already exist?", :yellow
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
def create_topics
|
115
|
+
unless options.skip_topics?
|
116
|
+
create_topic "#{@topic}-dev"
|
117
|
+
create_topic "#{@topic}-test"
|
118
|
+
create_topic @topic
|
119
|
+
end
|
120
|
+
end
|
35
121
|
end
|
36
122
|
end
|
37
123
|
end
|
data/medea-generators.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "medea-generators"
|
6
|
-
s.version = "0.2.
|
6
|
+
s.version = "0.2.6"
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.authors = ["Michael Jensen"]
|
9
9
|
s.email = ["michaelj@jasondb.com"]
|
@@ -12,8 +12,9 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.description = %q{Medea Generators provides scaffolding for Rails projects using Medea to access JasonDB.
|
13
13
|
This is very closely modelled on Ryan Bates' Nifty Generators.}
|
14
14
|
|
15
|
-
s.add_development_dependency 'rails', '~> 3.0.
|
15
|
+
s.add_development_dependency 'rails', '~> 3.0.3'
|
16
16
|
s.add_dependency 'medea'
|
17
|
+
s.add_dependency 'rest-client'
|
17
18
|
|
18
19
|
s.files = `git ls-files`.split("\n")
|
19
20
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 6
|
9
|
+
version: 0.2.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Jensen
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-21 00:00:00 +11:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -28,8 +28,8 @@ dependencies:
|
|
28
28
|
segments:
|
29
29
|
- 3
|
30
30
|
- 0
|
31
|
-
-
|
32
|
-
version: 3.0.
|
31
|
+
- 3
|
32
|
+
version: 3.0.3
|
33
33
|
type: :development
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
@@ -45,6 +45,19 @@ dependencies:
|
|
45
45
|
version: "0"
|
46
46
|
type: :runtime
|
47
47
|
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rest-client
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
type: :runtime
|
60
|
+
version_requirements: *id003
|
48
61
|
description: |-
|
49
62
|
Medea Generators provides scaffolding for Rails projects using Medea to access JasonDB.
|
50
63
|
This is very closely modelled on Ryan Bates' Nifty Generators.
|
@@ -58,6 +71,7 @@ extra_rdoc_files: []
|
|
58
71
|
|
59
72
|
files:
|
60
73
|
- .gitignore
|
74
|
+
- .rvmrc
|
61
75
|
- Gemfile
|
62
76
|
- Gemfile.lock
|
63
77
|
- Rakefile
|