totem 0.0.1 → 0.0.3
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 +2 -0
- data/README.md +8 -4
- data/Rakefile +2 -5
- data/bin/totem +5 -0
- data/lib/totem.rb +23 -85
- data/lib/totem/shell.rb +36 -0
- data/lib/totem/shell_cmds/base.rb +13 -0
- data/lib/totem/shell_cmds/console.rb +14 -0
- data/lib/totem/shell_cmds/new.rb +52 -0
- data/lib/totem/version.rb +1 -1
- data/templates/Gemfile.erb +3 -0
- data/templates/app/loader.rb.erb +2 -0
- data/templates/config/environment.rb.erb +7 -0
- data/totem.gemspec +2 -5
- metadata +21 -52
- data/lib/totem/actable.rb +0 -9
- data/lib/totem/connection.rb +0 -13
- data/lib/totem/tasks/console.rb +0 -10
- data/lib/totem/tasks/database.rb +0 -68
- data/lib/totem/tasks/generator.rb +0 -29
- data/lib/totem/tcp_server.rb +0 -13
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c7dd860951dbcc374badc7017f380f07a8aa36d1
|
4
|
+
data.tar.gz: 5e81108d1c625256ddefe12d65b312ba7035d33c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3f0a3b77364746a25eb863f7238401c67a0c850520084bf81a0c4d5eac1f3cbb8020624864c32f982a788f9eb8766fa798347bdd9202ff1ac4d3b3c5e0ed46d3
|
7
|
+
data.tar.gz: 2bdba58062c6acea84cb16b5a636a8872d5c67a92ad55b8bc6701b245415044c9f24150e34d46e1bc1aeed096f01eddbf3c16f6f71d867c04a62aeede8347527
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
# Totem
|
2
2
|
|
3
|
-
Totem is a framework for
|
4
|
-
|
3
|
+
Totem is a framework for creating Ruby projects.
|
4
|
+
It's like having a Rails project folder without the Rails dependency.
|
5
5
|
|
6
6
|
Features:
|
7
7
|
- Ruby on Rails inspired folder structure.
|
8
|
-
-
|
9
|
-
- Generators for database migrations.
|
8
|
+
- Lightweight and simple code.
|
10
9
|
- Integrated console.
|
10
|
+
- Uses built in Ruby classes and avoids depending on 3rd party gems.
|
11
11
|
- Designed for MRI and JRuby.
|
12
|
+
- Easily extensible through gems or directly in your project.
|
13
|
+
- ActiveRecord (coming soon).
|
14
|
+
- Tribe (coming soon).
|
15
|
+
- Designed for multi-threaded applications.
|
12
16
|
|
13
17
|
## Installation
|
14
18
|
|
data/Rakefile
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
|
3
|
-
desc 'Start
|
3
|
+
desc 'Start a Totem interactive console'
|
4
4
|
task :console do
|
5
5
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
6
6
|
|
7
7
|
require 'totem'
|
8
|
-
require 'irb'
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
IRB.start
|
9
|
+
Totem::Shell.new([:console]).run
|
13
10
|
end
|
data/bin/totem
ADDED
data/lib/totem.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
|
-
require '
|
2
|
-
require 'tribe_em'
|
1
|
+
require 'logger'
|
3
2
|
|
4
3
|
require 'totem/version'
|
5
|
-
require 'totem/
|
6
|
-
require 'totem/
|
7
|
-
require 'totem/
|
8
|
-
require 'totem/
|
9
|
-
require 'totem/connection'
|
10
|
-
require 'totem/tcp_server'
|
4
|
+
require 'totem/shell'
|
5
|
+
require 'totem/shell_cmds/base'
|
6
|
+
require 'totem/shell_cmds/console'
|
7
|
+
require 'totem/shell_cmds/new'
|
11
8
|
|
12
9
|
module Totem
|
13
10
|
def self.initialize(root)
|
@@ -15,10 +12,8 @@ module Totem
|
|
15
12
|
|
16
13
|
@setup = true
|
17
14
|
@root = root
|
18
|
-
|
19
15
|
Bundler.require(Totem.env.to_sym)
|
20
|
-
|
21
|
-
db_connect
|
16
|
+
$LOAD_PATH.unshift(root + '/app')
|
22
17
|
load_app
|
23
18
|
|
24
19
|
return true
|
@@ -29,79 +24,19 @@ module Totem
|
|
29
24
|
end
|
30
25
|
|
31
26
|
def self.env
|
32
|
-
return (@env ||= (ENV['
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.settings
|
36
|
-
return @settings if @settings
|
37
|
-
|
38
|
-
begin
|
39
|
-
@settings = Fiona::Settings.new do |s|
|
40
|
-
eval(File.read(File.join(root, 'config', 'settings.rb')))
|
41
|
-
end
|
42
|
-
rescue Exception => e
|
43
|
-
puts "Failed to initialize settings: #{e.message}\n#{e.backtrace.join("\n")}"
|
44
|
-
end
|
45
|
-
|
46
|
-
return @settings
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.db_config
|
50
|
-
return (@db_config ||= YAML.load_file(File.join(root, 'config', 'database.yml'))[env])
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.db_connect
|
54
|
-
return false if db_connected?
|
55
|
-
|
56
|
-
begin
|
57
|
-
ActiveRecord::Base.establish_connection(Totem.db_config)
|
58
|
-
rescue Exception => e
|
59
|
-
puts "Failed to establish DB connection: #{e.message}\n#{e.backtrace.join("\n")}"
|
60
|
-
return false
|
61
|
-
end
|
62
|
-
|
63
|
-
return true
|
64
|
-
end
|
65
|
-
|
66
|
-
def self.db_disconnect
|
67
|
-
return false unless db_connected?
|
68
|
-
|
69
|
-
ActiveRecord::Base.connection_pool.disconnect!
|
70
|
-
|
71
|
-
return true
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.db_reconnect
|
75
|
-
db_disconnect
|
76
|
-
db_connect
|
77
|
-
|
78
|
-
return true
|
79
|
-
end
|
80
|
-
|
81
|
-
def self.db_connected?
|
82
|
-
return !!ActiveRecord::Base.connected?
|
27
|
+
return (@env ||= (ENV['TOTEM_ENV'] || 'development'))
|
83
28
|
end
|
84
29
|
|
85
30
|
def self.load_app
|
86
|
-
|
87
|
-
load("loader.rb")
|
88
|
-
Dir.chdir(Totem.root)
|
31
|
+
require "#{Totem.root}/app/loader.rb"
|
89
32
|
end
|
90
33
|
|
91
34
|
def self.component
|
92
|
-
return @component
|
93
|
-
end
|
94
|
-
|
95
|
-
def self.component=(val)
|
96
|
-
return @component = val
|
35
|
+
return @component ||= ENV['TOTEM_COMPONENT']
|
97
36
|
end
|
98
37
|
|
99
38
|
def self.instance
|
100
|
-
return @instance ||
|
101
|
-
end
|
102
|
-
|
103
|
-
def self.instance=(val)
|
104
|
-
return @instance = val
|
39
|
+
return @instance || ENV['TOTEM_INSTANCE']
|
105
40
|
end
|
106
41
|
|
107
42
|
def self.logger=(val)
|
@@ -111,14 +46,7 @@ module Totem
|
|
111
46
|
def self.logger
|
112
47
|
return @logger if @logger
|
113
48
|
|
114
|
-
|
115
|
-
when 'development'
|
116
|
-
log_to_stdout
|
117
|
-
when 'production'
|
118
|
-
log_to_file
|
119
|
-
else
|
120
|
-
log_to_stdout
|
121
|
-
end
|
49
|
+
log_to_file
|
122
50
|
|
123
51
|
return @logger
|
124
52
|
end
|
@@ -129,15 +57,25 @@ module Totem
|
|
129
57
|
return nil
|
130
58
|
end
|
131
59
|
|
60
|
+
def self.log_file_path
|
61
|
+
name = env
|
62
|
+
name << "_#{component}" if component && component.length > 0
|
63
|
+
name << "_#{instance}" if instance && instance.length > 0
|
64
|
+
name << '.log'
|
65
|
+
|
66
|
+
return File.join(root, 'log', name)
|
67
|
+
end
|
68
|
+
|
132
69
|
def self.log_to_file
|
133
|
-
init_logger(
|
70
|
+
init_logger(log_file_path)
|
134
71
|
|
135
72
|
return nil
|
136
73
|
end
|
137
74
|
|
138
75
|
def self.init_logger(output)
|
139
|
-
@logger
|
76
|
+
raise 'Logger is already initialized' if @logger
|
140
77
|
|
78
|
+
@logger = Logger.new(output)
|
141
79
|
@logger.formatter = proc do |severity, datetime, progname, msg|
|
142
80
|
"#{datetime} :: #{msg}\n"
|
143
81
|
end
|
data/lib/totem/shell.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Totem
|
2
|
+
class Shell
|
3
|
+
@cmds = {}
|
4
|
+
|
5
|
+
def self.register_cmd(cmd, klass)
|
6
|
+
@cmds[cmd.to_sym] = klass
|
7
|
+
|
8
|
+
return nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(args)
|
12
|
+
@args = args
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
if @args[0].nil?
|
17
|
+
puts "Usage:\n totem <command>"
|
18
|
+
puts
|
19
|
+
puts "Commands:\n #{self.class.cmds.keys.join(', ')}"
|
20
|
+
return
|
21
|
+
end
|
22
|
+
|
23
|
+
cmd_to_class(@args[0]).new(@args[1..-1]).run
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def self.cmds
|
29
|
+
return @cmds
|
30
|
+
end
|
31
|
+
|
32
|
+
def cmd_to_class(cmd)
|
33
|
+
return self.class.cmds[cmd.to_sym] || raise("Unknown cmd: #{cmd}")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module Totem
|
4
|
+
module ShellCmds
|
5
|
+
class New < Totem::ShellCmds::Base
|
6
|
+
def run
|
7
|
+
if @args[0].nil?
|
8
|
+
puts "You must provide a name for the new project."
|
9
|
+
return
|
10
|
+
end
|
11
|
+
|
12
|
+
root_path = @args[0]
|
13
|
+
|
14
|
+
puts 'Creating project root directory...'
|
15
|
+
Dir.mkdir(root_path)
|
16
|
+
puts
|
17
|
+
|
18
|
+
puts 'Creating sub-directories...'
|
19
|
+
%w(app config log tmp).each do |dir|
|
20
|
+
puts " #{dir}..."
|
21
|
+
Dir.mkdir(root_path + '/' + dir)
|
22
|
+
end
|
23
|
+
puts
|
24
|
+
|
25
|
+
template_path = File.expand_path(File.dirname(__FILE__) + '/../../../templates')
|
26
|
+
|
27
|
+
puts 'Creating Gemfile...'
|
28
|
+
input = File.read(template_path + '/Gemfile.erb')
|
29
|
+
output = ERB.new(input).result(binding)
|
30
|
+
File.open(root_path + '/Gemfile', 'w') { |f| f.write(output) }
|
31
|
+
puts
|
32
|
+
|
33
|
+
puts 'Creating config/environment.rb...'
|
34
|
+
input = File.read(template_path + '/config/environment.rb.erb')
|
35
|
+
output = ERB.new(input).result(binding)
|
36
|
+
File.open(root_path + '/config/environment.rb', 'w') { |f| f.write(output) }
|
37
|
+
puts
|
38
|
+
|
39
|
+
puts 'Creating app/loader.rb...'
|
40
|
+
input = File.read(template_path + '/app/loader.rb.erb')
|
41
|
+
output = ERB.new(input).result(binding)
|
42
|
+
File.open(root_path + '/app/loader.rb', 'w') { |f| f.write(output) }
|
43
|
+
puts
|
44
|
+
|
45
|
+
puts 'Finished! You must now run "bundle update" inside your project directory.'
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
Totem::Shell.register_cmd(:new, Totem::ShellCmds::New)
|
data/lib/totem/version.rb
CHANGED
data/totem.gemspec
CHANGED
@@ -8,15 +8,12 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Totem::VERSION
|
9
9
|
gem.authors = ['Chad Remesch']
|
10
10
|
gem.email = ['chad@remesch.com']
|
11
|
-
gem.description = %q{
|
12
|
-
gem.summary = %q{
|
11
|
+
gem.description = %q{Totem is a framework for creating Ruby projects.}
|
12
|
+
gem.summary = %q{It's like having a Rails project folder without the Rails dependency.}
|
13
13
|
gem.homepage = 'https://github.com/chadrem/totem'
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
|
-
|
20
|
-
gem.add_dependency('tribe', '0.0.8')
|
21
|
-
gem.add_dependency('tribe_em', '0.0.2')
|
22
19
|
end
|
metadata
CHANGED
@@ -1,91 +1,60 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: totem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Chad Remesch
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
14
|
-
|
15
|
-
name: tribe
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - '='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 0.0.8
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - '='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 0.0.8
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: tribe_em
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - '='
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 0.0.2
|
38
|
-
type: :runtime
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - '='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 0.0.2
|
46
|
-
description: The Totem framework.
|
11
|
+
date: 2014-03-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Totem is a framework for creating Ruby projects.
|
47
14
|
email:
|
48
15
|
- chad@remesch.com
|
49
|
-
executables:
|
16
|
+
executables:
|
17
|
+
- totem
|
50
18
|
extensions: []
|
51
19
|
extra_rdoc_files: []
|
52
20
|
files:
|
53
|
-
- .gitignore
|
21
|
+
- ".gitignore"
|
54
22
|
- Gemfile
|
55
23
|
- LICENSE.txt
|
56
24
|
- README.md
|
57
25
|
- Rakefile
|
26
|
+
- bin/totem
|
58
27
|
- lib/totem.rb
|
59
|
-
- lib/totem/
|
60
|
-
- lib/totem/
|
61
|
-
- lib/totem/
|
62
|
-
- lib/totem/
|
63
|
-
- lib/totem/tasks/generator.rb
|
64
|
-
- lib/totem/tcp_server.rb
|
28
|
+
- lib/totem/shell.rb
|
29
|
+
- lib/totem/shell_cmds/base.rb
|
30
|
+
- lib/totem/shell_cmds/console.rb
|
31
|
+
- lib/totem/shell_cmds/new.rb
|
65
32
|
- lib/totem/version.rb
|
33
|
+
- templates/Gemfile.erb
|
34
|
+
- templates/app/loader.rb.erb
|
35
|
+
- templates/config/environment.rb.erb
|
66
36
|
- totem.gemspec
|
67
37
|
homepage: https://github.com/chadrem/totem
|
68
38
|
licenses: []
|
39
|
+
metadata: {}
|
69
40
|
post_install_message:
|
70
41
|
rdoc_options: []
|
71
42
|
require_paths:
|
72
43
|
- lib
|
73
44
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
45
|
requirements:
|
76
|
-
- -
|
46
|
+
- - ">="
|
77
47
|
- !ruby/object:Gem::Version
|
78
48
|
version: '0'
|
79
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
-
none: false
|
81
50
|
requirements:
|
82
|
-
- -
|
51
|
+
- - ">="
|
83
52
|
- !ruby/object:Gem::Version
|
84
53
|
version: '0'
|
85
54
|
requirements: []
|
86
55
|
rubyforge_project:
|
87
|
-
rubygems_version:
|
56
|
+
rubygems_version: 2.2.2
|
88
57
|
signing_key:
|
89
|
-
specification_version:
|
90
|
-
summary:
|
58
|
+
specification_version: 4
|
59
|
+
summary: It's like having a Rails project folder without the Rails dependency.
|
91
60
|
test_files: []
|
data/lib/totem/actable.rb
DELETED
data/lib/totem/connection.rb
DELETED
data/lib/totem/tasks/console.rb
DELETED
data/lib/totem/tasks/database.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
module Totem
|
2
|
-
module Tasks
|
3
|
-
class Database
|
4
|
-
def initialize
|
5
|
-
@config = Totem.db_config.clone
|
6
|
-
end
|
7
|
-
|
8
|
-
def create
|
9
|
-
options = { :charset => 'utf8', :collation => 'utf8_unicode_ci' }
|
10
|
-
|
11
|
-
create_db = lambda do |config|
|
12
|
-
ActiveRecord::Base.establish_connection(config.merge('database' => nil))
|
13
|
-
ActiveRecord::Base.connection.create_database(config['database'], options)
|
14
|
-
ActiveRecord::Base.establish_connection(config)
|
15
|
-
end
|
16
|
-
|
17
|
-
begin
|
18
|
-
create_db.call(@config)
|
19
|
-
rescue Mysql::Error => sqlerr
|
20
|
-
if sqlerr.errno == 1405
|
21
|
-
print "#{sqlerr.error}. \nPlease provide the root password for your mysql installation\n>"
|
22
|
-
root_password = $stdin.gets.strip
|
23
|
-
|
24
|
-
grant_statement = <<-SQL
|
25
|
-
GRANT ALL PRIVILEGES ON #{config['database']}.*
|
26
|
-
TO '#{config['username']}'@'localhost'
|
27
|
-
IDENTIFIED BY '#{config['password']}' WITH GRANT OPTION;
|
28
|
-
SQL
|
29
|
-
|
30
|
-
create_db.call(@config.merge('database' => nil, 'username' => 'root', 'password' => root_password))
|
31
|
-
else
|
32
|
-
$stderr.puts sqlerr.error
|
33
|
-
$stderr.puts "Couldn't create database for #{config.inspect}, charset: utf8, collation: utf8_unicode_ci"
|
34
|
-
$stderr.puts "(if you set the charset manually, make sure you have a matching collation)" if config['charset']
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
Totem.db_reconnect
|
39
|
-
|
40
|
-
return true
|
41
|
-
end
|
42
|
-
|
43
|
-
def drop
|
44
|
-
ActiveRecord::Base.connection.drop_database(@config['database'])
|
45
|
-
|
46
|
-
return true
|
47
|
-
end
|
48
|
-
|
49
|
-
def migrate
|
50
|
-
ActiveRecord::Migration.verbose = true
|
51
|
-
ActiveRecord::Migrator.migrate('db/migrate', ENV['VERSION'] ? ENV['VERSION'].to_i : nil)
|
52
|
-
|
53
|
-
Totem.db_reconnect
|
54
|
-
|
55
|
-
return true
|
56
|
-
end
|
57
|
-
|
58
|
-
def rollback
|
59
|
-
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
60
|
-
ActiveRecord::Migrator.rollback('db/migrate', step)
|
61
|
-
|
62
|
-
Totem.db_reconnect
|
63
|
-
|
64
|
-
return true
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module Totem
|
2
|
-
module Tasks
|
3
|
-
class Generator
|
4
|
-
def migration(name)
|
5
|
-
tstamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
|
6
|
-
fname = "#{tstamp}_#{name}.rb"
|
7
|
-
path = File.join(Totem.root, 'db', 'migrate', fname)
|
8
|
-
|
9
|
-
name || raise('You must specify a name')
|
10
|
-
|
11
|
-
puts "Creating migration: #{path}"
|
12
|
-
|
13
|
-
if File.exists?(path)
|
14
|
-
puts 'ERROR: File already exists.'
|
15
|
-
return
|
16
|
-
end
|
17
|
-
|
18
|
-
content = <<-EOS.unindent
|
19
|
-
class #{name.camelize} < ActiveRecord::Migration
|
20
|
-
end
|
21
|
-
EOS
|
22
|
-
|
23
|
-
File.open(path, 'w') { |f| f.write(content) }
|
24
|
-
|
25
|
-
return nil
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|