dragoon_system 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dragoon_system}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["zhanyinan"]
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  "dragoon_system.gemspec",
28
28
  "lib/active_record/base_patch.rb",
29
29
  "lib/dragoon_system.rb",
30
+ "lib/patches.rb",
30
31
  "lib/string_path.rb",
31
32
  "test/helper.rb",
32
33
  "test/test_dragoon_system.rb"
@@ -20,13 +20,33 @@ module ActiveRecord
20
20
  end
21
21
  end
22
22
 
23
+ def newest
24
+ scoped(:order => "#{self.table_name}.updated_at desc")
25
+ end
26
+
27
+ def desc
28
+ scoped(:order => "#{self.table_name}.created_at desc")
29
+ end
30
+
31
+ def regexp(field, data, table = table_name)
32
+ table_name = if table.is_a?(String)
33
+ table
34
+ elsif table < ActiveRecord::Base
35
+ table.table_name
36
+ else
37
+ raise ArgumentError
38
+ end
39
+
40
+ regexp_condition(field, data, table_name)
41
+ end
42
+
23
43
  private
24
44
 
25
- def or_empty_hash(param)
45
+ def or_empty_scope(param)
26
46
  unless param.blank?
27
47
  yield
28
48
  else
29
- {}
49
+ scoped
30
50
  end
31
51
  end
32
52
 
@@ -37,6 +57,13 @@ module ActiveRecord
37
57
  input.split(" ").uniq
38
58
  end
39
59
  end
60
+
61
+ def regexp_condition(field, data, table)
62
+ or_empty_scope(data) do
63
+ data = handle_input(data).join("|")
64
+ {:conditions => ["#{table}.#{field} regexp ? ", data]}
65
+ end
66
+ end
40
67
  end
41
68
 
42
69
 
data/lib/patches.rb ADDED
@@ -0,0 +1,5 @@
1
+ class Module
2
+ def ah(*data)
3
+ ActiveSupport::OrderedHash.[](*data)
4
+ end
5
+ end
data/test/helper.rb CHANGED
@@ -8,7 +8,6 @@ rescue Bundler::BundlerError => e
8
8
  exit e.status_code
9
9
  end
10
10
  require 'test/unit'
11
- require 'shoulda'
12
11
 
13
12
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
13
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -1,7 +1,3 @@
1
1
  require 'helper'
2
2
 
3
- class TestDragoonSystem < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end
3
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dragoon_system
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - zhanyinan
@@ -100,6 +100,7 @@ files:
100
100
  - dragoon_system.gemspec
101
101
  - lib/active_record/base_patch.rb
102
102
  - lib/dragoon_system.rb
103
+ - lib/patches.rb
103
104
  - lib/string_path.rb
104
105
  - test/helper.rb
105
106
  - test/test_dragoon_system.rb