totem_activerecord 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +96 -0
- data/Rakefile +14 -0
- data/lib/totem_activerecord/shell_cmds/db.rb +46 -0
- data/lib/totem_activerecord/version.rb +3 -0
- data/lib/totem_activerecord.rb +53 -0
- data/totem_activerecord.gemspec +26 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a05370ef1e82a18a72edaf9a52ca4b7e77301b58
|
4
|
+
data.tar.gz: 1565844208285c71f32c6a8fa820d0d8df95c70e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 67f19e9427cfccb3d0451d340518cfd1c3356e6308981bf66cfd00415713bd8c61ad7dcd679c957e9c92c08583e0e74e49645552b22c154d0d0898bf585ed7ca
|
7
|
+
data.tar.gz: cd16f18650b0e89857bbfaf0ce3e3ad10767734e0b40fa0c941bb51015e637708fcb56fcf576c3a4995457a30af085891c822faff9986e0093fe91790852a66b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Chad Remesch
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# TotemActiverecord
|
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.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'totem_activerecord'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install totem_activerecord
|
19
|
+
|
20
|
+
## Setup
|
21
|
+
|
22
|
+
You will need setup this gem the first time you use it in a project.
|
23
|
+
|
24
|
+
Create a `config/database.yml` (example for MRI + MySQL + Activerecord 3.x below):
|
25
|
+
|
26
|
+
development:
|
27
|
+
adapter: mysql2
|
28
|
+
database: my_app_dev
|
29
|
+
username: root
|
30
|
+
reconnect: true
|
31
|
+
timeout: 5000
|
32
|
+
pool: 5
|
33
|
+
|
34
|
+
Create a `db/migrate` directory:
|
35
|
+
|
36
|
+
$ mkdir -p db/migrate
|
37
|
+
|
38
|
+
Edit your `Gemfile` to specify a specific version of Activerecord.
|
39
|
+
It is recommeended you do this so that your project is always in a known state:
|
40
|
+
|
41
|
+
gem 'activerecord', '3.2.17', :require => 'active_record'
|
42
|
+
|
43
|
+
## Usage
|
44
|
+
|
45
|
+
Create your database:
|
46
|
+
|
47
|
+
$ bundle exec totem db create
|
48
|
+
|
49
|
+
Drop your database:
|
50
|
+
|
51
|
+
$ bundle exec totem db drop
|
52
|
+
|
53
|
+
Migrate your database:
|
54
|
+
|
55
|
+
$ bundle exec totem db migrate
|
56
|
+
|
57
|
+
Rollback your database (one migration back):
|
58
|
+
|
59
|
+
$ bundle exec totem db rollback
|
60
|
+
|
61
|
+
## Migrations
|
62
|
+
|
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.
|
65
|
+
|
66
|
+
Example migration `db/migrate/20140312221052_create_users.rb`:
|
67
|
+
|
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
|
76
|
+
|
77
|
+
## Models
|
78
|
+
|
79
|
+
You will need to manually create models in the `app` directory or a sub-directory.
|
80
|
+
|
81
|
+
Example model `app/user.rb` to go with the above migration:
|
82
|
+
|
83
|
+
class User < ActiveRecord::Base
|
84
|
+
end
|
85
|
+
|
86
|
+
Rember to add the model to the `app/loader.rb` just like you do with all classes in a Totem project:
|
87
|
+
|
88
|
+
require 'user'
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
1. Fork it ( http://github.com/<my-github-username>/totem_activerecord/fork )
|
93
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
94
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
95
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
96
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
desc 'Start a Totem interactive console (with Activerecord)'
|
4
|
+
task :console do
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
6
|
+
|
7
|
+
require 'irb'
|
8
|
+
|
9
|
+
require 'totem'
|
10
|
+
require 'totem_activerecord'
|
11
|
+
|
12
|
+
ARGV.clear
|
13
|
+
IRB.start
|
14
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module TotemActiverecord
|
2
|
+
module ShellCmds
|
3
|
+
class Db < Totem::ShellCmds::Base
|
4
|
+
def run
|
5
|
+
case @args[0]
|
6
|
+
when 'create' then create
|
7
|
+
when 'drop' then drop
|
8
|
+
when 'migrate' then migrate
|
9
|
+
when 'rollback' then rollback
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def create
|
14
|
+
ActiveRecord::Base.establish_connection(TotemActiverecord.config.merge('database' => nil))
|
15
|
+
ActiveRecord::Base.connection.create_database(TotemActiverecord.config['database'])
|
16
|
+
ActiveRecord::Base.establish_connection(TotemActiverecord.config)
|
17
|
+
|
18
|
+
return true
|
19
|
+
end
|
20
|
+
|
21
|
+
def drop
|
22
|
+
ActiveRecord::Base.connection.drop_database(TotemActiverecord.config['database'])
|
23
|
+
|
24
|
+
return true
|
25
|
+
end
|
26
|
+
|
27
|
+
def migrate
|
28
|
+
ActiveRecord::Migration.verbose = true
|
29
|
+
ActiveRecord::Migrator.migrate(TotemActiverecord.migrations_path)
|
30
|
+
|
31
|
+
TotemActiverecord.reconnect
|
32
|
+
|
33
|
+
return true
|
34
|
+
end
|
35
|
+
|
36
|
+
def rollback
|
37
|
+
ActiveRecord::Migrator.rollback(TotemActiverecord.migrations_path, 1)
|
38
|
+
TotemActiverecord.reconnect
|
39
|
+
|
40
|
+
return true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
Totem::Shell.register_cmd(:db, TotemActiverecord::ShellCmds::Db)
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'totem'
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
require 'totem_activerecord/version'
|
5
|
+
require 'totem_activerecord/shell_cmds/db'
|
6
|
+
|
7
|
+
module TotemActiverecord
|
8
|
+
def self.config_path
|
9
|
+
return File.join(Totem.root, 'config', 'database.yml')
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.migrations_path
|
13
|
+
return File.join(Totem.root, 'db', 'migrate')
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.config
|
17
|
+
return (@config ||= YAML.load_file(config_path)[Totem.env])
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.connect
|
21
|
+
return false if connected?
|
22
|
+
|
23
|
+
begin
|
24
|
+
ActiveRecord::Base.establish_connection(TotemActiverecord.config)
|
25
|
+
rescue Exception => e
|
26
|
+
puts "Failed to establish DB connection: #{e.message}\n#{e.backtrace.join("\n")}"
|
27
|
+
return false
|
28
|
+
end
|
29
|
+
|
30
|
+
return true
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.disconnect
|
34
|
+
return false unless connected?
|
35
|
+
|
36
|
+
ActiveRecord::Base.connection_pool.disconnect!
|
37
|
+
|
38
|
+
return true
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.reconnect
|
42
|
+
disconnect
|
43
|
+
connect
|
44
|
+
|
45
|
+
return true
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.connected?
|
49
|
+
return !!ActiveRecord::Base.connected?
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
Totem.register_callback(:before_load_app) { TotemActiverecord.connect }
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'totem_activerecord/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "totem_activerecord"
|
8
|
+
spec.version = TotemActiverecord::VERSION
|
9
|
+
spec.authors = ["Chad Remesch"]
|
10
|
+
spec.email = ["chad@remesch.com"]
|
11
|
+
spec.summary = %q{ActiveRecord add-on for the Totem gem.}
|
12
|
+
spec.description = %q{Add an easy to use ORM to your Totem based applications.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency("totem")
|
22
|
+
spec.add_dependency("activerecord")
|
23
|
+
|
24
|
+
spec.add_development_dependency("bundler", "~> 1.5")
|
25
|
+
spec.add_development_dependency("rake")
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: totem_activerecord
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chad Remesch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: totem
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Add an easy to use ORM to your Totem based applications.
|
70
|
+
email:
|
71
|
+
- chad@remesch.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/totem_activerecord.rb
|
82
|
+
- lib/totem_activerecord/shell_cmds/db.rb
|
83
|
+
- lib/totem_activerecord/version.rb
|
84
|
+
- totem_activerecord.gemspec
|
85
|
+
homepage: ''
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.2.2
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: ActiveRecord add-on for the Totem gem.
|
109
|
+
test_files: []
|