Permalink
Browse files

rename

  • Loading branch information...
1 parent c8d80dd commit 03fc4e943227afc3a99af7753a4afefdfb5d3b92 @aduffeck committed Jun 9, 2010
View
40 README.md
@@ -1,30 +1,30 @@
-# schizophrenia
+# has_alter_ego
-schizophrenia makes it possible to keep seed and live data transparently in parallel. In contrast to other seed
-data approaches schizophrenia synchronizes the seed definitions with your database objects automagically unless you've
+has_alter_ego makes it possible to keep seed and live data transparently in parallel. In contrast to other seed
+data approaches has_alter_ego synchronizes the seed definitions with your database objects automagically unless you've
overridden it in the database.
# Installation
## Rails 2.3.x
### As a plugin
- script/plugin install git://github.com/aduffeck/schizophrenia.git
- script/generate schizophrenia
+ script/plugin install git://github.com/aduffeck/has_alter_ego.git
+ script/generate has_alter_ego
rake db:migrate
### As a gem
Add the following line to your config/environment.rb file:
- config.gem "schizophrenia"
+ config.gem "has_alter_ego"
Then
- gem install schizophrenia
- script/generate schizophrenia
+ gem install has_alter_ego
+ script/generate has_alter_ego
rake db:migrate
# Usage
-The seed data is defined in YAML files called after the model's table. The files are expected in db/fixtures/schizophrenia.
+The seed data is defined in YAML files called after the model's table. The files are expected in db/fixtures/alter_egos.
-Say you have a Model Car. schizophrenia is enabled with the has_schizophrenia method:
+Say you have a Model Car. has_alter_ego is enabled with the has_alter_ego method:
create_table :cars do |t|
t.string :brand
@@ -33,10 +33,10 @@ Say you have a Model Car. schizophrenia is enabled with the has_schizophrenia me
class Car < ActiveRecord::Base
- has_schizophrenia
+ has_alter_ego
end
-You would then create a file db/fixtures/schizophrenia/cars.yml with the seed data:
+You would then create a file db/fixtures/has_alter_ego/cars.yml with the seed data:
1:
brand: Lotus
@@ -60,40 +60,40 @@ and you'd automagically have those objects available in your database.
=> #<Car id: 1, brand: "Lotus", model: "Elise">
Whenever the seed definition changes the objects in the database inherit the changes unless they have been overridden.
-You can check if an object was created from seed definition with *schizophrenic?*:
+You can check if an object was created from seed definition with *has_alter_ego?*:
@car = Car.find(1)
- @car.schizophrenic?
+ @car.has_alter_ego?
=> true
- Car.new.schizophrenic?
+ Car.new.has_alter_ego?
=> false
-The method *schizophrenia_state* tells whether an object has been overridden. "modified" objects will no longer inherit
+The method *alter_ego_state* tells whether an object has been overridden. "modified" objects will no longer inherit
changes to the seed data.
- @car.schizophrenia_state
+ @car.alter_ego_state
=> "default"
@car.update_attribute(:model, "foo")
=> true
@car
=> #<Car id: 1, brand: "Lotus", model: "foo">
- @car.schizophrenia_state
+ @car.alter_ego_state
=> "modified"
If you don't want to inherit changes for an object without actually modifying it you can use *pin!*:
@car.pin!
=> true
- @car.schizophrenia_state
+ @car.alter_ego_state
=> "pinned"
*reset* reverts the changes in the database and activates the synchronization again:
@car.reset
=> #<Car id: 1, brand: "Lotus", model: "Elise">
- @car.schizophrenia_state
+ @car.alter_ego_state
=> "default"
View
6 Rakefile
@@ -6,15 +6,15 @@ require "rake/gempackagetask"
desc 'Default: run unit tests.'
task :default => :test
-desc 'Test the schizophrenia plugin.'
+desc 'Test the has_alter_ego plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
-desc 'Generate documentation for the schizophrenia plugin.'
+desc 'Generate documentation for the has_alter_ego plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Schizophrenia'
@@ -23,4 +23,4 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_files.include('lib/**/*.rb')
end
-Rake::GemPackageTask.new(eval(File.read("schizophrenia.gemspec"))) { |pkg| }
+Rake::GemPackageTask.new(eval(File.read("has_alter_ego.gemspec"))) { |pkg| }
View
8 generators/has_alter_ego/has_alter_ego_generator.rb
@@ -0,0 +1,8 @@
+class HasAlterEgoGenerator < Rails::Generator::Base
+ def manifest
+ record do |m|
+ m.directory('db/fixtures/alter_egos')
+ m.migration_template('create_alter_egos.rb', "db/migrate", :migration_file_name => 'create_alter_egos')
+ end
+ end
+end
View
14 generators/has_alter_ego/templates/create_alter_egos.rb
@@ -0,0 +1,14 @@
+class CreateAlterEgos < ActiveRecord::Migration
+ def self.up
+ create_table :alter_egos do |t|
+ t.string :alter_ego_object_id
+ t.string :alter_ego_object_type, :limit => 40
+ t.string :state
+ end
+ add_index :alter_egos, [:alter_ego_object_id, :alter_ego_object_type]
+ end
+
+ def self.down
+ drop_table :alter_egos
+ end
+end
View
8 generators/schizophrenia/schizophrenia_generator.rb
@@ -1,8 +0,0 @@
-class SchizophreniaGenerator < Rails::Generator::Base
- def manifest
- record do |m|
- m.directory('db/fixtures/schizophrenia')
- m.migration_template('create_schizophrenics.rb', "db/migrate", :migration_file_name => 'create_schizophrenics')
- end
- end
-end
View
14 generators/schizophrenia/templates/create_schizophrenics.rb
@@ -1,14 +0,0 @@
-class CreateSchizophrenics < ActiveRecord::Migration
- def self.up
- create_table :schizophrenics do |t|
- t.string :schizophrenic_object_id
- t.string :schizophrenic_object_type, :limit => 40
- t.string :state
- end
- add_index :uuids, [:schizophrenic_object_id, :schizophrenic_object_type]
- end
-
- def self.down
- drop_table :schizophrenics
- end
-end
View
8 schizophrenia.gemspec → has_alter_ego.gemspec
@@ -1,13 +1,13 @@
spec = Gem::Specification.new do |s|
- s.name = "schizophrenia"
+ s.name = "has_alter_ego"
s.version = "0.0.1"
s.authors = ["André Duffeck"]
s.email = ["aduffeck@suse.de"]
- s.homepage = "http://github.com/aduffeck/schizophrenia"
+ s.homepage = "http://github.com/aduffeck/has_alter_ego"
s.summary = "A Rails plugin which makes it possible to keep seed and live data in parallel"
s.description = <<-EOM
- schizophrenia makes it possible to keep seed and live data transparently in parallel. In contrast to other seed
- data approaches schizophrenia synchronizes the seed definitions with your database objects automagically unless you've
+ has_alter_ego makes it possible to keep seed and live data transparently in parallel. In contrast to other seed
+ data approaches has_alter_ego synchronizes the seed definitions with your database objects automagically unless you've
overridden it in the database.
EOM
View
52 lib/schizophrenia.rb → lib/has_alter_ego.rb
@@ -1,18 +1,18 @@
-require File.join(File.dirname(__FILE__), "schizophrenia", "schizophrenic")
+require File.join(File.dirname(__FILE__), "has_alter_ego", "alter_ego")
-module Schizophrenia
+module HasAlterEgo
module ActiveRecordAdapater
def self.included(base)
base.send :extend, ClassMethods
end
module ClassMethods
- def has_schizophrenia opts = {}
+ def has_alter_ego opts = {}
opts.reverse_merge!({:reserved_space => 1000})
class_eval do
- has_one :schizophrenic, :as => :schizophrenic_object
- alias_method :save_without_schizophrenia, :save
+ has_one :alter_ego, :as => :alter_ego_object
+ alias_method :save_without_alter_ego, :save
send :include, InstanceMethods
reserve_space(opts[:reserved_space])
parse_yml
@@ -26,7 +26,7 @@ def reserve_space space
o = self.new
o[self.primary_key] = space
- o.save_without_validation
+ o.save_without_alter_ego
o.destroy
return
end
@@ -43,29 +43,29 @@ def parse_yml_for primary_key
yml = get_yml
db_object = self.find(primary_key) rescue nil
if db_object
- raise "There is already a #{db_object.class} with id #{db_object.id} in the database." unless db_object.schizophrenic?
- if db_object.schizophrenic.state == 'default'
+ raise "There is already a #{db_object.class} with id #{db_object.id} in the database." unless db_object.has_alter_ego?
+ if db_object.alter_ego.state == 'default'
yml[primary_key].keys.each do |attr|
db_object[attr] = yml[primary_key][attr]
end
- db_object.save_without_schizophrenia
+ db_object.save_without_alter_ego
end
else
db_object = self.new
db_object[self.primary_key] = primary_key
yml[primary_key].keys.each do |attr|
db_object[attr] = yml[primary_key][attr]
end
- db_object.build_schizophrenic
- db_object.schizophrenic.state = 'default'
- db_object.save_without_schizophrenia
+ db_object.build_alter_ego
+ db_object.alter_ego.state = 'default'
+ db_object.save_without_alter_ego
end
end
private
def get_yml
- filename = File.join(RAILS_ROOT, "db", "fixtures", "schizophrenia", self.table_name + ".yml")
+ filename = File.join(RAILS_ROOT, "db", "fixtures", "alter_egos", self.table_name + ".yml")
return {} unless File.exists?(filename)
yml = File.open(filename) do |yf|
YAML::load( yf )
@@ -75,30 +75,30 @@ def get_yml
end
module InstanceMethods
- def schizophrenic?
- return self.schizophrenic.present?
+ def has_alter_ego?
+ return self.alter_ego.present?
end
- def schizophrenia_state
- self.schizophrenic.state if self.schizophrenic
+ def alter_ego_state
+ self.alter_ego.state if self.alter_ego
end
def save perform_validation = true
- if self.schizophrenic
- self.schizophrenic.state = 'modified'
- self.schizophrenic.save
+ if self.alter_ego
+ self.alter_ego.state = 'modified'
+ self.alter_ego.save
end
- save_without_schizophrenia perform_validation
+ save_without_alter_ego perform_validation
end
def pin!
- self.schizophrenic.state = 'pinned'
- self.schizophrenic.save
+ self.alter_ego.state = 'pinned'
+ self.alter_ego.save
end
def reset
- self.schizophrenic.state = 'default'
- self.schizophrenic.save
+ self.alter_ego.state = 'default'
+ self.alter_ego.save
self.class.parse_yml_for self[self.class.primary_key]
self.reload
@@ -108,5 +108,5 @@ def reset
end
class ActiveRecord::Base
- include Schizophrenia::ActiveRecordAdapater
+ include HasAlterEgo::ActiveRecordAdapater
end
View
3 lib/has_alter_ego/alter_ego.rb
@@ -0,0 +1,3 @@
+class AlterEgo < ActiveRecord::Base
+ belongs_to :alter_ego_object, :polymorphic => true
+end
View
3 lib/schizophrenia/schizophrenic.rb
@@ -1,3 +0,0 @@
-class Schizophrenic < ActiveRecord::Base
- belongs_to :schizophrenic_object, :polymorphic => true
-end
View
1 lib/tasks/has_alter_ego.rake
@@ -0,0 +1 @@
+
View
4 lib/tasks/schizophrenia.rake
@@ -1,4 +0,0 @@
-# desc "Explaining what the task does"
-# task :has_schizophrenia do
-# # Task goes here
-# end
View
2 rails/init.rb
@@ -1 +1 @@
-require 'schizophrenia'
+require 'has_alter_ego'
View
0 test/db/fixtures/schizophrenia/bikes.yml → test/db/fixtures/alter_egos/bikes.yml
File renamed without changes.
View
0 test/db/fixtures/schizophrenia/cars.yml → test/db/fixtures/alter_egos/cars.yml
File renamed without changes.
View
0 test/db/fixtures/schizophrenia/drinks.yml → test/db/fixtures/alter_egos/drinks.yml
File renamed without changes.
View
50 test/schizophrenia_test.rb → test/has_alter_ego_test.rb
@@ -2,7 +2,7 @@
class Car < ActiveRecord::Base
has_many :tires
- has_schizophrenia
+ has_alter_ego
end
class Bike < ActiveRecord::Base
@@ -16,49 +16,49 @@ class Tire < ActiveRecord::Base
class Drink < ActiveRecord::Base
set_primary_key :name
- has_schizophrenia
+ has_alter_ego
end
-class SchizophreniaTest < Test::Unit::TestCase
+class HasAlterEgoTest < Test::Unit::TestCase
def test_space_gets_reserved
c = Car.create
assert_equal 1001, c.id
assert_equal 1, Scooter.create.id
- Scooter.has_schizophrenia :reserved_space => 500
+ Scooter.has_alter_ego :reserved_space => 500
assert_equal 501, Scooter.create.id
end
- def test_schizophrenic?
- assert Car.find(1).schizophrenic
- assert !Car.new.schizophrenic?
+ def test_has_alter_ego?
+ assert Car.find(1).alter_ego
+ assert !Car.new.has_alter_ego?
end
def test_create_objects_from_yml
assert_equal 4, Car.count
c1 = Car.find(1)
assert_equal "Lotus", c1.brand
assert_equal "Elise", c1.model
- assert c1.schizophrenic?
+ assert c1.has_alter_ego?
end
def test_exception_is_raised_if_id_is_already_in_use
bike = Bike.create
assert_raise RuntimeError do
- Bike.has_schizophrenia
+ Bike.has_alter_ego
end
end
def test_object_attributes_are_updated_if_not_modified
c = Car.find(1)
assert_equal "Lotus", c.brand
- assert_equal "default", c.schizophrenia_state
+ assert_equal "default", c.alter_ego_state
c.brand = "Toyota"
- c.save_without_schizophrenia
+ c.save_without_alter_ego
c.reload
assert_equal "Toyota", c.brand
- assert_equal "default", c.schizophrenia_state
+ assert_equal "default", c.alter_ego_state
Car.parse_yml
c.reload
@@ -71,11 +71,11 @@ def test_object_attributes_are_not_updated_if_pinned
assert_equal "Porsche", c.brand
c.brand = "VW"
- c.save_without_schizophrenia
+ c.save_without_alter_ego
c.pin!
c.reload
assert_equal "VW", c.brand
- assert_equal "pinned", c.schizophrenia_state
+ assert_equal "pinned", c.alter_ego_state
Car.parse_yml
c.reload
@@ -90,7 +90,7 @@ def test_object_attributes_are_not_updated_if_modified
c.save
c.reload
assert_equal "VW", c.brand
- assert_equal "modified", c.schizophrenia_state
+ assert_equal "modified", c.alter_ego_state
Car.parse_yml
c.reload
@@ -100,31 +100,31 @@ def test_object_attributes_are_not_updated_if_modified
def test_reset
c = Car.find(3)
assert_equal "Ferrari", c.brand
- assert_equal "default", c.schizophrenia_state
+ assert_equal "default", c.alter_ego_state
c.brand = "Fiat"
c.save
c.reload
assert_equal "Fiat", c.brand
- assert_equal "modified", c.schizophrenia_state
+ assert_equal "modified", c.alter_ego_state
c.reset
c.reload
assert_equal "Ferrari", c.brand
- assert_equal "default", c.schizophrenia_state
+ assert_equal "default", c.alter_ego_state
end
def test_associations_do_not_change_state
c = Car.find(4)
- assert_equal "default", c.schizophrenia_state
+ assert_equal "default", c.alter_ego_state
assert_equal 0, c.tires.size
4.times do
c.tires << Tire.new
end
c.reload
- assert_equal "default", c.schizophrenia_state
+ assert_equal "default", c.alter_ego_state
assert_equal 4, c.tires.size
end
@@ -133,24 +133,24 @@ def test_different_primary_key
assert_equal "none", Drink.find("water").color
water = Drink.find("water")
- assert water.schizophrenic?
- assert_equal "default", water.schizophrenia_state
+ assert water.has_alter_ego?
+ assert_equal "default", water.alter_ego_state
water.color = "blue"
water.save
water.reload
assert_equal "blue", water.color
- assert_equal "modified", water.schizophrenia_state
+ assert_equal "modified", water.alter_ego_state
water.reset
water.reload
assert_equal "none", water.color
- assert_equal "default", water.schizophrenia_state
+ assert_equal "default", water.alter_ego_state
orangejuice = Drink.new
orangejuice.name = "orangejuice"
orangejuice.color = "yellow"
orangejuice.save
- assert !orangejuice.schizophrenic?
+ assert !orangejuice.has_alter_ego?
end
end
View
8 test/test_helper.rb
@@ -5,14 +5,14 @@
require 'test/unit'
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
-require File.dirname(__FILE__) + '/../lib/schizophrenia'
+require File.dirname(__FILE__) + '/../lib/has_alter_ego'
RAILS_ROOT = File.dirname(__FILE__)
silence_stream(STDOUT) do
ActiveRecord::Schema.define do
- create_table :schizophrenics do |t|
- t.string :schizophrenic_object_id
- t.string :schizophrenic_object_type, :limit => 40
+ create_table :alter_egos do |t|
+ t.string :alter_ego_object_id
+ t.string :alter_ego_object_type, :limit => 40
t.string :state
end

0 comments on commit 03fc4e9

Please sign in to comment.