lamed 0.1.2

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Lee Chang
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = lamed
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2010 Lee Chang. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "lamed"
8
+ gem.summary = %Q{Get LaMeD}
9
+ gem.description = %Q{Yet another LaMe Ruby Web Framework}
10
+ gem.email = "leetchang@gmail.com"
11
+ gem.homepage = "http://github.com/onemorehill/lamed"
12
+ gem.authors = ["Lee Chang"]
13
+ gem.add_development_dependency "rack", ">= 1.0"
14
+ gem.add_development_dependency "mustache", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "lamed #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
@@ -0,0 +1,65 @@
1
+ module Lamed
2
+
3
+ class Controller < Mustache
4
+
5
+ include Rack
6
+ include Lamed::Helper
7
+ extend Lamed::Helper
8
+ include Lamed::Record
9
+ include Lamed::Lib
10
+
11
+ attr_accessor :query, :path, :self_path, :env
12
+
13
+ def set_self_path(str)
14
+ @self_path = str
15
+ end
16
+
17
+ def parse_uri(request_path)
18
+ begin
19
+ uri = (request_path.split("/").collect {|r| r.downcase.intern unless r.empty?}).compact
20
+ rescue NoMethodError
21
+ uri = Array.new
22
+ end
23
+ return uri
24
+ end
25
+
26
+ def parse_query_string(query_string)
27
+ begin
28
+ params = query_string.split('&').inject({}) { |h,(k,v)|
29
+ values = k.split('=')
30
+ # Drop any query params that have blank values
31
+ h[values[0].downcase.intern] = (CGI.unescape(values[1])).downcase if values.length == 2
32
+ h
33
+ }
34
+ rescue NoMethodError => e
35
+ params = Hash.new
36
+ end
37
+ return params
38
+ end
39
+
40
+ def call(env)
41
+ env[:query] = self.parse_query_string(env['QUERY_STRING'])
42
+ env[:path] = self.parse_uri(env['SCRIPT_NAME'])
43
+ response(env)
44
+ resp = @req_params
45
+ status_code = resp[:status_code] || 200
46
+ content_type = resp[:content_type] || "text/html"
47
+ [status_code, {"Content-Type" => content_type}, [resp[:body]]]
48
+ end
49
+
50
+ def request(*args)
51
+ end
52
+
53
+ def response(req_params)
54
+ @req_params = req_params
55
+ @req_params[:body] = self.render
56
+ return @req_params
57
+ end
58
+
59
+ def content_type(string)
60
+ @req_params[:content_type] = string
61
+ end
62
+
63
+ end
64
+
65
+ end
@@ -0,0 +1,88 @@
1
+ module Lamed
2
+
3
+ module Helper
4
+
5
+ # -=-=-=-= Hash Helper =-=-=-=-
6
+ # Changes keys that are strings in symbols. Goes two deep.
7
+ def symbolize_hash_keys(hash = self)
8
+ symbolize_value = ->(value) { value.inject({}) {|h,(k,v)| h[(k.intern rescue k) || key] = v;h } }
9
+ hash.inject({}) do |options, (key, value)|
10
+ value = Hash === value ? symbolize_value.call(value) : value
11
+ options[(key.to_sym rescue key) || key] = value
12
+ options
13
+ end
14
+ end
15
+
16
+ # -=-=-=-= String Helper =-=-=-=-
17
+ # Camel case a string with _ separator(s)
18
+ def camelize_string(str)
19
+ cameled_string = str.split("_").map {|s| s.capitalize }.join
20
+ return cameled_string
21
+ end
22
+
23
+ # Camel case a string with / separator(s)
24
+ def camelize_path(path)
25
+ cameled_path = path.split("/").collect {|a| camelize_string(a).intern}
26
+ cameled_path.delete_if { |s| s == :""}
27
+ return cameled_path
28
+ end
29
+
30
+ def uncamelize_string(str)
31
+ uncameled_string = (str.split('').collect {|c| c = c.upcase! == nil ? '_' + c.downcase : c.downcase}).join
32
+ uncameled_string.slice!(0) if uncameled_string[0] == '_'
33
+ return uncameled_string
34
+ end
35
+
36
+ def uncamelize_path(cameled_path)
37
+ uncameled_path = cameled_path.collect { |p| uncamelize_string(p.to_s) }
38
+ path = uncameled_path.join("/").insert(0, "/")
39
+ return path
40
+ end
41
+
42
+ # Convert strings into a usable MySQL time object.
43
+ def mysql_time(str)
44
+ str[/(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+)/]
45
+ year = $1.to_i; month = $2.to_i; day = $3.to_i; hour = $4.to_i; min = $5.to_i; sec = $6.to_i
46
+ new_time = Time.local(year,month,day,hour,min,sec)
47
+ return new_time
48
+ end
49
+
50
+ # -=-=-=-=Array Helper =-=-=-=-
51
+ def sorted_array(array = self)
52
+ count_hash = array.inject({}) { |h,(k,v)| h[k] = 0 if h[k].nil?; h[k] += 1; h }
53
+ sorted_array = count_hash.to_a.collect { |a|
54
+ a.reverse
55
+ }.sort.reverse.collect { |a|
56
+ a.reverse
57
+ }
58
+ sorted_array.collect! { |a| a[0] }
59
+ return sorted_array
60
+ end
61
+
62
+ def sorted_hash(array = self)
63
+ count_hash = array.inject({}) { |h,(k,v)| h[k] = 0 if h[k].nil?; h[k] += 1; h }
64
+ sorted_array = count_hash.to_a.collect { |a|
65
+ a.reverse
66
+ }.sort.reverse.collect { |a|
67
+ a.reverse
68
+ }
69
+ sorted_group = sorted_array.inject ({}) { |h,(k,v)|
70
+ h[k] = v
71
+ h
72
+ }
73
+ return sorted_group
74
+ end
75
+
76
+ def sorted_weighted_hash(array = self)
77
+ sorted_group = array.sorted_group
78
+ size = sorted_group.length
79
+ new_hash = Hash.new
80
+ sorted_group.each_pair { |k,v|
81
+ new_hash[k] = v.to_f/size.to_f
82
+ }
83
+ return new_hash
84
+ end
85
+
86
+ end
87
+
88
+ end
@@ -0,0 +1,93 @@
1
+ require 'yaml'
2
+ require 'logger'
3
+ require 'optparse'
4
+ require 'memcached'
5
+ require 'cgi'
6
+ require 'lib/lamed/helper'
7
+ require 'lib/lamed/object_loader'
8
+
9
+ module Lamed
10
+
11
+
12
+ # Build configurations from yaml files
13
+ if defined?(ROOT)
14
+ OPTIONS = {
15
+ :env => (ENV['RACK_ENV'] || "development").to_sym,
16
+ :config => ROOT + '/conf/',
17
+ :log_path => ROOT + '/logs',
18
+ :verbose => false
19
+ }
20
+
21
+ if File.exists?(File.join(ROOT,'/conf/config.yml'))
22
+ SYS_OPTIONS = YAML.load_file(OPTIONS[:config] + "config.yml")[OPTIONS[:env].to_s].inject({}) {|h,(k,v)| h[k.intern] = v; h}
23
+ end
24
+ if File.exists?(ROOT + '/conf/database.yml')
25
+ DB_OPTIONS = YAML.load_file(OPTIONS[:config] + "database.yml")[OPTIONS[:env].to_s].inject({}) {|h,(k,v)| h[k.intern] = v; h}
26
+ end
27
+ if defined?(SYS_OPTIONS)
28
+ @sys_options = SYS_OPTIONS
29
+ log_path =@sys_options[:logs] || OPTIONS[:log_path]
30
+ OPTIONS[:rotate] = !@sys_options.nil? ? @sys_options[:rotate] : nil
31
+ OPTIONS[:log] = File.join(log_path, OPTIONS[:env].to_s ,".log")
32
+ end
33
+ end
34
+
35
+ class << self
36
+
37
+ # Set up logging
38
+ def initialize_logger
39
+ if defined?(SYS_OPTIONS)
40
+ logs = Logger.new(@log_path, OPTIONS[:rotate])
41
+ case OPTIONS[:env]
42
+ when :development
43
+ logs.level = Logger::DEBUG
44
+ when :test
45
+ logs.level = Logger::DEBUG
46
+ when :staging
47
+ logs.level = Logger::DEBUG
48
+ when :production
49
+ logs.level = Logger::WARN
50
+ end
51
+ else
52
+ logs = Logger.new(STDERR)
53
+ end
54
+ puts "The log path does not exist or is not writable. Log messages will be sent to STANDARD ERROR"
55
+ @logger = logs
56
+ logs.warn("Logging level is set to #{logs.level}")
57
+ return @logger
58
+ end
59
+
60
+ if defined?(ROOT)
61
+ require 'lib/lamed/record'
62
+ require 'lib/lamed/lib'
63
+ end
64
+
65
+ def logger
66
+ @logger
67
+ end
68
+
69
+ def load_lib
70
+ #Dir[LAME_ROOT + '/lib/*.rb'].each {|d| require d}
71
+ lib = LoadObjects.new(ROOT, :lib)
72
+ lib.build_path_hash
73
+ lib.build_objects
74
+ end
75
+
76
+ def load_controller
77
+ ObjectLoader.load_new_objects(:controller)
78
+ end
79
+
80
+ def load_record
81
+ ObjectLoader.load_new_objects(:record)
82
+ end
83
+
84
+ end
85
+
86
+ if defined?(SYS_OPTIONS)
87
+ load_record
88
+ require 'lib/lamed/controller'
89
+ load_controller
90
+ end
91
+ initialize_logger
92
+
93
+ end
data/lib/lamed/lib.rb ADDED
@@ -0,0 +1,15 @@
1
+ module Lamed
2
+
3
+ module Lib
4
+
5
+ LAME_ROOT = ::LAME_ROOT unless(LAME_ROOT)
6
+
7
+ =begin
8
+ if defined?(SYS_OPTIONS)
9
+ lib.build_path_hash
10
+ lib.build_objects
11
+ end
12
+ =end
13
+ end
14
+
15
+ end
data/lib/lamed/main.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'rack'
2
+ require 'rack/builder'
3
+ require 'logger'
4
+
5
+ module Lamedd
6
+
7
+ require 'lib/lamed/initializer'
8
+
9
+ end
@@ -0,0 +1,59 @@
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
@@ -0,0 +1,106 @@
1
+ ROOT = ::File.join(::File.dirname(__FILE__), '..') unless defined?(ROOT)
2
+
3
+ module Lamed
4
+
5
+ class ObjectLoader
6
+
7
+ class << self
8
+
9
+ include Lamed::Helper
10
+ extend Lamed::Helper
11
+
12
+ # Load objects in this order:
13
+ # Libraries - Lib
14
+ # Records or models - Record
15
+ # 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
+
28
+ def get_files(type)
29
+ @paths = Dir.glob(FILE_FILTER[type])
30
+ end
31
+
32
+ def map_file_to_subdir
33
+ @mapped_file = Hash.new
34
+ @paths.each { |path|
35
+ path_parts = File.split(path)
36
+ dir = path_parts[0]
37
+ file_name = path_parts[1]
38
+ @mapped_file[dir] = @mapped_file[dir].nil? ? [file_name] : @mapped_file[dir] << file_name
39
+ }
40
+ @mapped_file
41
+ end
42
+
43
+ def camelize_ext_subdir(subdir)
44
+ ext_subdir = subdir.split(ROOT_EXT)[1]
45
+ camelized_ext_subdir = camelize_path ext_subdir
46
+ return camelized_ext_subdir
47
+ end
48
+
49
+ def create_object_from_camelized_path(camelized_ext_subdir)
50
+ klass = Lamed
51
+ camelized_ext_subdir.each { |symbol|
52
+ if klass.constants.include?(symbol)
53
+ klass_prime = klass.const_get(symbol)
54
+ else
55
+ klass_prime = klass.const_set(symbol, Module.new)
56
+ end
57
+ klass = klass_prime
58
+ }
59
+ return klass
60
+ end
61
+
62
+ def load_new_object(subdir, file_name)
63
+ file_name.each { |f|
64
+ file = File.join(subdir, f)
65
+ load file
66
+ }
67
+ return nil
68
+ end
69
+
70
+ def create_view_path(camelized_ext_subdir)
71
+ camelized_ext_subdir_prime = camelized_ext_subdir.dup; camelized_ext_subdir_prime.delete_at(0)
72
+ camelized_ext_subdir_prime.unshift(:View)
73
+ view_path = File.join(ROOT_EXT, uncamelize_path(camelized_ext_subdir_prime))
74
+ return view_path
75
+ end
76
+
77
+ # Load new object(s) into new klass(es) as defined by their path.
78
+ # First load the files then build the class/modules(klass) from the path.
79
+ # Then move the newly created objects into the newly built klass.
80
+ # Finally, remove the newly loaded objects from Object.
81
+ # Change the path= for controllers to the location of the mustache templates.
82
+ def load_new_object_into_klass(subdir, file_name)
83
+ orig_object_constants = Object.constants.dup
84
+ load_new_object(subdir, file_name)
85
+ camelized_ext_subdir = camelize_ext_subdir(subdir)
86
+ klass = create_object_from_camelized_path(camelized_ext_subdir)
87
+ view_path = create_view_path(camelized_ext_subdir)
88
+ (Object.constants - orig_object_constants).each { |o|
89
+ o_klass = Object.const_get(o)
90
+ # 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?('path')
92
+ klass.const_set(o, o_klass)
93
+ Object.instance_eval { remove_const o }
94
+ }
95
+ end
96
+
97
+ def load_new_objects(type)
98
+ get_files(type)
99
+ map_file_to_subdir
100
+ @mapped_file.each_pair { |subdir, file_name| load_new_object_into_klass(subdir, file_name) }
101
+ end
102
+
103
+ end
104
+
105
+ end
106
+ end
@@ -0,0 +1,20 @@
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
@@ -0,0 +1,25 @@
1
+ require 'redis'
2
+
3
+ class Redis
4
+
5
+ # Adding namespace or prefix keys to redis SET and GET request much like memcache.
6
+
7
+ $SYS_OPTIONS = {} unless defined?($SYS_OPTIONS)
8
+
9
+ REDIS_OPTIONS = {
10
+ :host => $SYS_OPTIONS[:redis_host] || '127.0.0.1' ,
11
+ :port => ($SYS_OPTIONS[:redis_port] || 6379).to_i,
12
+ :db => ($SYS_OPTIONS[:redis_db] || 0).to_i,
13
+ :timeout => ($SYS_OPTIONS[:redis_timeout] || 5).to_i,
14
+ }
15
+
16
+ def initialize(host, opts={})
17
+ @host = host || REDIS_OPTIONS[:host]
18
+ @port = opts[:port] || REDIS_OPTIONS[:port]
19
+ @db = opts[:db] || REDIS_OPTIONS[:db]
20
+ @timeout = opts[:timeout] || REDIS_OPTIONS[:timeout]
21
+ $debug = opts[:debug]
22
+ connect_to_server
23
+ end
24
+
25
+ end
data/lib/lamed.rb ADDED
@@ -0,0 +1,12 @@
1
+ lib_path = File.expand_path(File.dirname(__FILE__)) + "/../"
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)
5
+
6
+ require 'lib/lamed/main'
7
+
8
+ module Lamed
9
+
10
+ VERSION = '0.4.6'
11
+
12
+ end
@@ -0,0 +1,13 @@
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
@@ -0,0 +1,7 @@
1
+ development:
2
+ host: localhost
3
+ port: 3306
4
+ username: root
5
+ password: pwd
6
+ database: ithingy
7
+ adapter: mysql
@@ -0,0 +1,3 @@
1
+ class FirstController < Lamed::Controller
2
+
3
+ end
@@ -0,0 +1,2 @@
1
+ class SecondController < Lamed::Controller
2
+ end
@@ -0,0 +1,2 @@
1
+ class ThirdController < Lamed::Controller
2
+ end
@@ -0,0 +1,2 @@
1
+ class BarRecord < MySQL
2
+ end
@@ -0,0 +1,2 @@
1
+ class FooRecord < MySQL
2
+ end
@@ -0,0 +1,51 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+ require File.join(File.dirname(__FILE__), '..', '/lib/lamed/helper')
3
+
4
+ module Lamed
5
+
6
+ include Helper
7
+ describe "Symbolize Hash Keys" do
8
+ it "should convert hash keys from strings to symbols" do
9
+ hash = { 'key1' => 1, 'key2' => { 'key3' => 3, 'key4' => 4 } }
10
+ symbolized_hash = symbolize_hash_keys hash
11
+ symbolized_hash.should == { :key1 => 1, :key2 => { :key3 => 3, :key4 => 4 } }
12
+ end
13
+ end
14
+
15
+ describe "Camelize a string seperated by _" do
16
+ it "should convert strings seperated by _ in a single cameled word" do
17
+ string = "foo_bar"
18
+ cameled_string = camelize_string string
19
+ cameled_string.should == "FooBar"
20
+ end
21
+
22
+ it "should uncamelize a cameled string into an uncameled _ seperated string" do
23
+ string = "FooBar"
24
+ uncameled_string = uncamelize_string string
25
+ uncameled_string.should == "foo_bar"
26
+ end
27
+ end
28
+
29
+ describe "Camelize a path" do
30
+ it "should convert a path into a single cameled symbols" do
31
+ path = "/foo/bar"
32
+ cameled_path = camelize_path path
33
+ cameled_path.should == [:Foo, :Bar]
34
+ end
35
+
36
+ it "should convert an array of camelized symbols to a path" do
37
+ camelized_path = [:Foo, :Bar, :HootBar]
38
+ uncamelized_path = uncamelize_path camelized_path
39
+ uncamelized_path.should == '/foo/bar/hoot_bar'
40
+ end
41
+ end
42
+
43
+ describe "Convert a string into a time object" do
44
+ it "should convert a date string into a time object" do
45
+ string = "2009-01-01 00:00:00"
46
+ date = mysql_time string
47
+ date.to_i.should == 1230796800
48
+ end
49
+ end
50
+
51
+ end
@@ -0,0 +1,27 @@
1
+ LAME_ROOT = File.join(File.dirname(__FILE__), '..')
2
+ ROOT = File.join(LAME_ROOT, "/spec/fixtures")
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
4
+
5
+ require 'rack'
6
+ require 'lib/lamed/initializer'
7
+
8
+ module Lamed
9
+
10
+ describe "Initialize all Lamed Objects" do
11
+ it "should initialize the logger to STDERR" do
12
+ Lamed.logger.level.should == 0
13
+ end
14
+
15
+ it "should initialize the Controller and Record objects" do
16
+ Lamed::Record.constants.should == [:BarRecord, :FooRecord]
17
+ Lamed::Controller.constants.should == [:FirstController, :Second, :BarRecord, :FooRecord, :VERSION, :Builder, :Cascade,
18
+ :Chunked, :CommonLogger, :ConditionalGet, :ContentLength, :ContentType, :File,
19
+ :Deflater, :Directory, :ForwardRequest, :Handler, :Head, :Lint, :Lock,
20
+ :MethodOverride, :Mime, :Recursive, :Reloader, :ShowExceptions, :ShowStatus,
21
+ :Static, :URLMap, :Utils, :MockRequest, :MockResponse, :Request, :Response, :Auth,
22
+ :Session, :Adapter, :Template, :ContextMiss, :Context]
23
+ end
24
+
25
+ end
26
+
27
+ end
data/spec/lame_spec.rb ADDED
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Lamed" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,116 @@
1
+ LAME_ROOT = File.join(File.dirname(__FILE__), '..')
2
+ ROOT = File.join(LAME_ROOT, "/spec/fixtures")
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
4
+
5
+ require 'mustache'
6
+ require 'rack'
7
+ require "lib/lamed/helper"
8
+ require 'lib/lamed/lib'
9
+ require 'lib/lamed/record'
10
+ require 'lib/lamed/controller'
11
+ require "lib/lamed/object_loader"
12
+
13
+ module Lamed
14
+
15
+ describe "Load Objects into a tree" do
16
+ it "should find all record files within a subdir" do
17
+ record_result = ["/usr/pub/projects/lamed/spec/../spec/fixtures/ext/record/bar_record.rb",
18
+ "/usr/pub/projects/lamed/spec/../spec/fixtures/ext/record/foo_record.rb"]
19
+ controller_result = ["/usr/pub/projects/lamed/spec/../spec/fixtures/ext/controller/first_controller.rb",
20
+ "/usr/pub/projects/lamed/spec/../spec/fixtures/ext/controller/second/second_controller.rb",
21
+ "/usr/pub/projects/lamed/spec/../spec/fixtures/ext/controller/second/third_controller.rb"]
22
+ record_paths = ObjectLoader.get_files(:record)
23
+ controller_paths = ObjectLoader.get_files(:controller)
24
+ record_paths.should == record_result
25
+ controller_paths.should == controller_result
26
+ end
27
+
28
+ it "should group subdirs together given a path" do
29
+ @paths = ["/usr/pub/projects/lamed/spec/../spec/fixtures/ext/controller/first_controller.rb",
30
+ "/usr/pub/projects/lamed/spec/../spec/fixtures/ext/controller/second/second_controller.rb",
31
+ "/usr/pub/projects/lamed/spec/../spec/fixtures/ext/controller/second/third_controller.rb"]
32
+ result = { "/usr/pub/projects/lamed/spec/../spec/fixtures/ext/controller" => ["first_controller.rb"],
33
+ "/usr/pub/projects/lamed/spec/../spec/fixtures/ext/controller/second" => ["second_controller.rb",
34
+ "third_controller.rb"] }
35
+ mapped_file = ObjectLoader.map_file_to_subdir
36
+ mapped_file.should == result
37
+ end
38
+
39
+ it "should get the camelized ext sub directory" do
40
+ subdir = "/usr/pub/projects/lamed/spec/../spec/fixtures/ext/controller/second"
41
+ ext_subdir = ObjectLoader.camelize_ext_subdir(subdir)
42
+ ext_subdir.should == [:Controller, :Second]
43
+ end
44
+
45
+ it "should load path symbols as objects" do
46
+ camelized_path = [:Controller, :Second]
47
+ klass = ObjectLoader.create_object_from_camelized_path(camelized_path)
48
+ klass.should == Lamed::Controller::Second
49
+ end
50
+
51
+ it "should create new Controller objects from files" do
52
+ subdir, file_name = "/usr/pub/projects/lamed/spec/../spec/fixtures/ext/controller/second",
53
+ ["second_controller.rb", "third_controller.rb"]
54
+ new_objects = ObjectLoader.load_new_object(subdir, file_name)
55
+ Object.constants.include?(:SecondController).should == true
56
+ Object.constants.include?(:ThirdController).should == true
57
+ # Clean up
58
+ Object.instance_eval { [:SecondController, :ThirdController].each { |o| remove_const o } }
59
+ end
60
+
61
+ it "should create new Record Objects from files" do
62
+ subdir, file_name = "/usr/pub/projects/lamed/spec/../spec/fixtures/ext/record",
63
+ ["foo_record.rb", "bar_record.rb"]
64
+ new_objects = ObjectLoader.load_new_object(subdir, file_name)
65
+ Object.constants.include?(:FooRecord).should == true
66
+ Object.constants.include?(:BarRecord).should == true
67
+ # Clean up
68
+ Object.instance_eval { [:BarRecord, :FooRecord].each { |o| remove_const o } }
69
+ end
70
+
71
+ it "should create a new view path for the new class" do
72
+ camelized_ext_subdir = [:Controller, :Second]
73
+ view_path = ObjectLoader.create_view_path(camelized_ext_subdir)
74
+ view_path.should == "/usr/pub/projects/lamed/spec/../spec/fixtures/ext/view/second"
75
+ end
76
+
77
+ it "should move new objects to new Lamed class/modules" do
78
+ load 'lib/lamed/object_loader.rb'
79
+ subdir, file_name = "/usr/pub/projects/lamed/spec/../spec/fixtures/ext/controller/second",
80
+ ["second_controller.rb", "third_controller.rb"]
81
+ ObjectLoader.load_new_object_into_klass(subdir, file_name)
82
+ Object::Lamed::Controller::Second.constants.should == [:SecondController, :ThirdController]
83
+ Object::Lamed::Controller::Second::ThirdController.class.should == Class
84
+ end
85
+
86
+ it "should check to see if new objects were removed from Object" do
87
+ Object.constants.include?(:SecondController).should == false
88
+ Object.constants.include?(:ThirdController).should == false
89
+ end
90
+
91
+ it "should check the view path for the new objects" do
92
+ Object::Lamed::Controller::Second::SecondController.path.should == "/usr/pub/projects/lamed/spec/fixtures/ext/view/second"
93
+ Object::Lamed::Controller::Second::ThirdController.path.should == "/usr/pub/projects/lamed/spec/fixtures/ext/view/second"
94
+ end
95
+
96
+ it "should load up controllers" do
97
+ ObjectLoader.load_new_objects(:controller)
98
+ Lamed.constants.should == [:Helper, :Lib, :Record, :Controller, :ObjectLoader]
99
+ Lamed::Controller.constants.should == [:Second, :FirstController, :VERSION, :Builder, :Cascade, :Chunked, :CommonLogger,
100
+ :ConditionalGet, :ContentLength, :ContentType, :File, :Deflater, :Directory,
101
+ :ForwardRequest, :Handler, :Head, :Lint, :Lock, :MethodOverride, :Mime,
102
+ :Recursive, :Reloader, :ShowExceptions, :ShowStatus, :Static, :URLMap, :Utils,
103
+ :MockRequest, :MockResponse, :Request, :Response, :Auth, :Session, :Adapter,
104
+ :Template, :ContextMiss, :Context]
105
+ Lamed::Controller::Second.constants.should == [:SecondController, :ThirdController]
106
+ end
107
+
108
+ it "should load up records" do
109
+ ObjectLoader.load_new_objects(:record)
110
+ Lamed.constants.should == [:Helper, :Lib, :Record, :Controller, :ObjectLoader]
111
+ Lamed::Record.constants.should == [:BarRecord, :FooRecord]
112
+ end
113
+
114
+ end
115
+
116
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,6 @@
1
+ require 'spec'
2
+ require 'spec/autorun'
3
+
4
+ Spec::Runner.configure do |config|
5
+
6
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lamed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Lee Chang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-12 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rack
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "1.0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: mustache
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Yet another LaMe Ruby Web Framework
36
+ email: leetchang@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - lib/lamed.rb
52
+ - lib/lamed/controller.rb
53
+ - lib/lamed/helper.rb
54
+ - lib/lamed/initializer.rb
55
+ - lib/lamed/lib.rb
56
+ - lib/lamed/main.rb
57
+ - lib/lamed/mysql.rb
58
+ - lib/lamed/object_loader.rb
59
+ - lib/lamed/record.rb
60
+ - lib/lamed/redis.rb
61
+ - spec/fixtures/conf/config.yml
62
+ - spec/fixtures/conf/database.yml
63
+ - spec/fixtures/ext/controller/first_controller.rb
64
+ - spec/fixtures/ext/controller/second/second_controller.rb
65
+ - spec/fixtures/ext/controller/second/third_controller.rb
66
+ - spec/fixtures/ext/record/bar_record.rb
67
+ - spec/fixtures/ext/record/foo_record.rb
68
+ - spec/helpers_spec.rb
69
+ - spec/initializer_spec.rb
70
+ - spec/lame_spec.rb
71
+ - spec/object_loader_spec.rb
72
+ - spec/spec.opts
73
+ - spec/spec_helper.rb
74
+ has_rdoc: true
75
+ homepage: http://github.com/onemorehill/lamed
76
+ licenses: []
77
+
78
+ post_install_message:
79
+ rdoc_options:
80
+ - --charset=UTF-8
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ version:
95
+ requirements: []
96
+
97
+ rubyforge_project:
98
+ rubygems_version: 1.3.5
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Get LaMeD
102
+ test_files:
103
+ - spec/fixtures/ext/controller/first_controller.rb
104
+ - spec/fixtures/ext/controller/second/second_controller.rb
105
+ - spec/fixtures/ext/controller/second/third_controller.rb
106
+ - spec/fixtures/ext/record/bar_record.rb
107
+ - spec/fixtures/ext/record/foo_record.rb
108
+ - spec/helpers_spec.rb
109
+ - spec/initializer_spec.rb
110
+ - spec/lame_spec.rb
111
+ - spec/object_loader_spec.rb
112
+ - spec/spec_helper.rb