lazy-attribute 0.0.2 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/.rakeTasks +2 -2
- data/README.md +25 -4
- data/lazy-attribute.gemspec +8 -8
- data/lib/lazy/attribute/lazy_attribute.rb +7 -2
- data/lib/lazy/attribute/version.rb +1 -1
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd598124eaa3acf6fbc9a237d358c90c352f7551
|
4
|
+
data.tar.gz: 1bc0ed90fea729014c97d987554020f165bd0d27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f60e9027d3a4fba2bafab2f2bb0b3fdd658fafa625d9e800e1d15b6aa03908e3e182c6b668a91d653e40a125028498a20c528ddd884493fb7c27b89b1bf2be7
|
7
|
+
data.tar.gz: d09841dd9f20c7dc3ce104cc4d625506ec1a95b27af13e1091f704bf405137495a94de095d51a02401432d4cc9dae16ec283c274047ed15911619fbde8957586
|
data/.idea/.rakeTasks
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
2
|
<Settings><!--This file was automatically generated by Ruby plugin.
|
3
3
|
You are allowed to:
|
4
4
|
1. Remove rake task
|
5
5
|
2. Add existing rake tasks
|
6
6
|
To add existing rake tasks automatically delete this file and reload the project.
|
7
|
-
--><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build lazy-attribute-0.0.1.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Build and install lazy-attribute-0.0.1.gem into system gems" fullCmd="install" taksId="install" /><RakeTask description="Create tag v0.0.1 and build and push lazy-attribute-0.0.1.gem to Rubygems" fullCmd="release" taksId="release" /></RakeGroup></Settings>
|
7
|
+
--><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build lazy-attribute-0.0.1.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Build and install lazy-attribute-0.0.1.gem into system gems" fullCmd="install" taksId="install" /><RakeTask description="Create tag v0.0.1 and build and push lazy-attribute-0.0.1.gem to Rubygems" fullCmd="release" taksId="release" /></RakeGroup></Settings>
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
# Lazy
|
1
|
+
# Lazy Attribute
|
2
2
|
|
3
|
-
|
3
|
+
This gem provides a simple and extremely flexible way to use most frequent find_by query in a model.
|
4
|
+
You can minimize find_by query of a particular attribute in a model using lazy attribute gem.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -18,11 +19,31 @@ Or install it yourself as:
|
|
18
19
|
|
19
20
|
## Usage
|
20
21
|
|
21
|
-
|
22
|
+
In Model
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
class User < ActiveRecord::Base
|
26
|
+
|
27
|
+
lazy_attribute :email
|
28
|
+
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
User['sample@email.com']
|
34
|
+
```
|
35
|
+
|
36
|
+
Will give you the user object matches with the email and will return nil if record not found
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
lazy_attribute :email, :raise_error => true
|
40
|
+
```
|
41
|
+
|
42
|
+
Will give you the user object matches with the email and will raise ``` ActiveRecord::RecordNotFound ``` Exception if record not found
|
22
43
|
|
23
44
|
## Contributing
|
24
45
|
|
25
|
-
1. Fork it ( https://github.com/
|
46
|
+
1. Fork it ( https://github.com/selvachezhian/lazy-attribute/fork )
|
26
47
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
48
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
49
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lazy-attribute.gemspec
CHANGED
@@ -4,21 +4,21 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'lazy/attribute/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'lazy-attribute'
|
8
8
|
spec.version = Lazy::Attribute::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email =
|
11
|
-
spec.summary = %q{
|
12
|
-
spec.description = %q{
|
9
|
+
spec.authors = ['Selva Chezhian', 'Saravanan Hari']
|
10
|
+
spec.email = %w(selvachezhian.labam@gmail.com sarhari@gmail.com)
|
11
|
+
spec.summary = %q{Minimizing find_by query for a single repeated attribute}
|
12
|
+
spec.description = %q{This gem provides a simple and extremely flexible way to use most frequent find_by query in a model. You can minimize find_by query of a particular attribute in a model using lazy attribute gem.}
|
13
13
|
spec.homepage = 'https://github.com/selvachezhian/lazy-attribute'
|
14
|
-
spec.license =
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_development_dependency
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
22
22
|
spec.add_development_dependency 'rake', '~> 0'
|
23
23
|
spec.add_dependency 'activerecord', '~> 4.1'
|
24
24
|
end
|
@@ -2,14 +2,19 @@ module Lazy
|
|
2
2
|
module Attribute
|
3
3
|
module ClassMethods
|
4
4
|
|
5
|
-
def lazy_attribute(attr)
|
5
|
+
def lazy_attribute(attr, options = {})
|
6
6
|
singleton_class.instance_eval do
|
7
7
|
define_method('[]') do |ident|
|
8
|
-
|
8
|
+
options[:raise_error] ||= false
|
9
|
+
send(dynamic_find_method(options[:raise_error]), { attr.to_sym => ident })
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
14
|
+
def dynamic_find_method(raise_error = false)
|
15
|
+
raise_error ? 'find_by!' : 'find_by'
|
16
|
+
end
|
17
|
+
|
13
18
|
end
|
14
19
|
end
|
15
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazy-attribute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Selva Chezhian
|
8
|
+
- Saravanan Hari
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
12
|
+
date: 2014-12-17 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -52,9 +53,12 @@ dependencies:
|
|
52
53
|
- - "~>"
|
53
54
|
- !ruby/object:Gem::Version
|
54
55
|
version: '4.1'
|
55
|
-
description:
|
56
|
+
description: This gem provides a simple and extremely flexible way to use most frequent
|
57
|
+
find_by query in a model. You can minimize find_by query of a particular attribute
|
58
|
+
in a model using lazy attribute gem.
|
56
59
|
email:
|
57
60
|
- selvachezhian.labam@gmail.com
|
61
|
+
- sarhari@gmail.com
|
58
62
|
executables: []
|
59
63
|
extensions: []
|
60
64
|
extra_rdoc_files: []
|
@@ -99,5 +103,5 @@ rubyforge_project:
|
|
99
103
|
rubygems_version: 2.2.2
|
100
104
|
signing_key:
|
101
105
|
specification_version: 4
|
102
|
-
summary:
|
106
|
+
summary: Minimizing find_by query for a single repeated attribute
|
103
107
|
test_files: []
|