activerecord-raw-data 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+
6
+ script: bundle exec rake spec
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # ActiveRecord::RawData
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/hotchpotch/activerecord-raw-data.png?branch=master)](http://travis-ci.org/hotchpotch/activerecord-raw-data)
4
+
3
5
  Get ActiveRecord raw data. Hash, Array..
4
6
 
5
7
  ## Requirements
@@ -22,10 +24,18 @@ Or install it yourself as:
22
24
 
23
25
  ## Usage
24
26
 
25
- User.raw_data #=> [{"id" => 1, "name" => "alice"}, {"id" => 2, "name" => "bob"}, ...]
26
- User.raw_rows #=> [[1, "alice"], [2, "bob"], ...]
27
+ User.raw_data
28
+ #=> [{"id" => 1, "name" => "alice"}, {"id" => 2, "name" => "bob"}, ...]
29
+
30
+ User.raw_rows
31
+ #=> [[1, "alice"], [2, "bob"], ...]
32
+
27
33
  # raw_values like ActiveRecord::Base.pluck. if your AR support, should use pluck.
28
- User.select(:name).raw_values #=> ["alice", "bob, ...]
34
+ User.select(:name).raw_values
35
+ #=> ["alice", "bob", ...]
36
+
37
+ User.raw_data_by_sql('SELECT SUBSTR(name, 1, 1) AS initial FROM users ORDER BY users.name DESC')
38
+ #=> [{"initial" => "c"}, {"initial" => "b"}, ...]
29
39
 
30
40
  ## Contributing
31
41
 
@@ -34,3 +44,7 @@ Or install it yourself as:
34
44
  3. Commit your changes (`git commit -am 'Added some feature'`)
35
45
  4. Push to the branch (`git push origin my-new-feature`)
36
46
  5. Create new Pull Request
47
+
48
+ ## Author
49
+
50
+ Yuichi Tateno
@@ -20,6 +20,10 @@ module ActiveRecord
20
20
  def raw_values
21
21
  connection.select_values scoped.to_sql
22
22
  end
23
+
24
+ def raw_data_by_sql(sql)
25
+ connection.select_all sanitize_sql(sql)
26
+ end
23
27
  end
24
28
  end
25
29
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module RawData
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -52,4 +52,12 @@ describe ActiveRecord::RawData do
52
52
  it "should result raw values with select" do
53
53
  User.select(:name).raw_values.should eq ['alice', 'bob', 'carol']
54
54
  end
55
+
56
+ it "should result raw values with complex sql" do
57
+ User.raw_data_by_sql('SELECT SUBSTR(name, 1, 1) AS initial FROM users ORDER BY users.name DESC').should eq [
58
+ {"initial" => "c"},
59
+ {"initial" => "b"},
60
+ {"initial" => "a"}
61
+ ]
62
+ end
55
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-raw-data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-27 00:00:00.000000000 Z
12
+ date: 2012-03-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &2180053640 !ruby/object:Gem::Requirement
16
+ requirement: &2191751760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2180053640
24
+ version_requirements: *2191751760
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &2180053120 !ruby/object:Gem::Requirement
27
+ requirement: &2191751240 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.8.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2180053120
35
+ version_requirements: *2191751240
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &2180052640 !ruby/object:Gem::Requirement
38
+ requirement: &2191750760 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.8.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2180052640
46
+ version_requirements: *2191750760
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: pry
49
- requirement: &2180052160 !ruby/object:Gem::Requirement
49
+ requirement: &2191750280 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2180052160
57
+ version_requirements: *2191750280
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sqlite3
60
- requirement: &2180051680 !ruby/object:Gem::Requirement
60
+ requirement: &2191749800 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2180051680
68
+ version_requirements: *2191749800
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: database_cleaner
71
- requirement: &2180051200 !ruby/object:Gem::Requirement
71
+ requirement: &2191749320 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2180051200
79
+ version_requirements: *2191749320
80
80
  description: Get raw data from ActiveRecord
81
81
  email:
82
82
  - hotchpotch@gmail.com
@@ -85,6 +85,7 @@ extensions: []
85
85
  extra_rdoc_files: []
86
86
  files:
87
87
  - .gitignore
88
+ - .travis.yml
88
89
  - Gemfile
89
90
  - LICENSE
90
91
  - README.md
@@ -109,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
110
  version: '0'
110
111
  segments:
111
112
  - 0
112
- hash: 1942990223498134344
113
+ hash: -243093227698944520
113
114
  required_rubygems_version: !ruby/object:Gem::Requirement
114
115
  none: false
115
116
  requirements:
@@ -118,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
119
  version: '0'
119
120
  segments:
120
121
  - 0
121
- hash: 1942990223498134344
122
+ hash: -243093227698944520
122
123
  requirements: []
123
124
  rubyforge_project:
124
125
  rubygems_version: 1.8.17