cloudfuji 0.0.37
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/.gitignore +7 -0
- data/.rspec +4 -0
- data/Gemfile +17 -0
- data/README.md +3 -0
- data/Rakefile +36 -0
- data/app/controllers/cloudfuji/data_controller.rb +33 -0
- data/app/controllers/cloudfuji/envs_controller.rb +31 -0
- data/app/controllers/cloudfuji/mail_controller.rb +37 -0
- data/bin/cloudfuji +86 -0
- data/cloudfuji.gemspec +26 -0
- data/config/routes.rb +1 -0
- data/lib/cloudfuji.rb +53 -0
- data/lib/cloudfuji/action_mailer.rb +35 -0
- data/lib/cloudfuji/app.rb +202 -0
- data/lib/cloudfuji/bar.rb +19 -0
- data/lib/cloudfuji/base.rb +23 -0
- data/lib/cloudfuji/command.rb +110 -0
- data/lib/cloudfuji/config.rb +12 -0
- data/lib/cloudfuji/data.rb +52 -0
- data/lib/cloudfuji/data_helper.rb +1 -0
- data/lib/cloudfuji/dns.rb +195 -0
- data/lib/cloudfuji/engine.rb +21 -0
- data/lib/cloudfuji/envs.rb +6 -0
- data/lib/cloudfuji/envs_helper.rb +1 -0
- data/lib/cloudfuji/event.rb +63 -0
- data/lib/cloudfuji/event_observer.rb +20 -0
- data/lib/cloudfuji/mail_helper.rb +1 -0
- data/lib/cloudfuji/mail_route.rb +186 -0
- data/lib/cloudfuji/middleware.rb +42 -0
- data/lib/cloudfuji/models.rb +59 -0
- data/lib/cloudfuji/notification.rb +0 -0
- data/lib/cloudfuji/orm/active_record.rb +44 -0
- data/lib/cloudfuji/orm/mongoid.rb +31 -0
- data/lib/cloudfuji/platform.rb +47 -0
- data/lib/cloudfuji/schema.rb +42 -0
- data/lib/cloudfuji/smtp.rb +24 -0
- data/lib/cloudfuji/user.rb +59 -0
- data/lib/cloudfuji/user_helper.rb +7 -0
- data/lib/cloudfuji/utils.rb +53 -0
- data/lib/cloudfuji/version.rb +4 -0
- data/lib/generators/active_record/cloudfuji_generator.rb +28 -0
- data/lib/generators/active_record/templates/migration.rb +20 -0
- data/lib/generators/cloudfuji/auth_migration_generator.rb +46 -0
- data/lib/generators/cloudfuji/cloudfuji_generator.rb +14 -0
- data/lib/generators/cloudfuji/hooks_generator.rb +43 -0
- data/lib/generators/cloudfuji/install_generator.rb +24 -0
- data/lib/generators/cloudfuji/mail_routes_generator.rb +45 -0
- data/lib/generators/cloudfuji/orm_helpers.rb +21 -0
- data/lib/generators/cloudfuji/routes_generator.rb +22 -0
- data/lib/generators/mongoid/cloudfuji_generator.rb +17 -0
- data/lib/generators/templates/README +5 -0
- data/lib/generators/templates/cloudfuji.rb +10 -0
- data/lib/hooks.rb +36 -0
- data/lib/rails/routes.rb +42 -0
- data/lib/tasks/cloudfuji.rake +6 -0
- data/spec/app_spec/controllers/envs_controller_spec.rb +25 -0
- data/spec/app_spec/controllers/mail_controller_spec.rb +28 -0
- data/spec/app_spec/integration/app_claim_spec.rb +16 -0
- data/spec/gem_spec/base_spec.rb +24 -0
- data/spec/gem_spec/command_spec.rb +181 -0
- data/spec/gem_spec/config_spec.rb +9 -0
- data/spec/gem_spec/data_spec.rb +13 -0
- data/spec/gem_spec/hooks_spec.rb +5 -0
- data/spec/gem_spec/mail_route_spec.rb +168 -0
- data/spec/gem_spec/platform_spec.rb +9 -0
- data/spec/gem_spec/user_spec.rb +45 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/test_apps/rails-2.3/.gitignore +13 -0
- data/spec/test_apps/rails-2.3/Gemfile +13 -0
- data/spec/test_apps/rails-2.3/README +243 -0
- data/spec/test_apps/rails-2.3/Rakefile +10 -0
- data/spec/test_apps/rails-2.3/app/controllers/application_controller.rb +10 -0
- data/spec/test_apps/rails-2.3/app/helpers/application_helper.rb +3 -0
- data/spec/test_apps/rails-2.3/config/boot.rb +114 -0
- data/spec/test_apps/rails-2.3/config/environment.rb +41 -0
- data/spec/test_apps/rails-2.3/config/environments/development.rb +17 -0
- data/spec/test_apps/rails-2.3/config/environments/production.rb +28 -0
- data/spec/test_apps/rails-2.3/config/environments/test.rb +30 -0
- data/spec/test_apps/rails-2.3/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/test_apps/rails-2.3/config/initializers/cookie_verification_secret.rb +7 -0
- data/spec/test_apps/rails-2.3/config/initializers/inflections.rb +10 -0
- data/spec/test_apps/rails-2.3/config/initializers/mime_types.rb +5 -0
- data/spec/test_apps/rails-2.3/config/initializers/new_rails_defaults.rb +21 -0
- data/spec/test_apps/rails-2.3/config/initializers/session_store.rb +15 -0
- data/spec/test_apps/rails-2.3/config/locales/en.yml +5 -0
- data/spec/test_apps/rails-2.3/config/routes.rb +43 -0
- data/spec/test_apps/rails-2.3/db/seeds.rb +7 -0
- data/spec/test_apps/rails-2.3/doc/README_FOR_APP +2 -0
- data/spec/test_apps/rails-2.3/lib/tasks/rspec.rake +144 -0
- data/spec/test_apps/rails-2.3/public/404.html +30 -0
- data/spec/test_apps/rails-2.3/public/422.html +30 -0
- data/spec/test_apps/rails-2.3/public/500.html +30 -0
- data/spec/test_apps/rails-2.3/public/favicon.ico +0 -0
- data/spec/test_apps/rails-2.3/public/images/rails.png +0 -0
- data/spec/test_apps/rails-2.3/public/javascripts/application.js +2 -0
- data/spec/test_apps/rails-2.3/public/javascripts/controls.js +963 -0
- data/spec/test_apps/rails-2.3/public/javascripts/dragdrop.js +973 -0
- data/spec/test_apps/rails-2.3/public/javascripts/effects.js +1128 -0
- data/spec/test_apps/rails-2.3/public/javascripts/prototype.js +4320 -0
- data/spec/test_apps/rails-2.3/public/robots.txt +5 -0
- data/spec/test_apps/rails-2.3/script/about +4 -0
- data/spec/test_apps/rails-2.3/script/autospec +6 -0
- data/spec/test_apps/rails-2.3/script/console +3 -0
- data/spec/test_apps/rails-2.3/script/dbconsole +3 -0
- data/spec/test_apps/rails-2.3/script/destroy +3 -0
- data/spec/test_apps/rails-2.3/script/generate +3 -0
- data/spec/test_apps/rails-2.3/script/performance/benchmarker +3 -0
- data/spec/test_apps/rails-2.3/script/performance/profiler +3 -0
- data/spec/test_apps/rails-2.3/script/plugin +3 -0
- data/spec/test_apps/rails-2.3/script/runner +3 -0
- data/spec/test_apps/rails-2.3/script/server +3 -0
- data/spec/test_apps/rails-2.3/script/spec +10 -0
- data/spec/test_apps/rails-2.3/spec/all_spec.rb +5 -0
- data/spec/test_apps/rails-2.3/spec/rcov.opts +2 -0
- data/spec/test_apps/rails-2.3/spec/spec.opts +4 -0
- data/spec/test_apps/rails-2.3/spec/spec_helper.rb +83 -0
- data/spec/test_apps/rails-2.3/test/performance/browsing_test.rb +9 -0
- data/spec/test_apps/rails-2.3/test/test_helper.rb +38 -0
- data/spec/test_apps/rails-3.0/.gitignore +4 -0
- data/spec/test_apps/rails-3.0/.rspec +2 -0
- data/spec/test_apps/rails-3.0/Gemfile +10 -0
- data/spec/test_apps/rails-3.0/README +256 -0
- data/spec/test_apps/rails-3.0/Rakefile +7 -0
- data/spec/test_apps/rails-3.0/app/controllers/application_controller.rb +3 -0
- data/spec/test_apps/rails-3.0/app/controllers/static_controller.rb +4 -0
- data/spec/test_apps/rails-3.0/app/helpers/application_helper.rb +2 -0
- data/spec/test_apps/rails-3.0/app/helpers/static_helper.rb +2 -0
- data/spec/test_apps/rails-3.0/app/views/layouts/application.html.erb +14 -0
- data/spec/test_apps/rails-3.0/app/views/static/home.html.erb +1 -0
- data/spec/test_apps/rails-3.0/config.ru +4 -0
- data/spec/test_apps/rails-3.0/config/application.rb +46 -0
- data/spec/test_apps/rails-3.0/config/boot.rb +6 -0
- data/spec/test_apps/rails-3.0/config/environment.rb +5 -0
- data/spec/test_apps/rails-3.0/config/environments/development.rb +26 -0
- data/spec/test_apps/rails-3.0/config/environments/production.rb +49 -0
- data/spec/test_apps/rails-3.0/config/environments/test.rb +35 -0
- data/spec/test_apps/rails-3.0/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/test_apps/rails-3.0/config/initializers/inflections.rb +10 -0
- data/spec/test_apps/rails-3.0/config/initializers/mime_types.rb +5 -0
- data/spec/test_apps/rails-3.0/config/initializers/secret_token.rb +7 -0
- data/spec/test_apps/rails-3.0/config/initializers/session_store.rb +8 -0
- data/spec/test_apps/rails-3.0/config/locales/en.yml +5 -0
- data/spec/test_apps/rails-3.0/config/routes.rb +62 -0
- data/spec/test_apps/rails-3.0/db/schema.rb +15 -0
- data/spec/test_apps/rails-3.0/db/seeds.rb +7 -0
- data/spec/test_apps/rails-3.0/doc/README_FOR_APP +2 -0
- data/spec/test_apps/rails-3.0/lib/tasks/.gitkeep +0 -0
- data/spec/test_apps/rails-3.0/public/404.html +26 -0
- data/spec/test_apps/rails-3.0/public/422.html +26 -0
- data/spec/test_apps/rails-3.0/public/500.html +26 -0
- data/spec/test_apps/rails-3.0/public/favicon.ico +0 -0
- data/spec/test_apps/rails-3.0/public/images/rails.png +0 -0
- data/spec/test_apps/rails-3.0/public/index.html +239 -0
- data/spec/test_apps/rails-3.0/public/javascripts/application.js +2 -0
- data/spec/test_apps/rails-3.0/public/javascripts/controls.js +965 -0
- data/spec/test_apps/rails-3.0/public/javascripts/dragdrop.js +974 -0
- data/spec/test_apps/rails-3.0/public/javascripts/effects.js +1123 -0
- data/spec/test_apps/rails-3.0/public/javascripts/prototype.js +6001 -0
- data/spec/test_apps/rails-3.0/public/javascripts/rails.js +191 -0
- data/spec/test_apps/rails-3.0/public/robots.txt +5 -0
- data/spec/test_apps/rails-3.0/public/stylesheets/.gitkeep +0 -0
- data/spec/test_apps/rails-3.0/script/rails +6 -0
- data/spec/test_apps/rails-3.0/spec/all_spec.rb +5 -0
- data/spec/test_apps/rails-3.0/spec/spec_helper.rb +78 -0
- data/spec/test_apps/rails-3.0/test/performance/browsing_test.rb +9 -0
- data/spec/test_apps/rails-3.0/test/test_helper.rb +13 -0
- data/spec/test_apps/rails-3.0/vendor/plugins/.gitkeep +0 -0
- data/tasks/cover_me.rake +11 -0
- data/test_app/spec/views/home.html.erb_spec.rb +15 -0
- metadata +261 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module Cloudfuji
|
|
2
|
+
class Platform #:nodoc:
|
|
3
|
+
class << self
|
|
4
|
+
def name
|
|
5
|
+
ENV['CLOUDFUJI_NAME']
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def key
|
|
9
|
+
ENV['CLOUDFUJI_APP_KEY']
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def publish_url
|
|
13
|
+
"#{host}/apps/#{name}/bus"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def protocol
|
|
17
|
+
ENV['CLOUDFUJI_PROTOCOL'] || "https"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def port
|
|
21
|
+
ENV['CLOUDFUJI_PORT']
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def host
|
|
25
|
+
cloudfuji_port = port ? ":#{port}" : ""
|
|
26
|
+
cloudfuji_host = ENV['CLOUDFUJI_HOST'] || 'cloudfuji.com'
|
|
27
|
+
"#{protocol}://#{cloudfuji_host}#{cloudfuji_port}"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def on_cloudfuji?
|
|
31
|
+
ENV['HOSTING_PLATFORM']=="cloudfuji"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def claimed?
|
|
35
|
+
(ENV['CLOUDFUJI_CLAIMED'].nil? or ENV['CLOUDFUJI_CLAIMED'].blank?) ? false : true
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def metrics_token
|
|
39
|
+
ENV['CLOUDFUJI_METRICS_TOKEN']
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def cloudfuji_js_source
|
|
43
|
+
"#{Cloudfuji::Platform.host}/api/cloudfuji.js"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module Cloudfuji
|
|
2
|
+
# Holds devise schema information. To use it, just include its methods
|
|
3
|
+
# and overwrite the apply_schema method.
|
|
4
|
+
module Schema
|
|
5
|
+
|
|
6
|
+
# Creates reset_password_token and reset_password_sent_at.
|
|
7
|
+
#
|
|
8
|
+
# == Options
|
|
9
|
+
# * :reset_within - When true, adds a column that reset passwords within some date
|
|
10
|
+
def recoverable(options={})
|
|
11
|
+
use_within = options.fetch(:reset_within, Devise.reset_password_within.present?)
|
|
12
|
+
apply_devise_schema :reset_password_token, String
|
|
13
|
+
apply_devise_schema :reset_password_sent_at, DateTime if use_within
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Creates remember_token and remember_created_at.
|
|
17
|
+
#
|
|
18
|
+
# == Options
|
|
19
|
+
# * :use_salt - When true, does not create a remember_token and use password_salt instead.
|
|
20
|
+
def rememberable(options={})
|
|
21
|
+
use_salt = options.fetch(:use_salt, Devise.use_salt_as_remember_token)
|
|
22
|
+
apply_devise_schema :remember_token, String unless use_salt
|
|
23
|
+
apply_devise_schema :remember_created_at, DateTime
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Creates sign_in_count, current_sign_in_at, last_sign_in_at,
|
|
27
|
+
# current_sign_in_ip, last_sign_in_ip.
|
|
28
|
+
def trackable
|
|
29
|
+
apply_devise_schema :sign_in_count, Integer, :default => 0
|
|
30
|
+
apply_devise_schema :current_sign_in_at, DateTime
|
|
31
|
+
apply_devise_schema :last_sign_in_at, DateTime
|
|
32
|
+
apply_devise_schema :current_sign_in_ip, String
|
|
33
|
+
apply_devise_schema :last_sign_in_ip, String
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# Overwrite with specific modification to create your own schema.
|
|
38
|
+
def apply_devise_schema(name, type, options={})
|
|
39
|
+
raise NotImplementedError
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Cloudfuji
|
|
2
|
+
class SMTP
|
|
3
|
+
class << self
|
|
4
|
+
[:tls, :server, :port, :domain, :authentication, :user, :password].each do |method_name|
|
|
5
|
+
define_method "#{method_name}".to_sym do
|
|
6
|
+
ENV["SMTP_#{method_name.to_s.upcase}"]
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def setup_action_mailer_smtp!
|
|
11
|
+
ActionMailer::Base.smtp_settings = {
|
|
12
|
+
:enable_starttls_auto => Cloudfuji::SMTP.tls,
|
|
13
|
+
:tls => Cloudfuji::SMTP.tls,
|
|
14
|
+
:address => Cloudfuji::SMTP.server,
|
|
15
|
+
:port => Cloudfuji::SMTP.port,
|
|
16
|
+
:domain => Cloudfuji::SMTP.domain,
|
|
17
|
+
:authentication => Cloudfuji::SMTP.authentication,
|
|
18
|
+
:user_name => Cloudfuji::SMTP.user,
|
|
19
|
+
:password => Cloudfuji::SMTP.password,
|
|
20
|
+
}
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module Cloudfuji
|
|
2
|
+
# Cloudfuji User enables user validation against Cloudfuji's server
|
|
3
|
+
class User < Cloudfuji::Base
|
|
4
|
+
class << self
|
|
5
|
+
|
|
6
|
+
# Checks whether user an email and password correspond to a valid cloudfuji
|
|
7
|
+
# user. Returns nil if false, or the Cloudfuji user's ID if true.
|
|
8
|
+
def valid?(email, pass)
|
|
9
|
+
params = {}
|
|
10
|
+
params[:email] = email
|
|
11
|
+
params[:pass] = pass
|
|
12
|
+
Cloudfuji::Command.post_command(valid_unity_url, params)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Checks whether email corresponds to a valid Cloudfuji user.
|
|
16
|
+
# Returns true or false
|
|
17
|
+
def exists?(email)
|
|
18
|
+
params = {}
|
|
19
|
+
params[:email] = email
|
|
20
|
+
Cloudfuji::Command.post_command(exists_unity_url, params)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# send a Cloudfuji invite with a short description of the app (also a box of chocolates, if he's a Kryptonian)
|
|
24
|
+
# Cloudfuji::User.invite("clark@kent-on-krypton.com")
|
|
25
|
+
def invite(email)
|
|
26
|
+
params = {}
|
|
27
|
+
params[:email] = email
|
|
28
|
+
Cloudfuji::Command.post_command(invite_unity_url, params)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# List all pending invites
|
|
32
|
+
# Cloudfuji::User.pending_invites
|
|
33
|
+
def pending_invites
|
|
34
|
+
params = {}
|
|
35
|
+
Cloudfuji::Command.get_command(pending_invites_unity_url, params)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# To remove a user from an application
|
|
39
|
+
# Cloudfuji::User.remove("5z325f4knbm2f")
|
|
40
|
+
def remove(ido_id)
|
|
41
|
+
params = {}
|
|
42
|
+
params[:ido_id] = ido_id
|
|
43
|
+
Cloudfuji::Command.post_command(remove_unity_url, params)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# To send a notification to a user who belongs to your app
|
|
47
|
+
# Cloudfuji::User.notify('5z325f4knbm2f', 'Example title', 'Example message', 'chat')
|
|
48
|
+
def notify(ido_id, title, body, category="general")
|
|
49
|
+
params = {}
|
|
50
|
+
params[:ido_id] = ido_id
|
|
51
|
+
params[:title] = title
|
|
52
|
+
params[:body] = body
|
|
53
|
+
params[:category] = category
|
|
54
|
+
|
|
55
|
+
Cloudfuji::Command.post_command(notify_user_url, params)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module Cloudfuji
|
|
2
|
+
class Utils #:nodoc:
|
|
3
|
+
class << self
|
|
4
|
+
# TODO: Make this update all the available ENV variables
|
|
5
|
+
def refresh_env!
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def array_helper(array, proc)
|
|
9
|
+
array.collect do |value|
|
|
10
|
+
if value.kind_of?( Hash )
|
|
11
|
+
deep_process_hash_keys(value, proc)
|
|
12
|
+
elsif value.kind_of?( Array )
|
|
13
|
+
array_helper(array)
|
|
14
|
+
else
|
|
15
|
+
value
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def deep_process_hash_keys(input_hash, proc)
|
|
21
|
+
hash = {}
|
|
22
|
+
input_hash.keys.each do |key|
|
|
23
|
+
_key = proc.call(key)
|
|
24
|
+
if input_hash[key].kind_of?(Hash)
|
|
25
|
+
hash[_key] = deep_process_hash_keys(input_hash[key], proc)
|
|
26
|
+
elsif input_hash[key].kind_of?(Array)
|
|
27
|
+
hash[_key] = array_helper(input_hash[key], proc)
|
|
28
|
+
else
|
|
29
|
+
hash[_key] = input_hash[key]
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
hash
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def deep_underscore_hash_keys(input_hash)
|
|
37
|
+
deep_process_hash_keys(input_hash, Proc.new { |key| key.to_s.underscore })
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def deep_symbolize_hash_keys(input_hash)
|
|
41
|
+
deep_process_hash_keys(input_hash, Proc.new { |key| key.to_sym })
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def deep_stringify_hash_keys(input_hash)
|
|
45
|
+
deep_process_hash_keys(input_hash, Proc.new { |key| key.to_s })
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def normalize_keys(input_hash)
|
|
49
|
+
deep_symbolize_hash_keys(deep_underscore_hash_keys(input_hash))
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'rails/generators/active_record'
|
|
2
|
+
require 'generators/cloudfuji/orm_helpers'
|
|
3
|
+
|
|
4
|
+
module ActiveRecord
|
|
5
|
+
module Generators
|
|
6
|
+
class CloudfujiGenerator < ActiveRecord::Generators::Base
|
|
7
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
|
8
|
+
|
|
9
|
+
include Cloudfuji::Generators::OrmHelpers
|
|
10
|
+
source_root File.expand_path("../templates", __FILE__)
|
|
11
|
+
|
|
12
|
+
def generate_model
|
|
13
|
+
invoke "active_record:model", [name], :migration => false unless model_exists?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def copy_cloudfuji_migration
|
|
17
|
+
migration_template "migration.rb", "db/migrate/cloudfuji_create_#{table_name}"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def inject_cloudfuji_content
|
|
21
|
+
inject_into_class model_path, class_name, model_contents + <<-CONTENT
|
|
22
|
+
# Setup accessible (or protected) attributes for your model
|
|
23
|
+
attr_accessible :cloudfuji_id, :cloudfuji_version
|
|
24
|
+
CONTENT
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class CloudfujiCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
create_table(:<%= table_name %>) do |t|
|
|
4
|
+
t.string :cloudfuji_id
|
|
5
|
+
t.string :cloudfuji_version
|
|
6
|
+
|
|
7
|
+
<% for attribute in attributes -%>
|
|
8
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
|
9
|
+
<% end -%>
|
|
10
|
+
|
|
11
|
+
t.timestamps
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
add_index :<%= table_name %>, :cloudfuji_id, :unique => true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.down
|
|
18
|
+
drop_table :<%= table_name %>
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module Cloudfuji
|
|
2
|
+
module Generators
|
|
3
|
+
class AuthMigrationGenerator < Rails::Generators::NamedBase
|
|
4
|
+
|
|
5
|
+
def create_auth_migration_file
|
|
6
|
+
fields_to_add = []
|
|
7
|
+
new_resource = class_name.constantize.new
|
|
8
|
+
|
|
9
|
+
fields_to_add << "ido_id" if not new_resource.respond_to?(:ido_id)
|
|
10
|
+
fields_to_add << "first_name" if not new_resource.respond_to?(:first_name)
|
|
11
|
+
fields_to_add << "last_name" if not new_resource.respond_to?(:last_name)
|
|
12
|
+
fields_to_add << "email" if not new_resource.respond_to?(:email)
|
|
13
|
+
fields_to_add << "locale" if not new_resource.respond_to?(:locale)
|
|
14
|
+
fields_to_add << "timezone" if not new_resource.respond_to?(:timezone)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
attr_accessor_string = fields_to_add.collect { |field| ":"+field}.join(", ")
|
|
18
|
+
|
|
19
|
+
inject_into_class "app/models/#{class_name.underscore}.rb", class_name do
|
|
20
|
+
<<-EOF
|
|
21
|
+
attr_accessor #{attr_accessor_string}\n
|
|
22
|
+
|
|
23
|
+
def cloudfuji_extra_attributes(extra_attributes)
|
|
24
|
+
self.first_name = extra_attributes["first_name"].to_s
|
|
25
|
+
self.last_name = extra_attributes["last_name"].to_s
|
|
26
|
+
self.email = extra_attributes["email"]
|
|
27
|
+
self.locale = extra_attributes["locale"]
|
|
28
|
+
self.timezone = extra_attributes["timezone"]
|
|
29
|
+
end
|
|
30
|
+
EOF
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
gem("devise_cloudfuji_authenticatable")
|
|
34
|
+
|
|
35
|
+
generate("migration", "AddCloudfujiFieldsTo#{class_name}", *fields_to_add.collect { |field| field + ":string"})
|
|
36
|
+
generate("migration", "AddIndexForIdoIdTo#{class_name}")
|
|
37
|
+
Dir["db/migrate/*add_index_for_ido_id_to*"].each do |file|
|
|
38
|
+
inject_into_file file, :after => "class AddIndexForIdoIdToUser < ActiveRecord::Migration\n def change\n" do
|
|
39
|
+
" add_index :#{plural_name}, :ido_id\n"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Cloudfuji
|
|
2
|
+
module Generators
|
|
3
|
+
class CloudfujiGenerator < Rails::Generators::NamedBase
|
|
4
|
+
namespace "cloudfuji"
|
|
5
|
+
source_root File.expand_path("../templates", __FILE__)
|
|
6
|
+
|
|
7
|
+
desc "Generates a model with the given NAME (if one does not exist) with Cloudfuji " <<
|
|
8
|
+
"configuration plus a migration file and devise routes."
|
|
9
|
+
|
|
10
|
+
hook_for :orm
|
|
11
|
+
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module Cloudfuji
|
|
2
|
+
module Generators
|
|
3
|
+
class HooksGenerator < Rails::Generators::Base
|
|
4
|
+
|
|
5
|
+
def create_hooks_file
|
|
6
|
+
|
|
7
|
+
lib("cloudfuji/hooks/user_hooks.rb") do
|
|
8
|
+
<<-EOF
|
|
9
|
+
class CloudfujiUserHooks < Cloudfuji::EventObserver
|
|
10
|
+
def user_added
|
|
11
|
+
user.create(:email => params['data']['email'],
|
|
12
|
+
:ido_id => params['data']['ido_id'],
|
|
13
|
+
:active => true)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def user_removed
|
|
17
|
+
User.find_by_ido_id(params['data']['ido_id']).try(:disable!)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
EOF
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
lib('cloudfuji/hooks/app_hooks.rb') do
|
|
24
|
+
<<-EOF
|
|
25
|
+
class CloudfujiAppHooks < Cloudfuji::EventObserver
|
|
26
|
+
def app_claimed
|
|
27
|
+
User.find(1).update_attributes(:email => params['data']['email'],
|
|
28
|
+
:ido_id => params['data']['ido_id'])
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
EOF
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
initializer "cloudfuji_hooks.rb" do
|
|
35
|
+
<<-EOF
|
|
36
|
+
Dir["\#{Dir.pwd}/lib/cloudfuji/**/*.rb"].each { |file| require file }
|
|
37
|
+
EOF
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# require 'active_support/secure_random'
|
|
2
|
+
|
|
3
|
+
module Cloudfuji
|
|
4
|
+
module Generators
|
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
|
6
|
+
source_root File.expand_path("../../templates", __FILE__)
|
|
7
|
+
|
|
8
|
+
desc "Creates a Devise initializer and copy locale files to your application."
|
|
9
|
+
class_option :orm
|
|
10
|
+
|
|
11
|
+
def copy_initializer
|
|
12
|
+
template "cloudfuji.rb", "config/initializers/cloudfuji.rb"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# def copy_locale
|
|
16
|
+
# copy_file "../../../config/locales/en.yml", "config/locales/devise.en.yml"
|
|
17
|
+
# end
|
|
18
|
+
|
|
19
|
+
def show_readme
|
|
20
|
+
readme "README" if behavior == :invoke
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module Cloudfuji
|
|
2
|
+
module Generators
|
|
3
|
+
class MailRoutesGenerator < Rails::Generators::Base
|
|
4
|
+
|
|
5
|
+
def create_mail_routes_file
|
|
6
|
+
# Create the lib/cloudfuji directory if it doesnt exist
|
|
7
|
+
Dir.mkdir("#{Rails.root}/lib/cloudfuji") if not Dir.exists? "#{Rails.root}/lib/cloudfuji"
|
|
8
|
+
|
|
9
|
+
lib "cloudfuji/mail_routes.rb" do
|
|
10
|
+
<<-EOF
|
|
11
|
+
::Cloudfuji::Mailroute.map do |m|
|
|
12
|
+
|
|
13
|
+
m.route("simple") do
|
|
14
|
+
m.subject("hello")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
EOF
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
lib("cloudfuji/hooks/email_hooks.rb") do
|
|
22
|
+
<<-EOF
|
|
23
|
+
class CloudfujiEmailHooks < Cloudfuji::EventObserver
|
|
24
|
+
|
|
25
|
+
def mail_simple
|
|
26
|
+
puts "YAY!"
|
|
27
|
+
puts params.inspect
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
EOF
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
initializer "cloudfuji_hooks.rb" do
|
|
35
|
+
<<-EOF
|
|
36
|
+
Dir["\#{Dir.pwd}/lib/cloudfuji/**/*.rb"].each { |file| require file }
|
|
37
|
+
EOF
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
initializer("cloudfuji_mail_routes.rb", "require './lib/cloudfuji/mail_routes.rb'")
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|