totem_activerecord 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: a05370ef1e82a18a72edaf9a52ca4b7e77301b58
4
- data.tar.gz: 1565844208285c71f32c6a8fa820d0d8df95c70e
3
+ metadata.gz: b9abc9ae52b8f85e580196c99dc30beafec21107
4
+ data.tar.gz: faa75b7ccec1ee289419180f9979a85cebc6f4fd
5
5
  SHA512:
6
- metadata.gz: 67f19e9427cfccb3d0451d340518cfd1c3356e6308981bf66cfd00415713bd8c61ad7dcd679c957e9c92c08583e0e74e49645552b22c154d0d0898bf585ed7ca
7
- data.tar.gz: cd16f18650b0e89857bbfaf0ce3e3ad10767734e0b40fa0c941bb51015e637708fcb56fcf576c3a4995457a30af085891c822faff9986e0093fe91790852a66b
6
+ metadata.gz: c0cdec374306571a3716d11e561ba33b65e0774410f4211c7fc895c7207660d9484a6c0f1a09dedf068e27511c0b47399d198e5e4c7bf2c08c499252ef92272b
7
+ data.tar.gz: 4b6b1a83df9dc637d174e9f930010227498fbe81798dfb8ed4315442b907832a174907384b926a4e9d3c81867565afeaaf9e262eb3abf00b8d9295c6083ca3b0
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # TotemActiverecord
2
2
 
3
- This gem is an ActiveRecord add-on for [Totem](https://github.com/chadrem/totem).
4
- The version of the activerecord gem isn't locked down so that you can specify a specversion in your project's Gemfile.
3
+ This gem is the ActiveRecord add-on for [Totem](https://github.com/chadrem/totem).
5
4
 
6
5
  ## Installation
7
6
 
@@ -40,6 +39,13 @@ It is recommeended you do this so that your project is always in a known state:
40
39
 
41
40
  gem 'activerecord', '3.2.17', :require => 'active_record'
42
41
 
42
+ You will also need to add the appropriate database specific gem to your Gemfile.
43
+ For the above example, you would add the following:
44
+
45
+ gem 'mysql2'
46
+
47
+ You should now run `bundle` again so it instals the new gems.
48
+
43
49
  ## Usage
44
50
 
45
51
  Create your database:
@@ -58,25 +64,21 @@ Rollback your database (one migration back):
58
64
 
59
65
  $ bundle exec totem db rollback
60
66
 
61
- ## Migrations
67
+ Create a new (empty) migration:
62
68
 
63
- You will need to manually create migrations in the `db/migrate` directory.
64
- The filename and syntax is the same as what you would use in Rails.
69
+ $ bundle exec totem db migration <name>
65
70
 
66
- Example migration `db/migrate/20140312221052_create_users.rb`:
71
+ Run the 'up' method for a given migration:
67
72
 
68
- class CreateUsers < ActiveRecord::Migration
69
- def change
70
- create_table :users do |t|
71
- t.string :name
72
- t.timestamps
73
- end
74
- end
75
- end
73
+ $ bundle exec totem db up <timestamp>
74
+
75
+ Run the 'down' method for a given migration:
76
+
77
+ $ bundle exec totem db down <timestamp>
76
78
 
77
79
  ## Models
78
80
 
79
- You will need to manually create models in the `app` directory or a sub-directory.
81
+ You will need to manually create models in the `app` directory.
80
82
 
81
83
  Example model `app/user.rb` to go with the above migration:
82
84
 
@@ -89,7 +91,7 @@ Rember to add the model to the `app/loader.rb` just like you do with all classes
89
91
 
90
92
  ## Contributing
91
93
 
92
- 1. Fork it ( http://github.com/<my-github-username>/totem_activerecord/fork )
94
+ 1. Fork it
93
95
  2. Create your feature branch (`git checkout -b my-new-feature`)
94
96
  3. Commit your changes (`git commit -am 'Add some feature'`)
95
97
  4. Push to the branch (`git push origin my-new-feature`)
@@ -3,10 +3,15 @@ module TotemActiverecord
3
3
  class Db < Totem::ShellCmds::Base
4
4
  def run
5
5
  case @args[0]
6
- when 'create' then create
7
- when 'drop' then drop
8
- when 'migrate' then migrate
9
- when 'rollback' then rollback
6
+ when 'create' then create
7
+ when 'drop' then drop
8
+ when 'migrate' then migrate
9
+ when 'rollback' then rollback
10
+ when 'migration' then migration(@args[1])
11
+ when 'up' then up(@args[1])
12
+ when 'down' then down(@args[1])
13
+ else
14
+ puts_usage
10
15
  end
11
16
  end
12
17
 
@@ -14,6 +19,7 @@ module TotemActiverecord
14
19
  ActiveRecord::Base.establish_connection(TotemActiverecord.config.merge('database' => nil))
15
20
  ActiveRecord::Base.connection.create_database(TotemActiverecord.config['database'])
16
21
  ActiveRecord::Base.establish_connection(TotemActiverecord.config)
22
+ TotemActiverecord.reconnect
17
23
 
18
24
  return true
19
25
  end
@@ -27,7 +33,6 @@ module TotemActiverecord
27
33
  def migrate
28
34
  ActiveRecord::Migration.verbose = true
29
35
  ActiveRecord::Migrator.migrate(TotemActiverecord.migrations_path)
30
-
31
36
  TotemActiverecord.reconnect
32
37
 
33
38
  return true
@@ -39,6 +44,77 @@ module TotemActiverecord
39
44
 
40
45
  return true
41
46
  end
47
+
48
+ def migration(name)
49
+ return false unless require_arg(name, :name)
50
+
51
+ name = name.gsub(/\s/,'_')
52
+ timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
53
+ filename = "#{timestamp}_#{name}.rb"
54
+ path = File.join(Totem.root, 'db', 'migrate', filename)
55
+ content = "class #{name.camelize} < ActiveRecord::Migration\nend"
56
+
57
+ puts "Creating migration: #{path}"
58
+
59
+ if File.exists?(path)
60
+ puts_error('Migration already exists.')
61
+ return false
62
+ end
63
+
64
+ File.open(path, 'w') { |f| f.write(content) }
65
+
66
+ return true
67
+ end
68
+
69
+ def up(timestamp)
70
+ return false unless require_arg(timestamp, :timestamp)
71
+
72
+ ActiveRecord::Migration.verbose = true
73
+ ActiveRecord::Migrator.up(TotemActiverecord.migrations_path, timestamp.to_i)
74
+ TotemActiverecord.reconnect
75
+
76
+ return true
77
+ end
78
+
79
+ def down(timestamp)
80
+ return false unless require_arg(timestamp, :timestamp)
81
+
82
+ ActiveRecord::Migration.verbose = true
83
+ ActiveRecord::Migrator.down(TotemActiverecord.migrations_path, timestamp.to_i)
84
+ TotemActiverecord.reconnect
85
+
86
+ return true
87
+ end
88
+
89
+ private
90
+
91
+ def puts_usage
92
+ puts "Usage:\n bundle exec totem db <command>"
93
+ puts
94
+ puts "Commands:\n"
95
+ puts " create - Create the database if it doesn't exist."
96
+ puts " drop - Drop the database if it exists."
97
+ puts " migrate - Run all new migrations."
98
+ puts " rollback - Rollback one migration."
99
+ puts " migration <name> - Create a new migration with <name>."
100
+ puts " up <name> - Run 'up' method in the <name> migration."
101
+ puts " down <name> - Run 'down' method in the <name> migration."
102
+ end
103
+
104
+ def puts_error(message)
105
+ puts "ERROR: #{message}"
106
+ puts
107
+ puts_usage
108
+ end
109
+
110
+ def require_arg(val, name)
111
+ if val.nil? || val.length == 0
112
+ puts_error("You must provide a #{name}.")
113
+ return false
114
+ end
115
+
116
+ return true
117
+ end
42
118
  end
43
119
  end
44
120
  end
@@ -1,3 +1,3 @@
1
1
  module TotemActiverecord
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
@@ -4,23 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'totem_activerecord/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "totem_activerecord"
7
+ spec.name = 'totem_activerecord'
8
8
  spec.version = TotemActiverecord::VERSION
9
- spec.authors = ["Chad Remesch"]
10
- spec.email = ["chad@remesch.com"]
9
+ spec.authors = ['Chad Remesch']
10
+ spec.email = ['chad@remesch.com']
11
11
  spec.summary = %q{ActiveRecord add-on for the Totem gem.}
12
12
  spec.description = %q{Add an easy to use ORM to your Totem based applications.}
13
- spec.homepage = ""
14
- spec.license = "MIT"
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency("totem")
22
- spec.add_dependency("activerecord")
21
+ spec.add_dependency('totem', '>= 0.0.5')
22
+ spec.add_dependency('activerecord')
23
23
 
24
- spec.add_development_dependency("bundler", "~> 1.5")
25
- spec.add_development_dependency("rake")
24
+ spec.add_development_dependency('bundler', '~> 1.5')
25
+ spec.add_development_dependency('rake')
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: totem_activerecord
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
  - Chad Remesch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-12 00:00:00.000000000 Z
11
+ date: 2014-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: totem
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.0.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.0.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement