ar_lightning 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 52964be6eff854e32288e15aefa4c707bf604a49
4
+ data.tar.gz: 3db273b8e6862d1e4f1f4c06bb24c67d000e1544
5
+ SHA512:
6
+ metadata.gz: f62f3f5b93a86bda36412c028c48e6924c9fba6e941d804f2a4517730deb07e3d89f838081e88da515928ba68a81269a633ea2445327742996883bfee5438b94
7
+ data.tar.gz: bdf2157d444ee0cc991ba0b0ab34db2d3f61b9c3044d7564e9f04238719de1b152d004f39654f58db3aab6715da16c3ef8cf907074661ec832570daf2afde35a
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ar_lightning.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Luke
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # ArLightning
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ar_lightning'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ar_lightning
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ar_lightning/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ar_lightning"
8
+ spec.version = ArLightning::VERSION
9
+ spec.authors = ["Luke"]
10
+ spec.email = ["email@luke-roberts.info"]
11
+ spec.description = %q{This gem implements some of the ideas discussed in this post:http://brainspec.com/blog/2012/09/28/lightning-json-in-rails/ for LIGHTNING fast rails APIs}
12
+ spec.summary = %q{Lightning fast APIs as discussed in this post:http://brainspec.com/blog/2012/09/28/lightning-json-in-rails/}
13
+ spec.homepage = "https://github.com/lukeroberts1990/ar_lightning"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "active_record"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "sqlite3"
27
+ end
@@ -0,0 +1,4 @@
1
+ require "ar_lightning/version"
2
+ require "ar_lightning/active_record"
3
+
4
+ ActiveRecord::Base.extend ARLightning::ActiveRecord
@@ -0,0 +1,12 @@
1
+ module ARLightning
2
+ module ActiveRecord
3
+ def lightning(*args)
4
+ columns = args.present? ? args : column_names
5
+ connection.select_all(select(columns).arel).each do |attrs|
6
+ attrs.each_key do |attr|
7
+ attrs[attr] = type_cast_attribute(attr, attrs)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module ArLightning
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+ require 'benchmark'
3
+
4
+ describe ActiveRecord do
5
+ before do
6
+ 20.times do
7
+ Item.create(field_1:'boo', field_2:'boo', field_3:1)
8
+ Item.create(field_1:'hoo', field_2:'hoo', field_3:2)
9
+ end
10
+ end
11
+ context "sanity check" do
12
+ specify { Item.count.should be == 40 }
13
+ end
14
+ describe ".lightning" do
15
+ specify { Item.lightning.count.should be == 40 }
16
+ specify { Item.lightning.first.should be == { "field_1" => 'boo', "field_2" => 'boo', "field_3" => 1 } }
17
+ specify { Item.lightning.last.should be == { "field_1" => 'hoo', "field_2" => 'hoo', "field_3" => 2 } }
18
+ end
19
+ context "with an existing query" do
20
+ subject { Item.where(field_1:'boo') }
21
+ specify { subject.lightning.count.should be == 20 }
22
+ specify { subject.lightning.first.should be == { "field_1" => 'boo', "field_2" => 'boo', "field_3" => 1 } }
23
+ specify { subject.lightning.last.should be == { "field_1" => 'boo', "field_2" => 'boo', "field_3" => 1 } }
24
+ end
25
+ context "with specified fields" do
26
+ subject { Item.lightning(:field_1) }
27
+ specify { subject.first.should be == { 'field_1' => 'boo' } }
28
+ end
29
+
30
+ describe "performance" do
31
+ let!(:active_record) do
32
+ Benchmark.realtime{
33
+ 100.times do
34
+ Item.all
35
+ end
36
+ }
37
+ end
38
+ let!(:lightning) do
39
+ Benchmark.realtime{
40
+ 100.times do
41
+ Item.lightning
42
+ end
43
+ }
44
+ end
45
+ specify { puts "active record = #{active_record}" }
46
+ specify { puts "lightning = #{lightning}" }
47
+ specify { active_record.should be > lightning }
48
+ end
49
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'item' do
4
+ subject { Item.create(field_1:'boo', field_2:'hoo', field_3:1) }
5
+ specify { subject.field_1.should == 'boo' }
6
+ specify { subject.field_2.should == 'hoo' }
7
+ specify { subject.field_3.should == 1 }
8
+ end
@@ -0,0 +1,23 @@
1
+ require 'active_record'
2
+ require 'ar_lightning'
3
+
4
+ ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
5
+ ActiveRecord::Migrator.up "db/migrate"
6
+
7
+ ActiveRecord::Migration.create_table :items, :id => false do |t|
8
+ t.string :field_1
9
+ t.string :field_2
10
+ t.integer :field_3
11
+ end
12
+
13
+ class Item < ActiveRecord::Base
14
+ end
15
+
16
+ RSpec.configure do |config|
17
+ config.around do |example|
18
+ ActiveRecord::Base.transaction do
19
+ example.run
20
+ raise ActiveRecord::Rollback
21
+ end
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ar_lightning
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Luke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: active_record
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: This gem implements some of the ideas discussed in this post:http://brainspec.com/blog/2012/09/28/lightning-json-in-rails/
84
+ for LIGHTNING fast rails APIs
85
+ email:
86
+ - email@luke-roberts.info
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - ar_lightning.gemspec
97
+ - lib/ar_lightning.rb
98
+ - lib/ar_lightning/active_record.rb
99
+ - lib/ar_lightning/version.rb
100
+ - spec/active_model_spec.rb
101
+ - spec/ar_lightning_spec.rb
102
+ - spec/spec_helper.rb
103
+ homepage: https://github.com/lukeroberts1990/ar_lightning
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.0.0
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Lightning fast APIs as discussed in this post:http://brainspec.com/blog/2012/09/28/lightning-json-in-rails/
127
+ test_files:
128
+ - spec/active_model_spec.rb
129
+ - spec/ar_lightning_spec.rb
130
+ - spec/spec_helper.rb