tsukasaoishi-miyazakiresistance 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt
CHANGED
data/README.rdoc
CHANGED
@@ -35,6 +35,8 @@ MiyazakiResistance is a library like ActiveRecord to use Tokyo Tyrant.
|
|
35
35
|
Example.find(:first)
|
36
36
|
Example.find(:all)
|
37
37
|
Example.find(:all, :conditions => ["name = ? age = ?", "tsukasa", 34], :order => "created_at DESC", :offset => 1, :limit => 1)
|
38
|
+
Example.find_by_name("tsukasa")
|
39
|
+
Example.find_all_by_name_and_age("tsukasa", 34)
|
38
40
|
|
39
41
|
|
40
42
|
* You can write in config file
|
@@ -58,7 +60,6 @@ MiyazakiResistance is a library like ActiveRecord to use Tokyo Tyrant.
|
|
58
60
|
- server: localhost
|
59
61
|
port: 1978
|
60
62
|
role: readonly
|
61
|
-
log_file: log/miyazakiresistance.log
|
62
63
|
|
63
64
|
== REQUIREMENTS:
|
64
65
|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module MiyazakiResistance
|
2
|
+
module Enhance
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def method_missing(name, *arguments, &block)
|
9
|
+
if match = finder_attribute_names(name)
|
10
|
+
finder = match[:finder]
|
11
|
+
conditions = match[:cols].map{|col| "#{col} = ?"}.join(" ")
|
12
|
+
|
13
|
+
self.class_eval %Q|
|
14
|
+
def self.#{name}(*args)
|
15
|
+
options = args.last.is_a?(::Hash) ? pop : {}
|
16
|
+
options.update(:conditions => ["#{conditions}", args].flatten)
|
17
|
+
self.find(:#{finder}, options)
|
18
|
+
end
|
19
|
+
|
|
20
|
+
|
21
|
+
__send__(name, *arguments)
|
22
|
+
else
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def finder_attribute_names(name)
|
30
|
+
ret = {:finder => :first, :cols => nil}
|
31
|
+
if name.to_s =~ /^find_(all_by|by)_([_a-zA-Z]\w*)$/
|
32
|
+
ret[:finder] = :all if $1 == "all_by"
|
33
|
+
if cols = $2
|
34
|
+
cols = cols.split("_and_")
|
35
|
+
all_cols = self.all_columns.keys
|
36
|
+
ret[:cols] = cols if cols.all?{|col| all_cols.include?(col)}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
(ret[:cols].nil? || ret[:cols].empty?) ? nil : ret
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -10,7 +10,7 @@ module MiyazakiResistance
|
|
10
10
|
|
11
11
|
module ClassMethods
|
12
12
|
def logger
|
13
|
-
class_variable_get("@@logger") || (logger = Logger.new(
|
13
|
+
class_variable_get("@@logger") || (logger = Logger.new(default_log_file_path))
|
14
14
|
end
|
15
15
|
|
16
16
|
def logger=(target)
|
@@ -34,6 +34,10 @@ module MiyazakiResistance
|
|
34
34
|
def log_msg(str)
|
35
35
|
"[#{Time.now.strftime("%Y/%m/%d %H:%M:%S")}] #{str}"
|
36
36
|
end
|
37
|
+
|
38
|
+
def default_log_file_path
|
39
|
+
File.directory?("log") ? "log/miyazakiresistance.log" : "miyazakiresistance.log"
|
40
|
+
end
|
37
41
|
end
|
38
42
|
|
39
43
|
module InstanceMethods
|
@@ -22,8 +22,6 @@ module MiyazakiResistance
|
|
22
22
|
env = env.to_s
|
23
23
|
conf = YAML.load_file(file)
|
24
24
|
|
25
|
-
class_variable_set("@@logger", Logger.new(conf["log_file"])) if conf["log_file"]
|
26
|
-
|
27
25
|
if (config = conf[env]).nil?
|
28
26
|
logger_fatal "specified environment(#{env}) is not found in conig file(#{file})"
|
29
27
|
return
|
data/lib/miyazakiresistance.rb
CHANGED
@@ -6,18 +6,15 @@ require 'timeout'
|
|
6
6
|
require 'tokyotyrant'
|
7
7
|
|
8
8
|
Dir.glob("#{File.join(File.dirname(__FILE__), "../initializers")}/*.rb").each{|path| require path}
|
9
|
-
|
10
|
-
require 'miyazaki_resistance/tokyo_connection'
|
11
|
-
require 'miyazaki_resistance/miyazaki_logger'
|
12
|
-
require 'miyazaki_resistance/base'
|
13
|
-
require 'miyazaki_resistance/error'
|
9
|
+
Dir.glob("#{File.join(File.dirname(__FILE__), "miyazaki_resistance")}/*.rb").each{|path| require path}
|
14
10
|
|
15
11
|
module MiyazakiResistance
|
16
|
-
VERSION = '0.1.
|
12
|
+
VERSION = '0.1.3'
|
17
13
|
end
|
18
14
|
|
19
15
|
MiyazakiResistance::Base.class_eval do
|
20
16
|
include MiyazakiResistance::TokyoConnection
|
17
|
+
include MiyazakiResistance::Enhance
|
21
18
|
include MiyazakiResistance::MiyazakiLogger
|
22
19
|
|
23
20
|
OPERATIONS = {
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tsukasaoishi-miyazakiresistance
|
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
|
- Tsukasa OISHI
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- lib/miyazaki_resistance/error.rb
|
54
54
|
- lib/miyazaki_resistance/miyazaki_logger.rb
|
55
55
|
- lib/miyazaki_resistance/tokyo_connection.rb
|
56
|
+
- lib/miyazaki_resistance/enhance.rb
|
56
57
|
- initializers/rdb.rb
|
57
58
|
has_rdoc: true
|
58
59
|
homepage: http://www.kaeruspoon.net/keywords/MiyazakiResistance
|