bushido 0.0.29 → 0.0.30

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/Gemfile +23 -0
  2. data/Rakefile +9 -3
  3. data/app/controllers/bushido/data_controller.rb +4 -2
  4. data/app/controllers/bushido/envs_controller.rb +11 -3
  5. data/bushido.gemspec +1 -0
  6. data/lib/bushido/data.rb +44 -29
  7. data/lib/bushido/envs.rb +3 -31
  8. data/lib/bushido/hooks.rb +38 -0
  9. data/lib/bushido/ido_schema.rb +17 -0
  10. data/lib/bushido/middleware.rb +6 -5
  11. data/lib/bushido/models.rb +144 -0
  12. data/lib/bushido/orm/active_record.rb +44 -0
  13. data/lib/bushido/orm/mongoid.rb +31 -0
  14. data/lib/bushido/platform.rb +4 -1
  15. data/lib/bushido/schema.rb +42 -0
  16. data/lib/bushido/version.rb +1 -1
  17. data/lib/bushido.rb +17 -2
  18. data/lib/engine.rb +4 -7
  19. data/lib/generators/active_record/bushido_generator.rb +28 -0
  20. data/lib/generators/active_record/templates/migration.rb +20 -0
  21. data/lib/generators/bushido/bushido_generator.rb +14 -0
  22. data/lib/generators/bushido/install_generator.rb +24 -0
  23. data/lib/generators/bushido/orm_helpers.rb +21 -0
  24. data/lib/generators/mongoid/bushido_generator.rb +17 -0
  25. data/lib/generators/templates/README +5 -0
  26. data/lib/generators/templates/bushido.rb +10 -0
  27. data/lib/rails/#routes.rb# +16 -0
  28. data/test/controllers/envs_controller_test.rb +21 -0
  29. data/test/rails_app/Rakefile +9 -0
  30. data/test/rails_app/app/controllers/application_controller.rb +7 -0
  31. data/test/rails_app/app/helpers/application_helper.rb +2 -0
  32. data/test/rails_app/app/views/application/index.html.erb +1 -0
  33. data/test/rails_app/app/views/layouts/application.html.erb +14 -0
  34. data/test/rails_app/config/application.rb +50 -0
  35. data/test/rails_app/config/boot.rb +10 -0
  36. data/test/rails_app/config/database.yml +22 -0
  37. data/test/rails_app/config/environment.rb +5 -0
  38. data/test/rails_app/config/environments/development.rb +26 -0
  39. data/test/rails_app/config/environments/production.rb +49 -0
  40. data/test/rails_app/config/environments/test.rb +35 -0
  41. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  42. data/test/rails_app/config/initializers/inflections.rb +10 -0
  43. data/test/rails_app/config/initializers/mime_types.rb +5 -0
  44. data/test/rails_app/config/initializers/secret_token.rb +7 -0
  45. data/test/rails_app/config/initializers/session_store.rb +8 -0
  46. data/test/rails_app/config/locales/en.yml +5 -0
  47. data/test/rails_app/config/routes.rb +62 -0
  48. data/test/rails_app/config.ru +4 -0
  49. data/test/rails_app/db/development.sqlite3 +0 -0
  50. data/test/rails_app/db/test.sqlite3 +0 -0
  51. data/test/rails_app/log/development.log +66 -0
  52. data/test/rails_app/log/production.log +0 -0
  53. data/test/rails_app/log/server.log +0 -0
  54. data/test/rails_app/log/test.log +0 -0
  55. data/test/rails_app/public/404.html +26 -0
  56. data/test/rails_app/public/422.html +26 -0
  57. data/test/rails_app/public/500.html +26 -0
  58. data/test/rails_app/public/favicon.ico +0 -0
  59. data/test/rails_app/public/javascripts/application.js +2 -0
  60. data/test/rails_app/public/javascripts/controls.js +965 -0
  61. data/test/rails_app/public/javascripts/dragdrop.js +974 -0
  62. data/test/rails_app/public/javascripts/effects.js +1123 -0
  63. data/test/rails_app/public/javascripts/prototype.js +6001 -0
  64. data/test/rails_app/public/javascripts/rails.js +191 -0
  65. data/test/rails_app/public/stylesheets/.gitkeep +0 -0
  66. data/test/rails_app/script/rails +6 -0
  67. data/test/test_helper.rb +9 -0
  68. metadata +154 -79
  69. data/config/routes.rb +0 -1
  70. data/test/routes_test.rb +0 -12
  71. data/test/test_executable.rb +0 -10
data/Gemfile CHANGED
@@ -3,3 +3,26 @@ source "http://rubygems.org"
3
3
 
4
4
  # Specify your gem's dependencies in bushido.gemspec
5
5
  gemspec
6
+
7
+
8
+ gem "rails", "~> 3.0.7"
9
+ gem "sqlite3-ruby"
10
+
11
+ group :test do
12
+ # gem "webrat", "0.7.2", :require => false
13
+ # gem "mocha", :require => false
14
+ end
15
+
16
+ platforms :ruby do
17
+ #gem "sqlite3-ruby"
18
+
19
+ # group :mongoid do
20
+ # gem "mongo", "~> 1.3.0"
21
+ # gem "mongoid", "2.0.1"
22
+ # gem "bson_ext", "~> 1.3.0"
23
+ # end
24
+ end
25
+
26
+ group :development do
27
+ gem 'ci_reporter'
28
+ end
data/Rakefile CHANGED
@@ -1,9 +1,15 @@
1
1
  require 'rake/testtask'
2
2
  require 'bundler'
3
+ require 'ci/reporter/rake/test_unit'
4
+
3
5
  Bundler::GemHelper.install_tasks
4
6
 
5
- Rake::TestTask.new do |t|
6
- t.libs += ["lib", "test"]
7
- t.test_files = FileList['test/test*.rb']
7
+ task :default => :test
8
+
9
+ desc "Run bushido tests"
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << 'lib'
12
+ t.libs << 'test'
13
+ t.pattern = 'test/**/*_test.rb'
8
14
  t.verbose = true
9
15
  end
@@ -1,6 +1,7 @@
1
1
  module Bushido
2
2
  class DataController < ApplicationController
3
- # PUT /bushido/data/
3
+
4
+ # POST /bushido/data/
4
5
  def index
5
6
  @key = params.delete(:key)
6
7
  if ENV["BUSHIDO_APP_KEY"] != @key
@@ -13,7 +14,8 @@ module Bushido
13
14
 
14
15
  puts "OMG GOT DATA FROM BUSHIBUS"
15
16
  puts params.inspect
16
- Bushido::Data.fire('global', params)
17
+ puts params[:category].inspect
18
+ Bushido::Data.fire(params, "#{params[:category]}.#{params[:event]}")
17
19
  respond_to do |format|
18
20
  format.json {render :json => {'acknowledged' => true}, :status => 200}
19
21
  end
@@ -2,7 +2,11 @@ module Bushido
2
2
  class EnvsController < ApplicationController
3
3
  # PUT /bushido/envs/:id
4
4
  def update
5
- if ENV["BUSHIDO_KEY"] != params[:key] or params[:id] == "BUSHIDO_KEY"
5
+ logger.info "Updating ENV vars!"
6
+ logger.info "params: #{params.inspect}"
7
+
8
+ if Bushido::Platform.key != params[:key] or params[:id] == Bushido::Platform.key
9
+ logger.info "key didn't match! #{Bushido::Platform.key} != #{params[:key]}"
6
10
  respond_to do |format|
7
11
  format.html { render :layout => false, :text => true, :status => :forbidden }
8
12
  format.json { render :status => :unprocessable_entity }
@@ -10,16 +14,20 @@ module Bushido
10
14
  end
11
15
  end
12
16
 
17
+ logger.info "next: #{params[:id]} = #{ENV[params[:id]]}"
18
+
13
19
  ENV[params[:id]] = params[:value]
14
20
  @value = ENV[params[:id]]
15
-
21
+
22
+ logger.info "next: #{params[:id]} = #{ENV[params[:id]]}"
23
+
16
24
  respond_to do |format|
17
25
  if @value != ENV[params[:id]]
18
26
  format.html{render :layout => false, :text => true, :status => :unprocessable_entity}
19
27
  format.json{render :status => :unprocessable_entity}
20
28
  else
21
29
  puts "Firing update hooks method from controller"
22
- Bushido::Hooks.fire(params[:id], {params[:id] => ENV[params[:id]]})
30
+ Bushido::Envs.fire(params[:id], {params[:id] => ENV[params[:id]]})
23
31
  format.html{render :text => true}
24
32
  format.json{render :json => {params[:id] => ENV[params[:id]]}}
25
33
  end
data/bushido.gemspec CHANGED
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.add_dependency "rest-client", ">=1.6.1"
16
16
  s.add_dependency "json", ">=1.4.6"
17
17
  s.add_dependency "highline", ">=1.6.1"
18
+ s.add_dependency "orm_adapter", "~> 0.0.3"
18
19
 
19
20
  s.rubyforge_project = "bushido"
20
21
 
data/lib/bushido/data.rb CHANGED
@@ -1,40 +1,55 @@
1
1
  module Bushido
2
2
  class Data #:nodoc:
3
3
 
4
- @@hooks = {}
5
-
6
- class << self
7
- def fire(data, *hooks)
8
- unless @@hooks[:global].nil?
9
- @@hooks[:global].call(data, 'global')
10
- end
4
+ extend Hooks
11
5
 
12
- if hooks.length > 0
13
- hooks.each do |h|
14
- unless @@hooks[h].nil?
15
- @@hooks[h].call(data, hook)
16
- end
17
- end
18
- end
6
+ class << self
7
+ def attach(*models)
8
+ # Total no-op, we just need to load the classes in order to
9
+ # register the hooks, and this does that.
19
10
  end
20
11
 
21
- def listen *hooks, &block
22
- if hooks.empty? and block_given?
23
- @@hooks[:global] = block
24
- elsif !hooks.nil? and block_given?
25
- hooks.each do |h|
26
- @@hooks[h] = block
27
- end
28
- end
12
+ def bushido_data(model, model_data)
13
+ puts "prepping publish data..."
14
+ data = {}
15
+ data[:key] = Bushido::Platform.key
16
+
17
+
18
+ data["data"] = model_data
19
+ puts data.inspect
20
+ data["data"]["ido_model"] = model
21
+ puts "Publishing Ido model"
22
+ puts data.to_json
23
+ puts Bushido::Platform.publish_url
24
+
25
+ return data
29
26
  end
27
+
30
28
 
31
- def publish(model)
32
- puts "bushido publishing model"
33
- puts Bushido::Platform.host
34
- RestClient.post(Bushido::Platform.host, model.to_json, :content_type => :json, :accept => :json)
29
+ def publish(model, model_data, verb=:post)
30
+ puts "in the Data::Publish method"
31
+ # POST to /apps/:id/bus
32
+ data = bushido_data(model, model_data)
33
+
34
+ puts "got the data"
35
+ url = Bushido::Platform.publish_url
36
+ puts "url: #{url} , verb #{verb}"
37
+
38
+ if verb == :delete
39
+ verb = :put
40
+ url += "/#{data['data']['ido_id']}"
41
+ end
42
+
43
+ puts "Publishing to: #{url}"
44
+
45
+ # TODO: Catch non-200 response code
46
+ response = JSON.parse(RestClient.send(verb, url, data.to_json, :content_type => :json, :accept => :json))
47
+ if response['ido_id'].nil? or response['ido_version'].nil?
48
+ return false
49
+ end
50
+
51
+ return response
35
52
  end
36
-
37
53
  end
38
-
39
54
  end
40
- end
55
+ end
data/lib/bushido/envs.rb CHANGED
@@ -1,34 +1,6 @@
1
1
  module Bushido
2
2
  class Envs #:nodoc:
3
-
4
- @@hooks = {}
5
-
6
- class << self
7
- def fire(data, *hooks)
8
- unless @@hooks[:global].nil?
9
- @@hooks[:global].call(data, 'global')
10
- end
11
-
12
- if hooks.length > 0
13
- hooks.each do |h|
14
- unless @@hooks[h].nil?
15
- @@hooks[h].call(data, hook)
16
- end
17
- end
18
- end
19
- end
20
-
21
- def listen *hooks, &block
22
- if hooks.empty? and block_given?
23
- @@hooks[:global] = block
24
- elsif !hooks.nil? and block_given?
25
- hooks.each do |h|
26
- @@hooks[h] = block
27
- end
28
- end
29
- end
30
-
31
- end
32
-
3
+ extend Hooks
33
4
  end
34
- end
5
+ end
6
+
@@ -0,0 +1,38 @@
1
+ module Hooks
2
+
3
+ @@hooks = {}
4
+
5
+ def fire(data, *events)
6
+ puts "Hooks: #{@@hooks.inspect}"
7
+
8
+ puts "Events: #{events.inspect}"
9
+ puts "\twith data: #{data.inspect}"
10
+ unless @@hooks[:global].nil?
11
+ @@hooks[:global].call(data, 'global')
12
+ end
13
+
14
+ if events.length > 0
15
+ events.each do |event|
16
+ print "Checking for event: #{event} in hooks..."
17
+ if @@hooks[event].nil?
18
+ puts "not found, ignoring."
19
+ else
20
+ puts "found, firing!"
21
+ @@hooks[event].call(data, event)
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ def listen *events, &block
28
+ puts "Listening for #{events.inspect}"
29
+
30
+ if events.empty? and block_given?
31
+ @@hooks[:global] = block
32
+ elsif !events.nil? and block_given?
33
+ events.each do |event|
34
+ @@hooks[event] = block
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,17 @@
1
+ # This is probably a bad idea. Feel free to kill this file if you're unsure.
2
+ module Bushido
3
+ module IdoSchema
4
+ class << self
5
+ def schema_for(ido_model)
6
+ # GET to /ido/schemas/:ido_model
7
+ # TODO: Catch non-200 response code
8
+ response = JSON.parse(RestClient.get("#{Bushido::Platform.host}/ido/schemas/#{ido_model}/#{ENV['BUSHIDO_PROJECT_SHA']}", :content_type => :json, :accept => :json))
9
+ if response['ido_schema'].nil?
10
+ return false
11
+ end
12
+
13
+ return response['ido_schema']
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,10 +1,9 @@
1
- require 'rack/utils'
1
+ #require 'rack/utils'
2
2
 
3
3
  module Bushido
4
4
  class Middleware
5
5
 
6
- # BUSHIDO_JS_URL = 'http://localhost:4567/javascripts/bushido.js'
7
- BUSHIDO_JS_URL = 'http://bushi.do/api/bushido.js'
6
+ BUSHIDO_JS_URL = "#{Bushido::Platform.host}/api/bushido.js"
8
7
 
9
8
  include Rack::Utils
10
9
 
@@ -12,10 +11,12 @@ module Bushido
12
11
  @app = app
13
12
  @bushido_app_name = ENV['BUSHIDO_APP']
14
13
  @bushido_metrics_token = ENV['BUSHIDO_METRICS_TOKEN']
15
- @bushido_claimed = ENV['BUSHIDO_CLAIMED'].nil? ? false : true
14
+ @bushido_claimed = (ENV['BUSHIDO_CLAIMED'].nil? or ENV['BUSHIDO_CLAIMED'].blank?) ? false : true
16
15
  end
17
16
 
18
17
  def call(env)
18
+ @bushido_claimed = (ENV['BUSHIDO_CLAIMED'].nil? or ENV['BUSHIDO_CLAIMED'].blank?) ? false : true
19
+
19
20
  status, headers, response = @app.call(env)
20
21
 
21
22
  unless @bushido_app_name.empty?
@@ -30,7 +31,7 @@ module Bushido
30
31
  var _bushido_metrics_token = '#{@bushido_metrics_token}';
31
32
  (function() {
32
33
  var bushido = document.createElement('script'); bushido.type = 'text/javascript'; bushido.async = true;
33
- bushido.src = '#{BUSHIDO_JS_URL}?#{::Bushido::VERSION.gsub('.', '')}';
34
+ bushido.src = '#{BUSHIDO_JS_URL}?ts=#{::Bushido::VERSION.gsub('.', '')}';
34
35
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(bushido, s);
35
36
  })();
36
37
  </script>
@@ -0,0 +1,144 @@
1
+ module Bushido
2
+ module Models
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ end
6
+
7
+ def posh
8
+ puts "posh"
9
+ end
10
+
11
+ def to_ido
12
+ data = {}
13
+
14
+ self.class.ido_schema.each do |schema_field|
15
+ data[schema_field] = self.send(schema_field.to_sym)
16
+ end
17
+
18
+ data
19
+ end
20
+
21
+
22
+ def ido_destroy
23
+ unless self.ido_id.nil?
24
+ puts "Global IdoData, publishing destroy event to Bushido databus"
25
+
26
+ data = self.to_ido
27
+
28
+ puts "This is the data I *want* to publish: #{data.inspect}"
29
+
30
+ begin
31
+ response = Bushido::Data.publish(self.class.class_variable_get("@@ido_model"), data, :delete)
32
+ rescue => e
33
+ puts e.inspect
34
+ # TODO: Catch specific exceptions and bubble up errors (e.g. 'bushido is down', 'model is malformed', etc.)
35
+ return false
36
+ end
37
+
38
+ self.ido_version = response["ido_version"]
39
+ self.ido_id ||= response["ido_id"]
40
+
41
+ puts response.inspect
42
+ else
43
+ puts "Remote change, not publishing to Bushido databus"
44
+ end
45
+
46
+ return true
47
+ end
48
+
49
+
50
+
51
+ def ido_save
52
+ # It's possible we're saving an item just handed to us by Bushido, so we
53
+ # don't want to re-publish it. We can detect it using the version.
54
+
55
+ puts "what"
56
+ # bushido_id.nil? This is new, it's from us (otherwise bushido would have given it an id), we should publish it.
57
+ # bushido_version == self.find(self.id).bushido_version The version hasn't changed, our data has, we should publish it
58
+ puts "new_record? #{self.new_record?}"
59
+ puts "self.id = #{self.id}"
60
+ puts "ido_id.nil? #{ido_id.nil?}"
61
+ unless self.new_record?
62
+ puts "ido_version == self.class.find(self.id).ido_version ? #{ido_version == self.class.find(self.id).ido_version}"
63
+ puts "#{self.ido_version} == #{self.class.find(self.id).ido_version} ? #{ido_version == self.class.find(self.id).ido_version}"
64
+ end
65
+ if self.ido_id.nil? or (not self.new_record? and self.ido_version == self.class.find(self.id).ido_version)
66
+ puts "Local change, publishing to Bushido databus"
67
+
68
+ puts "Converting to Ido format..."
69
+ data = self.to_ido
70
+
71
+ puts "Publishing: #{data}"
72
+
73
+ begin
74
+ print "About to publish"
75
+ response = Bushido::Data.publish(self.class.class_variable_get("@@ido_model"), data)
76
+ puts "done!"
77
+ rescue => e
78
+ puts "ERROR!"
79
+ puts e.inspect
80
+ # TODO: Catch specific exceptions and bubble up errors (e.g. 'bushido is down', 'model is malformed', etc.)
81
+ return false
82
+ end
83
+
84
+ self.ido_version = response["ido_version"]
85
+ self.ido_id ||= response["ido_id"]
86
+
87
+ puts response.inspect
88
+ else
89
+ puts "Remote change, not publishing to Bushido databus"
90
+ end
91
+
92
+ return true
93
+ end
94
+
95
+ module ClassMethods
96
+ def ido model
97
+ self.class_variable_set("@@ido_model", model)
98
+
99
+ [:create, :update, :destroy].each do |event|
100
+ puts "Hooking into #{model}.#{event}..."
101
+
102
+ Bushido::Data.listen("#{model}.#{event}") do |data, hook|
103
+ puts "#{hook}.) Firing off #{model}.#{event} now with data: #{data}"
104
+ self.send("on_ido_#{event}".to_sym, self.from_ido(data))
105
+ end
106
+ end
107
+
108
+ before_save :ido_save
109
+ before_destroy :ido_destroy
110
+ end
111
+
112
+ def from_ido(incoming_json)
113
+ model = self.new
114
+ puts model.inspect
115
+
116
+ ido_schema.each do |schema_field|
117
+ puts "Setting#{schema_field}= #{incoming_json[schema_field]}"
118
+ model.send("#{schema_field}=".to_sym, incoming_json[schema_field])
119
+ end
120
+
121
+ model
122
+ end
123
+
124
+
125
+ def on_ido_create(ido_app)
126
+ ido_app.save
127
+ end
128
+
129
+ def on_ido_update(ido_app)
130
+ app = self.find_or_create_by_ido_id(ido_app.ido_id)
131
+
132
+ ido_schema.each do |schema_field|
133
+ app.send("#{schema_field}=".to_sym, ido_app[schema_field])
134
+ end
135
+
136
+ app.save
137
+ end
138
+
139
+ def on_ido_destroy(ido_app)
140
+ self.find_by_ido_id(ido_app.ido_id).try(:destroy)
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,44 @@
1
+ require 'orm_adapter/adapters/active_record'
2
+
3
+ module Bushido
4
+ module Orm
5
+ # This module contains some helpers and handle schema (migrations):
6
+ #
7
+ # create_table :accounts do |t|
8
+ # t.database_authenticatable
9
+ # t.confirmable
10
+ # t.recoverable
11
+ # t.rememberable
12
+ # t.trackable
13
+ # t.lockable
14
+ # t.timestamps
15
+ # end
16
+ #
17
+ # However this method does not add indexes. If you need them, here is the declaration:
18
+ #
19
+ # add_index "accounts", ["email"], :name => "email", :unique => true
20
+ # add_index "accounts", ["confirmation_token"], :name => "confirmation_token", :unique => true
21
+ # add_index "accounts", ["reset_password_token"], :name => "reset_password_token", :unique => true
22
+ #
23
+ module ActiveRecord
24
+ module Schema
25
+ include Bushido::Schema
26
+
27
+ # Tell how to apply schema methods.
28
+ def apply_bushido_schema(name, type, options={})
29
+ column name, type.to_s.downcase.to_sym, options
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ module ActiveRecord
37
+ class Base
38
+ include Bushido::Models
39
+ end
40
+ end
41
+
42
+ ActiveRecord::ConnectionAdapters::Table.send :include, Bushido::Orm::ActiveRecord::Schema
43
+ ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Bushido::Orm::ActiveRecord::Schema
44
+
@@ -0,0 +1,31 @@
1
+ require 'orm_adapter/adapters/mongoid'
2
+
3
+ module Bushido
4
+ module Orm
5
+ module Mongoid
6
+ module Hook
7
+ def bushido_modules_hook!
8
+ extend Schema
9
+ yield
10
+ return unless Devise.apply_schema
11
+ devise_modules.each { |m| send(m) if respond_to?(m, true) }
12
+ end
13
+ end
14
+
15
+ module Schema
16
+ include Bushido::Schema
17
+
18
+ # Tell how to apply schema methods
19
+ def apply_bushido_schema(name, type, options={})
20
+ type = Time if type == DateTime
21
+ field name, { :type => type }.merge!(options)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ Mongoid::Document::ClassMethods.class_eval do
29
+ include Bushido::Models
30
+ include Bushido::Orm::Mongoid::Hook
31
+ end
@@ -9,7 +9,10 @@ module Bushido
9
9
  def key
10
10
  ENV['BUSHIDO_APP_KEY']
11
11
  end
12
-
12
+
13
+ def publish_url
14
+ "#{host}/apps/#{name}/bus"
15
+ end
13
16
 
14
17
  def host
15
18
  port = ENV['BUSHIDO_PORT'] ? ":#{ENV['BUSHIDO_PORT']}" : ""
@@ -0,0 +1,42 @@
1
+ module Bushido
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
@@ -1,4 +1,4 @@
1
1
  module Bushido
2
2
  # Current version of the Bushido gem
3
- VERSION = "0.0.29"
3
+ VERSION = "0.0.30"
4
4
  end
data/lib/bushido.rb CHANGED
@@ -1,12 +1,18 @@
1
1
  module Bushido #:nodoc:
2
2
  require 'optparse'
3
- require 'rest-client'
3
+ require 'rest_client'
4
4
  require 'json'
5
5
  require 'highline/import'
6
-
6
+ require 'orm_adapter'
7
+
7
8
  require 'engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
9
+
10
+ require "action_dispatch"
11
+ require "rails/routes"
12
+ require "bushido/hooks"
8
13
  require "bushido/platform"
9
14
  require "bushido/utils"
15
+ require "bushido/hooks"
10
16
  require "bushido/command"
11
17
  require "bushido/app"
12
18
  require "bushido/user"
@@ -15,4 +21,13 @@ module Bushido #:nodoc:
15
21
  require "bushido/envs"
16
22
  require "bushido/data"
17
23
  require "bushido/middleware"
24
+ require "bushido/models"
25
+ require "bushido/schema"
26
+ require "bushido/ido_schema"
27
+
28
+ # Default way to setup Bushido. Run rails generate bushido_install to create
29
+ # a fresh initializer with all configuration values.
30
+ def self.setup
31
+ yield self
32
+ end
18
33
  end
data/lib/engine.rb CHANGED
@@ -4,15 +4,12 @@ require 'rails/routes'
4
4
 
5
5
  module Bushido
6
6
  class Engine < Rails::Engine
7
-
7
+
8
8
  initializer "bushido.add_middleware" do |app|
9
-
9
+
10
10
  #Only include our middleware if its on our platform
11
- unless ENV['BUSHIDO_APP'].nil?
12
- app.middleware.use Bushido::Middleware
13
- end
14
-
11
+ app.middleware.use Bushido::Middleware unless ENV['BUSHIDO_APP'].nil?
15
12
  end
16
-
13
+
17
14
  end
18
15
  end