lazy-attribute 3.1.1 → 3.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/README.md +3 -1
- data/Rakefile +3 -1
- data/lazy-attribute.gemspec +4 -2
- data/lib/lazy/attribute/lazy_attribute.rb +8 -29
- data/lib/lazy/attribute/version.rb +1 -1
- data/spec/lazy/attribute/lazy_attribute_spec.rb +28 -0
- data/spec/spec_helper.rb +4 -0
- metadata +38 -19
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MTY4MjdkMTFjOWIzNTcwZmUzY2ZiMTU3N2Q4NDIyYzY4NjZlN2EzMw==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c4725a9f464abc0ba205225cd030015de16f8160
|
4
|
+
data.tar.gz: 9fd550fd0fc061450b289d92534ab28464adb6e0
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NTg1NWFlNTNmMDE2NDE1YzFhZTU5Y2E5NGJjYTAwZGI0ZmRlN2VmNzU5OTNk
|
11
|
-
MTQ2ZTYwYmMwMzU4YWU5ZTM0NjQ4MmIzYTA4NjMxMDc2ZWJiZDk=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YjJiNjYwMzcwNTc2YTk4MmM0YzFhMmE4NTZiYWM5MDYzMWNlYzJjYTdkODA3
|
14
|
-
MTcwODkxNmU4Y2RkZTliODYzMDQ2ZGQ4NDJjNzJiMWI4NzRhNWFhYjFiYjA3
|
15
|
-
YThmZGU1MTU5OGIwYzU2Y2M2OGM4MzhiMjYxNTg0MDQxNjMxMDc=
|
6
|
+
metadata.gz: 7527058e4d773fd3ff8862738e62ade469844faf9f0f9bf4ad3cd76a93a6327db880c6e620f18718d4711cff153b7068d82fa6a4de3527985eabf8cc7cec6855
|
7
|
+
data.tar.gz: df6f5f924bb3fe2e9731bcade91a4dd640f68e8069104e00b4f9073670c84d21c2edcdd5393284e3923b45819f9bd976ac63a1df53cac6dbdb7343dff1edce98
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/selvachezhian/lazy-attribute.svg?branch=master)](https://travis-ci.org/selvachezhian/lazy-attribute)
|
2
|
+
|
1
3
|
# Lazy Attribute
|
2
4
|
|
3
5
|
This gem provides a simple and extremely flexible way to use most frequent find_by query in a model.
|
@@ -7,7 +9,7 @@ You can minimize find_by query of a particular attribute in a model using lazy a
|
|
7
9
|
|
8
10
|
Add this line to your application's Gemfile:
|
9
11
|
|
10
|
-
gem 'lazy-attribute'
|
12
|
+
gem 'lazy-attribute'
|
11
13
|
|
12
14
|
And then execute:
|
13
15
|
|
data/Rakefile
CHANGED
data/lazy-attribute.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'lazy/attribute/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'lazy-attribute'
|
8
8
|
spec.version = Lazy::Attribute::VERSION
|
9
|
-
spec.authors = ['Selva Chezhian', '
|
10
|
-
spec.email = %w(selvachezhian.labam@gmail.com
|
9
|
+
spec.authors = ['Selva Chezhian', 'Prasanna']
|
10
|
+
spec.email = %w(selvachezhian.labam@gmail.com prasannacse2005@gmail.com)
|
11
11
|
spec.summary = %q{Minimizing find_by query for a single repeated attribute}
|
12
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'
|
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
23
23
|
spec.add_development_dependency 'rake', '~> 0'
|
24
24
|
spec.add_development_dependency 'yard'
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
|
25
27
|
|
26
28
|
spec.add_dependency 'activerecord', '~> 4.1'
|
27
29
|
|
@@ -13,47 +13,26 @@ module Lazy
|
|
13
13
|
# ActiveRecord::RecordInvalid: Validation failed exception if any validation error thrown at the time of creation missing record
|
14
14
|
#
|
15
15
|
# @return [none]
|
16
|
+
|
16
17
|
def lazy_attribute(attribute, options = {})
|
17
|
-
default_options = {
|
18
|
+
default_options = {raise_error: false, key: '[]', create_if_not_found: false}
|
18
19
|
options.reverse_merge!(default_options)
|
19
20
|
|
20
21
|
singleton_class.instance_eval do
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
define_method('[]') do |identifier|
|
25
|
-
send_dynamic_method(options, attribute, identifier)
|
26
|
-
end
|
27
|
-
|
28
|
-
else
|
29
|
-
|
30
|
-
define_method(options[:key]) do |identifier|
|
31
|
-
send_dynamic_method(options, attribute, identifier)
|
32
|
-
end
|
33
|
-
|
22
|
+
define_method(options[:key]) do |identifier|
|
23
|
+
send(dynamic_find_method(options), {attribute.to_sym => identifier})
|
34
24
|
end
|
35
|
-
|
36
25
|
end
|
37
26
|
end
|
38
27
|
|
39
28
|
private
|
40
29
|
|
41
30
|
def dynamic_find_method(options)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
elsif !options[:raise_error] && options[:create_if_not_found]
|
47
|
-
'find_or_create_by'
|
48
|
-
elsif !options[:raise_error] && !options[:create_if_not_found]
|
49
|
-
'find_by'
|
50
|
-
end
|
31
|
+
create = 'or_create' if options[:create_if_not_found]
|
32
|
+
method = ['find', create, 'by'].compact.join('_')
|
33
|
+
method += '!' if options[:raise_error]
|
34
|
+
method
|
51
35
|
end
|
52
|
-
|
53
|
-
def send_dynamic_method(options, attr, identifier)
|
54
|
-
send(dynamic_find_method(options), { attr.to_sym => identifier })
|
55
|
-
end
|
56
|
-
|
57
36
|
end
|
58
37
|
end
|
59
38
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
include Lazy::Attribute::ClassMethods
|
3
|
+
|
4
|
+
describe 'Lazy Attribute' do
|
5
|
+
|
6
|
+
context 'Dynamic Find' do
|
7
|
+
it 'should return find_by if no options are passed' do
|
8
|
+
method_name = dynamic_find_method({})
|
9
|
+
expect(method_name).to eql('find_by')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should return find_or_create_by if create_if_not_found options is passed' do
|
13
|
+
method_name = dynamic_find_method({create_if_not_found: true})
|
14
|
+
expect(method_name).to eql('find_or_create_by')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should return find_by! if raise_error option is passed' do
|
18
|
+
method_name = dynamic_find_method({raise_error: true})
|
19
|
+
expect(method_name).to eql('find_by!')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should return find_or_create_by! if raise_error and create_if_not_found options are passed' do
|
23
|
+
method_name = dynamic_find_method({create_if_not_found: true, raise_error: true})
|
24
|
+
expect(method_name).to eql('find_or_create_by!')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,71 +1,84 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazy-attribute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Selva Chezhian
|
8
|
-
-
|
9
|
-
- Elavarasu
|
8
|
+
- Prasanna
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2016-03-24 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: bundler
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
17
|
requirements:
|
19
|
-
- - ~>
|
18
|
+
- - "~>"
|
20
19
|
- !ruby/object:Gem::Version
|
21
20
|
version: '1.6'
|
22
21
|
type: :development
|
23
22
|
prerelease: false
|
24
23
|
version_requirements: !ruby/object:Gem::Requirement
|
25
24
|
requirements:
|
26
|
-
- - ~>
|
25
|
+
- - "~>"
|
27
26
|
- !ruby/object:Gem::Version
|
28
27
|
version: '1.6'
|
29
28
|
- !ruby/object:Gem::Dependency
|
30
29
|
name: rake
|
31
30
|
requirement: !ruby/object:Gem::Requirement
|
32
31
|
requirements:
|
33
|
-
- - ~>
|
32
|
+
- - "~>"
|
34
33
|
- !ruby/object:Gem::Version
|
35
34
|
version: '0'
|
36
35
|
type: :development
|
37
36
|
prerelease: false
|
38
37
|
version_requirements: !ruby/object:Gem::Requirement
|
39
38
|
requirements:
|
40
|
-
- - ~>
|
39
|
+
- - "~>"
|
41
40
|
- !ruby/object:Gem::Version
|
42
41
|
version: '0'
|
43
42
|
- !ruby/object:Gem::Dependency
|
44
43
|
name: yard
|
45
44
|
requirement: !ruby/object:Gem::Requirement
|
46
45
|
requirements:
|
47
|
-
- -
|
46
|
+
- - ">="
|
48
47
|
- !ruby/object:Gem::Version
|
49
48
|
version: '0'
|
50
49
|
type: :development
|
51
50
|
prerelease: false
|
52
51
|
version_requirements: !ruby/object:Gem::Requirement
|
53
52
|
requirements:
|
54
|
-
- -
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
55
68
|
- !ruby/object:Gem::Version
|
56
69
|
version: '0'
|
57
70
|
- !ruby/object:Gem::Dependency
|
58
71
|
name: activerecord
|
59
72
|
requirement: !ruby/object:Gem::Requirement
|
60
73
|
requirements:
|
61
|
-
- - ~>
|
74
|
+
- - "~>"
|
62
75
|
- !ruby/object:Gem::Version
|
63
76
|
version: '4.1'
|
64
77
|
type: :runtime
|
65
78
|
prerelease: false
|
66
79
|
version_requirements: !ruby/object:Gem::Requirement
|
67
80
|
requirements:
|
68
|
-
- - ~>
|
81
|
+
- - "~>"
|
69
82
|
- !ruby/object:Gem::Version
|
70
83
|
version: '4.1'
|
71
84
|
description: This gem provides a simple and extremely flexible way to use most frequent
|
@@ -73,13 +86,14 @@ description: This gem provides a simple and extremely flexible way to use most f
|
|
73
86
|
in a model using lazy attribute gem.
|
74
87
|
email:
|
75
88
|
- selvachezhian.labam@gmail.com
|
76
|
-
-
|
77
|
-
- elavarasu.pandiyan@gmail.com
|
89
|
+
- prasannacse2005@gmail.com
|
78
90
|
executables: []
|
79
91
|
extensions: []
|
80
92
|
extra_rdoc_files: []
|
81
93
|
files:
|
82
|
-
- .gitignore
|
94
|
+
- ".gitignore"
|
95
|
+
- ".rspec"
|
96
|
+
- ".travis.yml"
|
83
97
|
- Gemfile
|
84
98
|
- LICENSE.txt
|
85
99
|
- README.md
|
@@ -88,6 +102,8 @@ files:
|
|
88
102
|
- lib/lazy/attribute.rb
|
89
103
|
- lib/lazy/attribute/lazy_attribute.rb
|
90
104
|
- lib/lazy/attribute/version.rb
|
105
|
+
- spec/lazy/attribute/lazy_attribute_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
91
107
|
homepage: https://github.com/selvachezhian/lazy-attribute
|
92
108
|
licenses:
|
93
109
|
- MIT
|
@@ -98,18 +114,21 @@ require_paths:
|
|
98
114
|
- lib
|
99
115
|
required_ruby_version: !ruby/object:Gem::Requirement
|
100
116
|
requirements:
|
101
|
-
- -
|
117
|
+
- - ">="
|
102
118
|
- !ruby/object:Gem::Version
|
103
119
|
version: '0'
|
104
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
121
|
requirements:
|
106
|
-
- -
|
122
|
+
- - ">="
|
107
123
|
- !ruby/object:Gem::Version
|
108
124
|
version: '0'
|
109
125
|
requirements: []
|
110
126
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.4.6
|
112
128
|
signing_key:
|
113
129
|
specification_version: 4
|
114
130
|
summary: Minimizing find_by query for a single repeated attribute
|
115
|
-
test_files:
|
131
|
+
test_files:
|
132
|
+
- spec/lazy/attribute/lazy_attribute_spec.rb
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
has_rdoc: yard
|