activerecord_lite 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 35d97fd18970f39220a27ef8276a454814aa653e
4
+ data.tar.gz: c9e5f1d7808c89117fe6664eb854c72fde57f6dc
5
+ SHA512:
6
+ metadata.gz: 673e2d14b2fe0bf082e3c2e7b01e2e1c69e7a2e8a98e8d0c4c07bf24a379516f930ad1f04385f05b568a633e14badc876399a465cf8cad6039742d94659a306e
7
+ data.tar.gz: 0e3da48fab306bbdcb2f8e91e766d610cf2d0bd51b1557ec4edf9b95a4a54a50d4a84a3e039750e825d52605ce135ef2e042cb45bcc17a8bdf240f0f67db047a
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.5
5
+ before_install: gem install bundler -v 1.13.7
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activerecord_lite.gemspec
4
+ gemspec
@@ -0,0 +1,36 @@
1
+ # ActiverecordLite
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/activerecord_lite`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'activerecord_lite'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install activerecord_lite
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/abacha/activerecord_lite.
36
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'activerecord_lite/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "activerecord_lite"
8
+ spec.version = ActiveRecordLite::VERSION
9
+ spec.authors = ["Adriano Bacha"]
10
+ spec.email = ["abacha@gmail.com"]
11
+
12
+ spec.summary = %q{lightweight activerecord queries}
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
15
+ f.match(%r{^(test|spec|features)/})
16
+ end
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.14"
20
+ spec.add_development_dependency "rspec", "~> 3.0"
21
+ spec.add_development_dependency "activerecord", ">= 4.0.0"
22
+ spec.add_development_dependency "sqlite3", "~> 1.3"
23
+ end
@@ -0,0 +1,3 @@
1
+ require "activerecord_lite/version"
2
+
3
+ require "activerecord_lite/base"
@@ -0,0 +1,34 @@
1
+ module ActiveRecordLite
2
+ module Base
3
+ def fetch_lite(*select_sql)
4
+ select_columns, columns = prepare(select_sql)
5
+ _struct = Struct.new(*columns)
6
+ sql = select(select_columns).to_sql
7
+ self.connection.select_all(sql).map { |result| _struct.new(*result.values) }
8
+ end
9
+
10
+ def pluck_first(attribute)
11
+ order(attribute).pluck(attribute).first
12
+ end
13
+
14
+ def pluck_last(attribute)
15
+ order(attribute).pluck(attribute).last
16
+ end
17
+
18
+ private
19
+ def prepare(select_sql)
20
+ first_key = select_sql[0]
21
+ if first_key.is_a?(Hash)
22
+ prepare_hash(first_key)
23
+ else
24
+ [select_sql, select_sql]
25
+ end
26
+ end
27
+
28
+ def prepare_hash(select_sql)
29
+ columns = select_sql.keys
30
+ select_columns = select_sql.map { |key, value| "#{value} #{key}" }.join(",")
31
+ [select_columns, columns]
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveRecordLite
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord_lite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adriano Bacha
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activerecord
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 4.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 4.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ description:
70
+ email:
71
+ - abacha@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - README.md
81
+ - activerecord_lite.gemspec
82
+ - lib/activerecord_lite.rb
83
+ - lib/activerecord_lite/base.rb
84
+ - lib/activerecord_lite/version.rb
85
+ homepage:
86
+ licenses: []
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.4.8
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: lightweight activerecord queries
108
+ test_files: []