lamed 0.1.2 → 0.1.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.
- data/VERSION +1 -1
- data/lamed.gemspec +89 -0
- data/lib/lamed/controller.rb +10 -7
- data/lib/lamed/helper.rb +6 -3
- data/lib/lamed/initializer.rb +28 -28
- data/lib/lamed/main.rb +20 -1
- data/lib/lamed/model.rb +70 -0
- data/lib/lamed/object_loader.rb +70 -42
- data/lib/lamed.rb +1 -2
- data/spec/examples/conf/config.yml +2 -0
- data/spec/examples/config.ru +13 -0
- data/spec/examples/ext/controllers/hello_world.rb +9 -0
- data/spec/examples/ext/controllers/lamest/bar.rb +9 -0
- data/spec/examples/ext/controllers/lamest/foo.rb +9 -0
- data/spec/examples/ext/models/bar_model.rb +2 -0
- data/spec/examples/ext/models/foo_model.rb +2 -0
- data/spec/examples/ext/views/hello_world.mustache +1 -0
- data/spec/examples/ext/views/lamest/bar.mustache +1 -0
- data/spec/examples/ext/views/lamest/foo.mustache +1 -0
- data/spec/examples/lib/foo_lib.rb +2 -0
- data/spec/helpers_spec.rb +15 -0
- data/spec/initializer_spec.rb +10 -11
- data/spec/object_loader_spec.rb +51 -52
- metadata +22 -17
- data/lib/lamed/lib.rb +0 -15
- data/lib/lamed/mysql.rb +0 -59
- data/lib/lamed/record.rb +0 -20
- data/spec/fixtures/conf/config.yml +0 -13
- data/spec/fixtures/ext/controller/first_controller.rb +0 -3
- data/spec/fixtures/ext/controller/second/second_controller.rb +0 -2
- data/spec/fixtures/ext/controller/second/third_controller.rb +0 -2
- data/spec/fixtures/ext/record/bar_record.rb +0 -2
- data/spec/fixtures/ext/record/foo_record.rb +0 -2
- /data/spec/{fixtures → examples}/conf/database.yml +0 -0
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.3
|
data/lamed.gemspec
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Generated by jeweler
|
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
|
4
|
+
# -*- encoding: utf-8 -*-
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = %q{lamed}
|
|
8
|
+
s.version = "0.1.3"
|
|
9
|
+
|
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
+
s.authors = ["Lee Chang"]
|
|
12
|
+
s.date = %q{2010-01-19}
|
|
13
|
+
s.description = %q{Yet another LaMe Ruby Web Framework}
|
|
14
|
+
s.email = %q{leetchang@gmail.com}
|
|
15
|
+
s.extra_rdoc_files = [
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"README.rdoc"
|
|
18
|
+
]
|
|
19
|
+
s.files = [
|
|
20
|
+
".document",
|
|
21
|
+
".gitignore",
|
|
22
|
+
"LICENSE",
|
|
23
|
+
"README.rdoc",
|
|
24
|
+
"Rakefile",
|
|
25
|
+
"VERSION",
|
|
26
|
+
"lamed.gemspec",
|
|
27
|
+
"lib/lamed.rb",
|
|
28
|
+
"lib/lamed/controller.rb",
|
|
29
|
+
"lib/lamed/helper.rb",
|
|
30
|
+
"lib/lamed/initializer.rb",
|
|
31
|
+
"lib/lamed/main.rb",
|
|
32
|
+
"lib/lamed/model.rb",
|
|
33
|
+
"lib/lamed/object_loader.rb",
|
|
34
|
+
"lib/lamed/redis.rb",
|
|
35
|
+
"spec/examples/conf/config.yml",
|
|
36
|
+
"spec/examples/conf/database.yml",
|
|
37
|
+
"spec/examples/config.ru",
|
|
38
|
+
"spec/examples/ext/controllers/hello_world.rb",
|
|
39
|
+
"spec/examples/ext/controllers/lamest/bar.rb",
|
|
40
|
+
"spec/examples/ext/controllers/lamest/foo.rb",
|
|
41
|
+
"spec/examples/ext/models/bar_model.rb",
|
|
42
|
+
"spec/examples/ext/models/foo_model.rb",
|
|
43
|
+
"spec/examples/ext/views/hello_world.mustache",
|
|
44
|
+
"spec/examples/ext/views/lamest/bar.mustache",
|
|
45
|
+
"spec/examples/ext/views/lamest/foo.mustache",
|
|
46
|
+
"spec/examples/lib/foo_lib.rb",
|
|
47
|
+
"spec/helpers_spec.rb",
|
|
48
|
+
"spec/initializer_spec.rb",
|
|
49
|
+
"spec/lame_spec.rb",
|
|
50
|
+
"spec/object_loader_spec.rb",
|
|
51
|
+
"spec/spec.opts",
|
|
52
|
+
"spec/spec_helper.rb"
|
|
53
|
+
]
|
|
54
|
+
s.homepage = %q{http://github.com/onemorehill/lamed}
|
|
55
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
56
|
+
s.require_paths = ["lib"]
|
|
57
|
+
s.rubygems_version = %q{1.3.5}
|
|
58
|
+
s.summary = %q{Get LaMeD}
|
|
59
|
+
s.test_files = [
|
|
60
|
+
"spec/examples/ext/controllers/hello_world.rb",
|
|
61
|
+
"spec/examples/ext/controllers/lamest/bar.rb",
|
|
62
|
+
"spec/examples/ext/controllers/lamest/foo.rb",
|
|
63
|
+
"spec/examples/ext/models/bar_model.rb",
|
|
64
|
+
"spec/examples/ext/models/foo_model.rb",
|
|
65
|
+
"spec/examples/lib/foo_lib.rb",
|
|
66
|
+
"spec/helpers_spec.rb",
|
|
67
|
+
"spec/initializer_spec.rb",
|
|
68
|
+
"spec/lame_spec.rb",
|
|
69
|
+
"spec/object_loader_spec.rb",
|
|
70
|
+
"spec/spec_helper.rb"
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
if s.respond_to? :specification_version then
|
|
74
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
75
|
+
s.specification_version = 3
|
|
76
|
+
|
|
77
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
78
|
+
s.add_development_dependency(%q<rack>, [">= 1.0"])
|
|
79
|
+
s.add_development_dependency(%q<mustache>, [">= 0"])
|
|
80
|
+
else
|
|
81
|
+
s.add_dependency(%q<rack>, [">= 1.0"])
|
|
82
|
+
s.add_dependency(%q<mustache>, [">= 0"])
|
|
83
|
+
end
|
|
84
|
+
else
|
|
85
|
+
s.add_dependency(%q<rack>, [">= 1.0"])
|
|
86
|
+
s.add_dependency(%q<mustache>, [">= 0"])
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
data/lib/lamed/controller.rb
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
require 'mustache'
|
|
2
|
+
|
|
1
3
|
module Lamed
|
|
2
|
-
|
|
3
4
|
class Controller < Mustache
|
|
4
5
|
|
|
5
6
|
include Rack
|
|
6
7
|
include Lamed::Helper
|
|
7
8
|
extend Lamed::Helper
|
|
8
|
-
include Lamed::
|
|
9
|
-
include Lamed::Lib
|
|
9
|
+
include Lamed::Model
|
|
10
10
|
|
|
11
11
|
attr_accessor :query, :path, :self_path, :env
|
|
12
12
|
|
|
@@ -38,6 +38,7 @@ module Lamed
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def call(env)
|
|
41
|
+
@env = env
|
|
41
42
|
env[:query] = self.parse_query_string(env['QUERY_STRING'])
|
|
42
43
|
env[:path] = self.parse_uri(env['SCRIPT_NAME'])
|
|
43
44
|
response(env)
|
|
@@ -56,10 +57,12 @@ module Lamed
|
|
|
56
57
|
return @req_params
|
|
57
58
|
end
|
|
58
59
|
|
|
59
|
-
def content_type(
|
|
60
|
-
@req_params[:content_type] =
|
|
60
|
+
def content_type(content_type)
|
|
61
|
+
@req_params[:content_type] = content_type
|
|
61
62
|
end
|
|
62
|
-
|
|
63
|
-
end
|
|
64
63
|
|
|
64
|
+
def user_agent
|
|
65
|
+
@env['HTTP_USER_AGENT']
|
|
66
|
+
end
|
|
67
|
+
end
|
|
65
68
|
end
|
data/lib/lamed/helper.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
module Lamed
|
|
2
2
|
|
|
3
3
|
module Helper
|
|
4
|
-
|
|
5
4
|
# -=-=-=-= Hash Helper =-=-=-=-
|
|
6
5
|
# Changes keys that are strings in symbols. Goes two deep.
|
|
7
6
|
def symbolize_hash_keys(hash = self)
|
|
@@ -39,6 +38,12 @@ module Lamed
|
|
|
39
38
|
return path
|
|
40
39
|
end
|
|
41
40
|
|
|
41
|
+
def class_to_path(klass)
|
|
42
|
+
klass_str = klass.to_s.split("::").collect { |s| uncamelize_string s }
|
|
43
|
+
klass_path = File.join("/", klass_str)
|
|
44
|
+
return klass_path
|
|
45
|
+
end
|
|
46
|
+
|
|
42
47
|
# Convert strings into a usable MySQL time object.
|
|
43
48
|
def mysql_time(str)
|
|
44
49
|
str[/(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+)/]
|
|
@@ -82,7 +87,5 @@ module Lamed
|
|
|
82
87
|
}
|
|
83
88
|
return new_hash
|
|
84
89
|
end
|
|
85
|
-
|
|
86
90
|
end
|
|
87
|
-
|
|
88
91
|
end
|
data/lib/lamed/initializer.rb
CHANGED
|
@@ -8,7 +8,6 @@ require 'lib/lamed/object_loader'
|
|
|
8
8
|
|
|
9
9
|
module Lamed
|
|
10
10
|
|
|
11
|
-
|
|
12
11
|
# Build configurations from yaml files
|
|
13
12
|
if defined?(ROOT)
|
|
14
13
|
OPTIONS = {
|
|
@@ -28,38 +27,42 @@ module Lamed
|
|
|
28
27
|
@sys_options = SYS_OPTIONS
|
|
29
28
|
log_path =@sys_options[:logs] || OPTIONS[:log_path]
|
|
30
29
|
OPTIONS[:rotate] = !@sys_options.nil? ? @sys_options[:rotate] : nil
|
|
31
|
-
|
|
30
|
+
@log_path = File.join(log_path, OPTIONS[:env].to_s + ".log")
|
|
32
31
|
end
|
|
33
32
|
end
|
|
34
33
|
|
|
35
34
|
class << self
|
|
36
|
-
|
|
37
35
|
# Set up logging
|
|
38
36
|
def initialize_logger
|
|
39
37
|
if defined?(SYS_OPTIONS)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
begin
|
|
39
|
+
logs = Logger.new(@log_path, OPTIONS[:rotate])
|
|
40
|
+
case OPTIONS[:env]
|
|
41
|
+
when :development
|
|
42
|
+
logs.level = Logger::DEBUG
|
|
43
|
+
when :test
|
|
44
|
+
logs.level = Logger::DEBUG
|
|
45
|
+
when :staging
|
|
46
|
+
logs.level = Logger::DEBUG
|
|
47
|
+
when :production
|
|
48
|
+
logs.level = Logger::WARN
|
|
49
|
+
end
|
|
50
|
+
rescue
|
|
51
|
+
logs = nil
|
|
50
52
|
end
|
|
51
|
-
|
|
53
|
+
end
|
|
54
|
+
if logs.nil?
|
|
55
|
+
puts "The log path #{@log_path} does not exist or is not writable."
|
|
56
|
+
puts "Log messages will be sent to STANDARD ERROR"
|
|
52
57
|
logs = Logger.new(STDERR)
|
|
53
58
|
end
|
|
54
|
-
puts "The log path does not exist or is not writable. Log messages will be sent to STANDARD ERROR"
|
|
55
59
|
@logger = logs
|
|
56
|
-
logs.warn("Logging level is set to #{
|
|
60
|
+
logs.warn("Logging level is set to #{@logger.level}")
|
|
57
61
|
return @logger
|
|
58
62
|
end
|
|
59
63
|
|
|
60
64
|
if defined?(ROOT)
|
|
61
|
-
require 'lib/lamed/
|
|
62
|
-
require 'lib/lamed/lib'
|
|
65
|
+
require 'lib/lamed/model'
|
|
63
66
|
end
|
|
64
67
|
|
|
65
68
|
def logger
|
|
@@ -67,27 +70,24 @@ module Lamed
|
|
|
67
70
|
end
|
|
68
71
|
|
|
69
72
|
def load_lib
|
|
70
|
-
|
|
71
|
-
lib = LoadObjects.new(ROOT, :lib)
|
|
72
|
-
lib.build_path_hash
|
|
73
|
-
lib.build_objects
|
|
73
|
+
Dir[ROOT + '/lib/**/*.rb'].each {|f| load f}
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
def load_controller
|
|
77
|
-
ObjectLoader.
|
|
77
|
+
ObjectLoader.load_controller_object
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
def
|
|
81
|
-
|
|
80
|
+
def load_model
|
|
81
|
+
ObjectLoader.load_model_object
|
|
82
82
|
end
|
|
83
|
-
|
|
84
83
|
end
|
|
85
84
|
|
|
86
85
|
if defined?(SYS_OPTIONS)
|
|
87
|
-
|
|
86
|
+
load_model
|
|
88
87
|
require 'lib/lamed/controller'
|
|
89
88
|
load_controller
|
|
89
|
+
load_lib
|
|
90
90
|
end
|
|
91
91
|
initialize_logger
|
|
92
|
-
|
|
92
|
+
|
|
93
93
|
end
|
data/lib/lamed/main.rb
CHANGED
|
@@ -2,8 +2,27 @@ require 'rack'
|
|
|
2
2
|
require 'rack/builder'
|
|
3
3
|
require 'logger'
|
|
4
4
|
|
|
5
|
-
module
|
|
5
|
+
module Lamed
|
|
6
6
|
|
|
7
7
|
require 'lib/lamed/initializer'
|
|
8
8
|
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
module Rack
|
|
12
|
+
|
|
13
|
+
class Builder
|
|
14
|
+
|
|
15
|
+
include Lamed
|
|
16
|
+
|
|
17
|
+
def run_apps
|
|
18
|
+
use Rack::Lint
|
|
19
|
+
ObjectLoader.mapped_class.each_pair do |path, klass|
|
|
20
|
+
map path do
|
|
21
|
+
run klass.new
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
9
28
|
end
|
data/lib/lamed/model.rb
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'mysql'
|
|
2
|
+
require 'lib/lamed/redis'
|
|
3
|
+
|
|
4
|
+
module Lamed
|
|
5
|
+
|
|
6
|
+
module Model
|
|
7
|
+
|
|
8
|
+
#include Lamed
|
|
9
|
+
|
|
10
|
+
LAME_ROOT = ::LAME_ROOT unless defined?(LAME_ROOT)
|
|
11
|
+
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class MySQL < Mysql
|
|
15
|
+
|
|
16
|
+
attr_reader :status, :db_conn, :db_conn_read, :params
|
|
17
|
+
|
|
18
|
+
def initialize(params = {})
|
|
19
|
+
@params = params
|
|
20
|
+
@host = params[:host] || '127.0.0.1'
|
|
21
|
+
@port = (params[:port] || 3306).to_i
|
|
22
|
+
@user = params[:username] || 'root'
|
|
23
|
+
@password = params[:password] || 'pwd'
|
|
24
|
+
@database = params[:database]
|
|
25
|
+
@read_host = params[:read_host]
|
|
26
|
+
@read_username = params[:read_user]
|
|
27
|
+
@read_password = params[:read_password]
|
|
28
|
+
@read_database = params[:read_password]
|
|
29
|
+
@read_port = params[:read_port]
|
|
30
|
+
self.connect
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def connect
|
|
34
|
+
$db_conn = Mysql.real_connect(@host, @user, @password, @database, @port)
|
|
35
|
+
# Check to make sure there is a read db in the configs
|
|
36
|
+
if @read_host
|
|
37
|
+
$db_conn_read = Mysql.real_connect(@read_host, @read_username, @read_password, @read_database, @read_port)
|
|
38
|
+
else
|
|
39
|
+
$db_conn_read = $db_conn
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.query(query_string)
|
|
44
|
+
n = 0 # track how many times the system had to reconnect to the db
|
|
45
|
+
begin
|
|
46
|
+
# Test to see if the query starts with a select which would mean it was a read query
|
|
47
|
+
if query_string.split[0].upcase == "SELECT"
|
|
48
|
+
res = $db_conn_read.query(query_string)
|
|
49
|
+
else
|
|
50
|
+
res = $db_conn.query(query_string)
|
|
51
|
+
end
|
|
52
|
+
rescue Mysql::Error => e
|
|
53
|
+
case e.to_s
|
|
54
|
+
when 'MySQL server has gone away'
|
|
55
|
+
MySQL.new($DB_OPTIONS)
|
|
56
|
+
n += 1
|
|
57
|
+
retry
|
|
58
|
+
when 'Lost connection to MySQL server during query'
|
|
59
|
+
MySQL.new($DB_OPTIONS)
|
|
60
|
+
n += 1
|
|
61
|
+
retry
|
|
62
|
+
else
|
|
63
|
+
# Don't know what to do because of an unknown error so to play it safe we'll just break instead looping endlessly.
|
|
64
|
+
raise "ERROR: #{e.to_s} Not sure what this error is from #{@host}."
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
return res
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
data/lib/lamed/object_loader.rb
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
ROOT = ::File.join(::File.dirname(__FILE__), '..') unless defined?(ROOT)
|
|
2
2
|
|
|
3
3
|
module Lamed
|
|
4
|
-
|
|
5
4
|
class ObjectLoader
|
|
6
5
|
|
|
6
|
+
ORIG_OBJECT_CONSTANTS = Object.constants.freeze
|
|
7
|
+
ROOT_EXT = File.join(ROOT, "/ext")
|
|
8
|
+
VIEW_PATH = File.join(ROOT_EXT, "/views")
|
|
9
|
+
file_pattern = "**/*.rb"
|
|
10
|
+
|
|
11
|
+
FILE_FILTER = {
|
|
12
|
+
:model => File.join(ROOT_EXT, "/models", file_pattern),
|
|
13
|
+
:controller => File.join(ROOT_EXT, "/controllers", file_pattern),
|
|
14
|
+
:view => File.join(ROOT_EXT, "/views", file_pattern)
|
|
15
|
+
}
|
|
16
|
+
|
|
7
17
|
class << self
|
|
8
18
|
|
|
9
|
-
include Lamed
|
|
10
|
-
|
|
19
|
+
include Lamed
|
|
20
|
+
include Helper
|
|
21
|
+
extend Helper
|
|
22
|
+
|
|
23
|
+
attr_reader :mapped_class
|
|
11
24
|
|
|
12
25
|
# Load objects in this order:
|
|
13
26
|
# Libraries - Lib
|
|
14
|
-
# Records or models -
|
|
27
|
+
# Records or models - Model
|
|
15
28
|
# Controllers or apps - Controller
|
|
16
|
-
|
|
17
|
-
ORIG_OBJECT_CONSTANTS = Object.constants.freeze
|
|
18
|
-
ROOT_EXT = File.join(ROOT, "/ext")
|
|
19
|
-
VIEW_PATH = File.join(ROOT_EXT, "/view")
|
|
20
|
-
FILE_PATTERN = "**/*.rb"
|
|
21
|
-
|
|
22
|
-
FILE_FILTER = {
|
|
23
|
-
:record => File.join(ROOT_EXT, "/record", FILE_PATTERN),
|
|
24
|
-
:controller => File.join(ROOT_EXT, "/controller", FILE_PATTERN),
|
|
25
|
-
:view => File.join(ROOT_EXT, "/view", FILE_PATTERN)
|
|
26
|
-
}
|
|
27
|
-
|
|
29
|
+
|
|
28
30
|
def get_files(type)
|
|
29
31
|
@paths = Dir.glob(FILE_FILTER[type])
|
|
30
32
|
end
|
|
@@ -41,21 +43,23 @@ module Lamed
|
|
|
41
43
|
end
|
|
42
44
|
|
|
43
45
|
def camelize_ext_subdir(subdir)
|
|
44
|
-
ext_subdir = subdir.split(ROOT_EXT)[1]
|
|
45
|
-
camelized_ext_subdir = camelize_path ext_subdir
|
|
46
|
+
ext_subdir = subdir.split(ROOT_EXT + "/controllers")[1]
|
|
47
|
+
camelized_ext_subdir = camelize_path ext_subdir if ext_subdir
|
|
46
48
|
return camelized_ext_subdir
|
|
47
49
|
end
|
|
48
50
|
|
|
49
51
|
def create_object_from_camelized_path(camelized_ext_subdir)
|
|
50
|
-
klass = Lamed
|
|
51
|
-
camelized_ext_subdir
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
klass = Lamed::Controller
|
|
53
|
+
if camelized_ext_subdir
|
|
54
|
+
camelized_ext_subdir.each do |symbol|
|
|
55
|
+
if klass.constants.include?(symbol)
|
|
56
|
+
klass_prime = klass.const_get(symbol)
|
|
57
|
+
else
|
|
58
|
+
klass_prime = klass.const_set(symbol, Module.new)
|
|
59
|
+
end
|
|
60
|
+
klass = klass_prime
|
|
56
61
|
end
|
|
57
|
-
|
|
58
|
-
}
|
|
62
|
+
end
|
|
59
63
|
return klass
|
|
60
64
|
end
|
|
61
65
|
|
|
@@ -68,39 +72,63 @@ module Lamed
|
|
|
68
72
|
end
|
|
69
73
|
|
|
70
74
|
def create_view_path(camelized_ext_subdir)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
view_path = File.join(ROOT_EXT, uncamelize_path(camelized_ext_subdir_prime))
|
|
75
|
+
camelized_ext_subdir_dup = camelized_ext_subdir.nil? ? [] : camelized_ext_subdir.dup
|
|
76
|
+
view_path = File.join(VIEW_PATH, uncamelize_path(camelized_ext_subdir_dup))
|
|
74
77
|
return view_path
|
|
75
78
|
end
|
|
76
79
|
|
|
77
|
-
# Load new
|
|
80
|
+
# Load new controller(s) into new klass(es) as defined by their path.
|
|
78
81
|
# First load the files then build the class/modules(klass) from the path.
|
|
79
|
-
# Then move the newly created objects into the newly built
|
|
82
|
+
# Then move the newly created objects into the newly built class.
|
|
80
83
|
# Finally, remove the newly loaded objects from Object.
|
|
81
|
-
# Change the path
|
|
82
|
-
def
|
|
84
|
+
# Change the +path=+ for the new controllers to the location of the mustache templates +VIEW_PATH+.
|
|
85
|
+
def load_controller_into_new_class(subdir, file_name)
|
|
83
86
|
orig_object_constants = Object.constants.dup
|
|
84
87
|
load_new_object(subdir, file_name)
|
|
85
88
|
camelized_ext_subdir = camelize_ext_subdir(subdir)
|
|
86
89
|
klass = create_object_from_camelized_path(camelized_ext_subdir)
|
|
87
90
|
view_path = create_view_path(camelized_ext_subdir)
|
|
88
|
-
(Object.constants - orig_object_constants).each
|
|
91
|
+
(Object.constants - orig_object_constants).each do |o|
|
|
89
92
|
o_klass = Object.const_get(o)
|
|
90
93
|
# Change path to mustache path location if it has the path method (Check for a Controller object)
|
|
91
|
-
o_klass.path = create_view_path(camelized_ext_subdir) if o_klass.respond_to?(
|
|
94
|
+
o_klass.path = create_view_path(camelized_ext_subdir) if o_klass.respond_to?(:path)
|
|
92
95
|
klass.const_set(o, o_klass)
|
|
93
|
-
Object.instance_eval { remove_const o }
|
|
94
|
-
|
|
96
|
+
Object.instance_eval { remove_const o }
|
|
97
|
+
complete_klass_str = klass.to_s + "::" + o_klass.to_s
|
|
98
|
+
map_new_class(complete_klass_str) if o_klass.respond_to?(:path)
|
|
99
|
+
end
|
|
95
100
|
end
|
|
96
101
|
|
|
97
|
-
|
|
98
|
-
|
|
102
|
+
# Create a new map for the Controller using Rack::Builder map
|
|
103
|
+
def map_new_class(klass_str)
|
|
104
|
+
path_prime = File.join(klass_str.split('::').collect { |s| uncamelize_string s })
|
|
105
|
+
path = path_prime.split('/controller').last
|
|
106
|
+
map_class_to_path(path, klass_str)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def map_class_to_path(path, klass_str)
|
|
110
|
+
@mapped_class = Hash.new unless defined?(@mapped_class)
|
|
111
|
+
@mapped_class[path] = eval(klass_str)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def load_controller_object
|
|
115
|
+
get_files(:controller)
|
|
99
116
|
map_file_to_subdir
|
|
100
|
-
@mapped_file.each_pair { |subdir, file_name|
|
|
117
|
+
@mapped_file.each_pair { |subdir, file_name| load_controller_into_new_class(subdir, file_name) }
|
|
101
118
|
end
|
|
102
|
-
|
|
119
|
+
|
|
120
|
+
# Load model(s)
|
|
121
|
+
def load_model_object
|
|
122
|
+
orig_object_constants = Object.constants.dup
|
|
123
|
+
klass = Lamed::Model
|
|
124
|
+
get_files(:model)
|
|
125
|
+
@paths.each { |f| load f }
|
|
126
|
+
(Object.constants - orig_object_constants).each do |o|
|
|
127
|
+
o_klass = Object.const_get(o)
|
|
128
|
+
klass.const_set(o, o_klass)
|
|
129
|
+
Object.instance_eval { remove_const o }
|
|
130
|
+
end
|
|
131
|
+
end
|
|
103
132
|
end
|
|
104
|
-
|
|
105
133
|
end
|
|
106
134
|
end
|
data/lib/lamed.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
lib_path = File.expand_path(File.dirname(__FILE__)) + "/../"
|
|
2
2
|
$LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
|
|
3
|
-
|
|
4
|
-
::LAME_ROOT = ::File.expand_path(::File.dirname(__FILE__)) unless defined?(::LAME_ROOT)
|
|
3
|
+
LAME_ROOT = File.expand_path(File.dirname(__FILE__)) unless defined?(LAME_ROOT)
|
|
5
4
|
|
|
6
5
|
require 'lib/lamed/main'
|
|
7
6
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
lame_path = ::File.expand_path(::File.dirname(__FILE__)) + "/../../"
|
|
2
|
+
$LOAD_PATH.unshift(lame_path) unless $LOAD_PATH.include?(lame_path)
|
|
3
|
+
::ROOT = ::File.expand_path(::File.dirname(__FILE__)) unless defined?(::ROOT)
|
|
4
|
+
|
|
5
|
+
require 'lib/lamed'
|
|
6
|
+
|
|
7
|
+
# Do not remove this unless you want to manually map HTTP['PATH_INFO'] to your controllers.
|
|
8
|
+
run_apps
|
|
9
|
+
|
|
10
|
+
# Add your custom url mappings here
|
|
11
|
+
# map "/hello" do
|
|
12
|
+
# run HelloWorld.new
|
|
13
|
+
# end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{{say_hello}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{{say_hello}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{{say_hello}}
|
data/spec/helpers_spec.rb
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__), "spec_helper")
|
|
2
2
|
require File.join(File.dirname(__FILE__), '..', '/lib/lamed/helper')
|
|
3
3
|
|
|
4
|
+
module Foo
|
|
5
|
+
module Bar
|
|
6
|
+
module Har
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
4
11
|
module Lamed
|
|
5
12
|
|
|
6
13
|
include Helper
|
|
@@ -48,4 +55,12 @@ module Lamed
|
|
|
48
55
|
end
|
|
49
56
|
end
|
|
50
57
|
|
|
58
|
+
describe "Convert a class to a path string" do
|
|
59
|
+
it "should build a path string from a class" do
|
|
60
|
+
klass = Foo::Bar::Har
|
|
61
|
+
path = class_to_path klass
|
|
62
|
+
path.should == "/foo/bar/har"
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
51
66
|
end
|
data/spec/initializer_spec.rb
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
LAME_ROOT = File.join(File.dirname(__FILE__), '..')
|
|
2
|
-
ROOT = File.join(LAME_ROOT, "/spec/
|
|
2
|
+
ROOT = File.join(LAME_ROOT, "/spec/examples")
|
|
3
3
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
|
|
4
4
|
|
|
5
5
|
require 'rack'
|
|
6
6
|
require 'lib/lamed/initializer'
|
|
7
7
|
|
|
8
|
-
module Lamed
|
|
9
8
|
|
|
10
9
|
describe "Initialize all Lamed Objects" do
|
|
11
10
|
it "should initialize the logger to STDERR" do
|
|
12
11
|
Lamed.logger.level.should == 0
|
|
13
12
|
end
|
|
14
13
|
|
|
15
|
-
it "should initialize the Controller and
|
|
16
|
-
Lamed::
|
|
17
|
-
Lamed::Controller.constants.should == [:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
it "should initialize the Controller, Lib, and Model objects" do
|
|
15
|
+
Lamed::Model.constants.should == [:BarModel, :FooModel]
|
|
16
|
+
Lamed::Controller.constants.sort.should == [:HelloWorld, :Lamest, :BarModel, :FooModel, :VERSION, :Cascade, :Chunked,
|
|
17
|
+
:ConditionalGet, :ContentLength, :ContentType, :File, :Deflater, :Directory,
|
|
18
|
+
:ForwardRequest, :Handler, :Head, :Lint, :Lock, :MethodOverride, :Mime,
|
|
19
|
+
:Recursive, :Reloader, :ShowStatus, :Static, :URLMap, :MockRequest,
|
|
20
|
+
:MockResponse, :Response, :Auth, :Session, :Adapter, :Builder, :CommonLogger,
|
|
21
|
+
:Utils, :Request, :ShowExceptions, :Template, :ContextMiss, :Context].sort
|
|
22
|
+
Object.constants.include?(:FooLib).should == true
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
end
|
data/spec/object_loader_spec.rb
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
LAME_ROOT = File.join(File.dirname(__FILE__), '..')
|
|
2
|
-
ROOT = File.join(LAME_ROOT, "/spec/
|
|
2
|
+
ROOT = File.join(LAME_ROOT, "/spec/examples")
|
|
3
3
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
|
|
4
4
|
|
|
5
5
|
require 'mustache'
|
|
6
6
|
require 'rack'
|
|
7
7
|
require "lib/lamed/helper"
|
|
8
|
-
require 'lib/lamed/
|
|
9
|
-
require 'lib/lamed/record'
|
|
8
|
+
require 'lib/lamed/model'
|
|
10
9
|
require 'lib/lamed/controller'
|
|
11
10
|
require "lib/lamed/object_loader"
|
|
12
11
|
|
|
@@ -14,101 +13,101 @@ module Lamed
|
|
|
14
13
|
|
|
15
14
|
describe "Load Objects into a tree" do
|
|
16
15
|
it "should find all record files within a subdir" do
|
|
17
|
-
record_result = ["/usr/pub/projects/lamed/spec/../spec/
|
|
18
|
-
"/usr/pub/projects/lamed/spec/../spec/
|
|
19
|
-
controller_result = ["/usr/pub/projects/lamed/spec/../spec/
|
|
20
|
-
"/usr/pub/projects/lamed/spec/../spec/
|
|
21
|
-
"/usr/pub/projects/lamed/spec/../spec/
|
|
22
|
-
record_paths = ObjectLoader.get_files(:
|
|
16
|
+
record_result = ["/usr/pub/projects/lamed/spec/../spec/examples/ext/models/bar_model.rb",
|
|
17
|
+
"/usr/pub/projects/lamed/spec/../spec/examples/ext/models/foo_model.rb"]
|
|
18
|
+
controller_result = ["/usr/pub/projects/lamed/spec/../spec/examples/ext/controllers/hello_world.rb",
|
|
19
|
+
"/usr/pub/projects/lamed/spec/../spec/examples/ext/controllers/lamest/bar.rb",
|
|
20
|
+
"/usr/pub/projects/lamed/spec/../spec/examples/ext/controllers/lamest/foo.rb"]
|
|
21
|
+
record_paths = ObjectLoader.get_files(:model)
|
|
23
22
|
controller_paths = ObjectLoader.get_files(:controller)
|
|
24
23
|
record_paths.should == record_result
|
|
25
24
|
controller_paths.should == controller_result
|
|
26
25
|
end
|
|
27
26
|
|
|
28
27
|
it "should group subdirs together given a path" do
|
|
29
|
-
@paths = ["/usr/pub/projects/lamed/spec/../spec/
|
|
30
|
-
"/usr/pub/projects/lamed/spec/../spec/
|
|
31
|
-
"/usr/pub/projects/lamed/spec/../spec/
|
|
32
|
-
result = {
|
|
33
|
-
|
|
34
|
-
"third_controller.rb"] }
|
|
28
|
+
@paths = ["/usr/pub/projects/lamed/spec/../spec/examples/ext/controllers/hello_world.rb",
|
|
29
|
+
"/usr/pub/projects/lamed/spec/../spec/examples/ext/controllers/lamest/foo.rb",
|
|
30
|
+
"/usr/pub/projects/lamed/spec/../spec/examples/ext/controllers/lamest/bar.rb"]
|
|
31
|
+
result = {"/usr/pub/projects/lamed/spec/../spec/examples/ext/controllers"=>["hello_world.rb"],
|
|
32
|
+
"/usr/pub/projects/lamed/spec/../spec/examples/ext/controllers/lamest"=>["bar.rb", "foo.rb"]}
|
|
35
33
|
mapped_file = ObjectLoader.map_file_to_subdir
|
|
36
34
|
mapped_file.should == result
|
|
37
35
|
end
|
|
38
36
|
|
|
39
37
|
it "should get the camelized ext sub directory" do
|
|
40
|
-
subdir = "/usr/pub/projects/lamed/spec/../spec/
|
|
38
|
+
subdir = "/usr/pub/projects/lamed/spec/../spec/examples/ext/controllers/second"
|
|
41
39
|
ext_subdir = ObjectLoader.camelize_ext_subdir(subdir)
|
|
42
|
-
ext_subdir.should == [:
|
|
40
|
+
ext_subdir.should == [:Second]
|
|
43
41
|
end
|
|
44
42
|
|
|
45
43
|
it "should load path symbols as objects" do
|
|
46
|
-
camelized_path = [:
|
|
44
|
+
camelized_path = [:Second]
|
|
47
45
|
klass = ObjectLoader.create_object_from_camelized_path(camelized_path)
|
|
48
46
|
klass.should == Lamed::Controller::Second
|
|
49
47
|
end
|
|
50
48
|
|
|
51
49
|
it "should create new Controller objects from files" do
|
|
52
|
-
subdir, file_name = "/usr/pub/projects/lamed/spec/../spec/
|
|
53
|
-
["
|
|
50
|
+
subdir, file_name = "/usr/pub/projects/lamed/spec/../spec/examples/ext/controllers/lamest",
|
|
51
|
+
["bar.rb", "foo.rb"]
|
|
54
52
|
new_objects = ObjectLoader.load_new_object(subdir, file_name)
|
|
55
|
-
Object.constants.include?(:
|
|
56
|
-
Object.constants.include?(:
|
|
53
|
+
Object.constants.include?(:Foo).should == true
|
|
54
|
+
Object.constants.include?(:Bar).should == true
|
|
57
55
|
# Clean up
|
|
58
|
-
Object.instance_eval { [:
|
|
56
|
+
Object.instance_eval { [:Foo, :Bar].each { |o| remove_const o } }
|
|
59
57
|
end
|
|
60
58
|
|
|
61
59
|
it "should create new Record Objects from files" do
|
|
62
|
-
subdir, file_name = "/usr/pub/projects/lamed/spec/../spec/
|
|
63
|
-
["
|
|
60
|
+
subdir, file_name = "/usr/pub/projects/lamed/spec/../spec/examples/ext/models",
|
|
61
|
+
["foo_model.rb", "bar_model.rb"]
|
|
64
62
|
new_objects = ObjectLoader.load_new_object(subdir, file_name)
|
|
65
|
-
Object.constants.include?(:
|
|
66
|
-
Object.constants.include?(:
|
|
63
|
+
Object.constants.include?(:FooModel).should == true
|
|
64
|
+
Object.constants.include?(:BarModel).should == true
|
|
67
65
|
# Clean up
|
|
68
|
-
Object.instance_eval { [:
|
|
66
|
+
Object.instance_eval { [:BarModel, :FooModel].each { |o| remove_const o } }
|
|
69
67
|
end
|
|
70
68
|
|
|
71
69
|
it "should create a new view path for the new class" do
|
|
72
|
-
camelized_ext_subdir = [:
|
|
70
|
+
camelized_ext_subdir = [:Lamest, :Foo]
|
|
73
71
|
view_path = ObjectLoader.create_view_path(camelized_ext_subdir)
|
|
74
|
-
view_path.should == "/usr/pub/projects/lamed/spec/../spec/
|
|
72
|
+
view_path.should == "/usr/pub/projects/lamed/spec/../spec/examples/ext/views/lamest/foo"
|
|
75
73
|
end
|
|
76
74
|
|
|
77
75
|
it "should move new objects to new Lamed class/modules" do
|
|
78
76
|
load 'lib/lamed/object_loader.rb'
|
|
79
|
-
subdir, file_name = "/usr/pub/projects/lamed/spec/../spec/
|
|
80
|
-
["
|
|
81
|
-
ObjectLoader.
|
|
82
|
-
Object::Lamed::Controller::
|
|
83
|
-
Object::Lamed::Controller::
|
|
77
|
+
subdir, file_name = "/usr/pub/projects/lamed/spec/../spec/examples/ext/controllers/lamest",
|
|
78
|
+
["bar.rb", "foo.rb"]
|
|
79
|
+
ObjectLoader.load_controller_into_new_class(subdir, file_name)
|
|
80
|
+
Object::Lamed::Controller::Lamest.constants.should == [:Bar, :Foo]
|
|
81
|
+
Object::Lamed::Controller::Lamest::Foo.class.should == Class
|
|
84
82
|
end
|
|
85
83
|
|
|
86
84
|
it "should check to see if new objects were removed from Object" do
|
|
87
|
-
Object.constants.include?(:
|
|
88
|
-
Object.constants.include?(:
|
|
85
|
+
Object.constants.include?(:Foo).should == false
|
|
86
|
+
Object.constants.include?(:Bar).should == false
|
|
89
87
|
end
|
|
90
88
|
|
|
91
89
|
it "should check the view path for the new objects" do
|
|
92
|
-
Object::Lamed::Controller::
|
|
93
|
-
Object::Lamed::Controller::
|
|
90
|
+
Object::Lamed::Controller::Lamest::Bar.path.should == "/usr/pub/projects/lamed/spec/examples/ext/views/lamest"
|
|
91
|
+
Object::Lamed::Controller::Lamest::Foo.path.should == "/usr/pub/projects/lamed/spec/examples/ext/views/lamest"
|
|
94
92
|
end
|
|
95
93
|
|
|
96
94
|
it "should load up controllers" do
|
|
97
|
-
ObjectLoader.
|
|
98
|
-
Lamed.constants.should == [:Helper, :
|
|
99
|
-
Lamed::Controller.constants.should == [:
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
95
|
+
ObjectLoader.load_controller_object
|
|
96
|
+
Lamed.constants.should == [:Helper, :Model, :MySQL, :Controller, :ObjectLoader]
|
|
97
|
+
Lamed::Controller.constants.sort.should == [:Adapter, :Auth, :Builder, :Cascade, :Chunked, :CommonLogger,
|
|
98
|
+
:ConditionalGet, :ContentLength, :ContentType, :Context, :ContextMiss,
|
|
99
|
+
:Deflater, :Directory, :File, :ForwardRequest, :Handler, :Head,
|
|
100
|
+
:HelloWorld, :Lamest, :Lint, :Lock, :MethodOverride, :Mime, :MockRequest,
|
|
101
|
+
:MockResponse, :Recursive, :Reloader, :Request, :Response, :Second,
|
|
102
|
+
:Session, :ShowExceptions, :ShowStatus, :Static, :Template, :URLMap,
|
|
103
|
+
:Utils, :VERSION].sort
|
|
104
|
+
Lamed::Controller::Lamest.constants.should == [:Bar, :Foo]
|
|
106
105
|
end
|
|
107
106
|
|
|
108
|
-
it "should load up
|
|
109
|
-
ObjectLoader.
|
|
110
|
-
Lamed.constants.should == [:Helper, :
|
|
111
|
-
Lamed::
|
|
107
|
+
it "should load up models" do
|
|
108
|
+
ObjectLoader.load_model_object
|
|
109
|
+
Lamed.constants.should == [:Helper, :Model, :MySQL, :Controller, :ObjectLoader]
|
|
110
|
+
Lamed::Model.constants.should == [:BarModel, :FooModel]
|
|
112
111
|
end
|
|
113
112
|
|
|
114
113
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lamed
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lee Chang
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2010-01-
|
|
12
|
+
date: 2010-01-19 00:00:00 -08:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
@@ -48,23 +48,27 @@ files:
|
|
|
48
48
|
- README.rdoc
|
|
49
49
|
- Rakefile
|
|
50
50
|
- VERSION
|
|
51
|
+
- lamed.gemspec
|
|
51
52
|
- lib/lamed.rb
|
|
52
53
|
- lib/lamed/controller.rb
|
|
53
54
|
- lib/lamed/helper.rb
|
|
54
55
|
- lib/lamed/initializer.rb
|
|
55
|
-
- lib/lamed/lib.rb
|
|
56
56
|
- lib/lamed/main.rb
|
|
57
|
-
- lib/lamed/
|
|
57
|
+
- lib/lamed/model.rb
|
|
58
58
|
- lib/lamed/object_loader.rb
|
|
59
|
-
- lib/lamed/record.rb
|
|
60
59
|
- lib/lamed/redis.rb
|
|
61
|
-
- spec/
|
|
62
|
-
- spec/
|
|
63
|
-
- spec/
|
|
64
|
-
- spec/
|
|
65
|
-
- spec/
|
|
66
|
-
- spec/
|
|
67
|
-
- spec/
|
|
60
|
+
- spec/examples/conf/config.yml
|
|
61
|
+
- spec/examples/conf/database.yml
|
|
62
|
+
- spec/examples/config.ru
|
|
63
|
+
- spec/examples/ext/controllers/hello_world.rb
|
|
64
|
+
- spec/examples/ext/controllers/lamest/bar.rb
|
|
65
|
+
- spec/examples/ext/controllers/lamest/foo.rb
|
|
66
|
+
- spec/examples/ext/models/bar_model.rb
|
|
67
|
+
- spec/examples/ext/models/foo_model.rb
|
|
68
|
+
- spec/examples/ext/views/hello_world.mustache
|
|
69
|
+
- spec/examples/ext/views/lamest/bar.mustache
|
|
70
|
+
- spec/examples/ext/views/lamest/foo.mustache
|
|
71
|
+
- spec/examples/lib/foo_lib.rb
|
|
68
72
|
- spec/helpers_spec.rb
|
|
69
73
|
- spec/initializer_spec.rb
|
|
70
74
|
- spec/lame_spec.rb
|
|
@@ -100,11 +104,12 @@ signing_key:
|
|
|
100
104
|
specification_version: 3
|
|
101
105
|
summary: Get LaMeD
|
|
102
106
|
test_files:
|
|
103
|
-
- spec/
|
|
104
|
-
- spec/
|
|
105
|
-
- spec/
|
|
106
|
-
- spec/
|
|
107
|
-
- spec/
|
|
107
|
+
- spec/examples/ext/controllers/hello_world.rb
|
|
108
|
+
- spec/examples/ext/controllers/lamest/bar.rb
|
|
109
|
+
- spec/examples/ext/controllers/lamest/foo.rb
|
|
110
|
+
- spec/examples/ext/models/bar_model.rb
|
|
111
|
+
- spec/examples/ext/models/foo_model.rb
|
|
112
|
+
- spec/examples/lib/foo_lib.rb
|
|
108
113
|
- spec/helpers_spec.rb
|
|
109
114
|
- spec/initializer_spec.rb
|
|
110
115
|
- spec/lame_spec.rb
|
data/lib/lamed/lib.rb
DELETED
data/lib/lamed/mysql.rb
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
require 'mysql'
|
|
2
|
-
|
|
3
|
-
class MySQL
|
|
4
|
-
|
|
5
|
-
attr_reader :status, :db_conn, :db_conn_read, :params
|
|
6
|
-
|
|
7
|
-
def initialize(params = {})
|
|
8
|
-
@params = params
|
|
9
|
-
@host = params[:host] || '127.0.0.1'
|
|
10
|
-
@port = (params[:port] || 3306).to_i
|
|
11
|
-
@user = params[:username] || 'root'
|
|
12
|
-
@password = params[:password] || 'pwd'
|
|
13
|
-
@database = params[:database]
|
|
14
|
-
@read_host = params[:read_host]
|
|
15
|
-
@read_username = params[:read_user]
|
|
16
|
-
@read_password = params[:read_password]
|
|
17
|
-
@read_database = params[:read_password]
|
|
18
|
-
@read_port = params[:read_port]
|
|
19
|
-
self.connect
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def connect
|
|
23
|
-
$db_conn = Mysql.real_connect(@host, @user, @password, @database, @port)
|
|
24
|
-
# Check to make sure there is a read db in the configs
|
|
25
|
-
if @read_host
|
|
26
|
-
$db_conn_read = Mysql.real_connect(@read_host, @read_username, @read_password, @read_database, @read_port)
|
|
27
|
-
else
|
|
28
|
-
$db_conn_read = $db_conn
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def self.query(query_string)
|
|
33
|
-
n = 0 # track how many times the system had to reconnect to the db
|
|
34
|
-
begin
|
|
35
|
-
# Test to see if the query starts with a select which would mean it was a read query
|
|
36
|
-
if query_string.split[0].upcase == "SELECT"
|
|
37
|
-
res = $db_conn_read.query(query_string)
|
|
38
|
-
else
|
|
39
|
-
res = $db_conn.query(query_string)
|
|
40
|
-
end
|
|
41
|
-
rescue Mysql::Error => e
|
|
42
|
-
case e.to_s
|
|
43
|
-
when 'MySQL server has gone away'
|
|
44
|
-
MySQL.new($DB_OPTIONS)
|
|
45
|
-
n += 1
|
|
46
|
-
retry
|
|
47
|
-
when 'Lost connection to MySQL server during query'
|
|
48
|
-
MySQL.new($DB_OPTIONS)
|
|
49
|
-
n += 1
|
|
50
|
-
retry
|
|
51
|
-
else
|
|
52
|
-
# Don't know what to do because of an unknown error so to play it safe we'll just break instead looping endlessly.
|
|
53
|
-
raise "ERROR: #{e.to_s} Not sure what this error is from #{@host}."
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
return res
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
end
|
data/lib/lamed/record.rb
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
require 'lib/lamed/mysql'
|
|
2
|
-
require 'lib/lamed/redis'
|
|
3
|
-
|
|
4
|
-
module Lamed
|
|
5
|
-
|
|
6
|
-
module Record
|
|
7
|
-
|
|
8
|
-
#include Lamed
|
|
9
|
-
|
|
10
|
-
LAME_ROOT = ::LAME_ROOT unless defined?(LAME_ROOT)
|
|
11
|
-
|
|
12
|
-
if defined?($DB_OPTIONS)
|
|
13
|
-
record.build_path_hash
|
|
14
|
-
record.build_objects
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
development:
|
|
2
|
-
radio_indexer_cache: ['127.0.0.1:11211']
|
|
3
|
-
index_cache: ['127.0.0.1:11211']
|
|
4
|
-
main_cache: ['127.0.0.1:11211']
|
|
5
|
-
redis_host: '127.0.0.1'
|
|
6
|
-
redis_port: 6389
|
|
7
|
-
http_procs: 1
|
|
8
|
-
workers: 1
|
|
9
|
-
port: 3000
|
|
10
|
-
run_as: reco
|
|
11
|
-
pid: logs/run/
|
|
12
|
-
logs: logs/nutsie_radio
|
|
13
|
-
rotate: daily
|
|
File without changes
|