lazy-attribute 2.0.1 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +11 -1
- data/lazy-attribute.gemspec +4 -0
- data/lib/lazy/attribute/lazy_attribute.rb +32 -4
- data/lib/lazy/attribute/version.rb +1 -1
- metadata +17 -10
- data/.idea/.name +0 -1
- data/.idea/.rakeTasks +0 -7
- data/.idea/encodings.xml +0 -4
- data/.idea/lazy-attribute.iml +0 -31
- data/.idea/misc.xml +0 -4
- data/.idea/modules.xml +0 -8
- data/.idea/scopes/scope_settings.xml +0 -5
- data/.idea/vcs.xml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcebd941632c3e7f542524b136d7f23517beef58
|
4
|
+
data.tar.gz: 606bbd17c3b5b198a1608e81f82c9980343f0a21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da0408b255f671f58f35da26ccde95b0af8ad611309d31a53d81fcbfc150b122a4113ab2328dcce1cb8fcf70743b355a47e5a52dee6d3bd81bf0c0079f1acbe5
|
7
|
+
data.tar.gz: cb1ccc754ad6f17376611df164b367101930700755e8d984772410a05c460e034cf175b95589d4912afd302f5b3ca24dc35b481a8a12222e7caeafb52775165c
|
data/README.md
CHANGED
@@ -36,11 +36,21 @@ User['sample@email.com']
|
|
36
36
|
Will give you the user object matches with the email and will return nil if record not found
|
37
37
|
|
38
38
|
```ruby
|
39
|
-
lazy_attribute :email, :
|
39
|
+
lazy_attribute :email, raise_error: true
|
40
40
|
```
|
41
41
|
|
42
42
|
Will give you the user object matches with the email and will raise ``` ActiveRecord::RecordNotFound ``` Exception if record not found
|
43
43
|
|
44
|
+
You can use more than one lazy_attribute to your model by providing unique key for that
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
lazy_attribute :first_name, raise_error: true, key: :fn
|
48
|
+
```
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
User.fn('first name')
|
52
|
+
```
|
53
|
+
|
44
54
|
## Contributing
|
45
55
|
|
46
56
|
1. Fork it ( https://github.com/selvachezhian/lazy-attribute/fork )
|
data/lazy-attribute.gemspec
CHANGED
@@ -20,5 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
22
22
|
spec.add_development_dependency 'rake', '~> 0'
|
23
|
+
spec.add_development_dependency 'yard'
|
24
|
+
|
23
25
|
spec.add_dependency 'activerecord', '~> 4.1'
|
26
|
+
|
27
|
+
spec.has_rdoc = 'yard'
|
24
28
|
end
|
@@ -2,19 +2,47 @@ module Lazy
|
|
2
2
|
module Attribute
|
3
3
|
module ClassMethods
|
4
4
|
|
5
|
-
|
5
|
+
# Including the lazy_attribute gem to the model
|
6
|
+
#
|
7
|
+
# @param attribute [Symbol]
|
8
|
+
# @param [Hash] options
|
9
|
+
# @option options [Boolean] :raise_error (false) will raise ActiveRecord::RecordNotFoundException if the value set as true and the record not present
|
10
|
+
# @option options [Symbol] :key (:default) if the key parameter is not set, it will take the default as the key
|
11
|
+
#
|
12
|
+
# @return [none]
|
13
|
+
def lazy_attribute(attribute, options = {})
|
14
|
+
default_options = { raise_error: false, key: :default }
|
15
|
+
options.reverse_merge!(default_options)
|
16
|
+
|
6
17
|
singleton_class.instance_eval do
|
7
|
-
|
8
|
-
|
9
|
-
|
18
|
+
|
19
|
+
if options[:key] == :default
|
20
|
+
|
21
|
+
define_method('[]') do |identifier|
|
22
|
+
send_dynamic_method(options, attribute, identifier)
|
23
|
+
end
|
24
|
+
|
25
|
+
else
|
26
|
+
|
27
|
+
define_method(options[:key]) do |identifier|
|
28
|
+
send_dynamic_method(options, attribute, identifier)
|
29
|
+
end
|
30
|
+
|
10
31
|
end
|
32
|
+
|
11
33
|
end
|
12
34
|
end
|
13
35
|
|
36
|
+
private
|
37
|
+
|
14
38
|
def dynamic_find_method(raise_error = false)
|
15
39
|
raise_error ? 'find_by!' : 'find_by'
|
16
40
|
end
|
17
41
|
|
42
|
+
def send_dynamic_method(options, attr, identifier)
|
43
|
+
send(dynamic_find_method(options[:raise_error]), { attr.to_sym => identifier })
|
44
|
+
end
|
45
|
+
|
18
46
|
end
|
19
47
|
end
|
20
48
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazy-attribute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Selva Chezhian
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-01-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -39,6 +39,20 @@ dependencies:
|
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: yard
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
57
|
name: activerecord
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,14 +78,6 @@ extensions: []
|
|
64
78
|
extra_rdoc_files: []
|
65
79
|
files:
|
66
80
|
- ".gitignore"
|
67
|
-
- ".idea/.name"
|
68
|
-
- ".idea/.rakeTasks"
|
69
|
-
- ".idea/encodings.xml"
|
70
|
-
- ".idea/lazy-attribute.iml"
|
71
|
-
- ".idea/misc.xml"
|
72
|
-
- ".idea/modules.xml"
|
73
|
-
- ".idea/scopes/scope_settings.xml"
|
74
|
-
- ".idea/vcs.xml"
|
75
81
|
- Gemfile
|
76
82
|
- LICENSE.txt
|
77
83
|
- README.md
|
@@ -105,3 +111,4 @@ signing_key:
|
|
105
111
|
specification_version: 4
|
106
112
|
summary: Minimizing find_by query for a single repeated attribute
|
107
113
|
test_files: []
|
114
|
+
has_rdoc: yard
|
data/.idea/.name
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
lazy-attribute
|
data/.idea/.rakeTasks
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<Settings><!--This file was automatically generated by Ruby plugin.
|
3
|
-
You are allowed to:
|
4
|
-
1. Remove rake task
|
5
|
-
2. Add existing rake tasks
|
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>
|
data/.idea/encodings.xml
DELETED
data/.idea/lazy-attribute.iml
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<module type="RUBY_MODULE" version="4">
|
3
|
-
<component name="FacetManager">
|
4
|
-
<facet type="gem" name="Ruby Gem">
|
5
|
-
<configuration>
|
6
|
-
<option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
|
7
|
-
<option name="GEM_APP_TEST_PATH" value="$MODULE_DIR$/test" />
|
8
|
-
<option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
|
9
|
-
</configuration>
|
10
|
-
</facet>
|
11
|
-
</component>
|
12
|
-
<component name="NewModuleRootManager">
|
13
|
-
<content url="file://$MODULE_DIR$">
|
14
|
-
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
15
|
-
</content>
|
16
|
-
<orderEntry type="jdk" jdkName="RVM: ruby-2.1.2" jdkType="RUBY_SDK" />
|
17
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
18
|
-
<orderEntry type="library" scope="PROVIDED" name="activemodel (v4.1.6, RVM: ruby-2.1.2) [gem]" level="application" />
|
19
|
-
<orderEntry type="library" scope="PROVIDED" name="activerecord (v4.1.6, RVM: ruby-2.1.2) [gem]" level="application" />
|
20
|
-
<orderEntry type="library" scope="PROVIDED" name="activesupport (v4.1.6, RVM: ruby-2.1.2) [gem]" level="application" />
|
21
|
-
<orderEntry type="library" scope="PROVIDED" name="arel (v5.0.1.20140414130214, RVM: ruby-2.1.2) [gem]" level="application" />
|
22
|
-
<orderEntry type="library" scope="PROVIDED" name="builder (v3.2.2, RVM: ruby-2.1.2) [gem]" level="application" />
|
23
|
-
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.6.2, RVM: ruby-2.1.2) [gem]" level="application" />
|
24
|
-
<orderEntry type="library" scope="PROVIDED" name="i18n (v0.6.11, RVM: ruby-2.1.2) [gem]" level="application" />
|
25
|
-
<orderEntry type="library" scope="PROVIDED" name="json (v1.8.1, RVM: ruby-2.1.2) [gem]" level="application" />
|
26
|
-
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.4.2, RVM: ruby-2.1.2) [gem]" level="application" />
|
27
|
-
<orderEntry type="library" scope="PROVIDED" name="rake (v0.9.6, RVM: ruby-2.1.2) [gem]" level="application" />
|
28
|
-
<orderEntry type="library" scope="PROVIDED" name="thread_safe (v0.3.4, RVM: ruby-2.1.2) [gem]" level="application" />
|
29
|
-
<orderEntry type="library" scope="PROVIDED" name="tzinfo (v1.2.2, RVM: ruby-2.1.2) [gem]" level="application" />
|
30
|
-
</component>
|
31
|
-
</module>
|
data/.idea/misc.xml
DELETED
data/.idea/modules.xml
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<project version="4">
|
3
|
-
<component name="ProjectModuleManager">
|
4
|
-
<modules>
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/../lazy_attribute/.idea/lazy-attribute.iml" filepath="$PROJECT_DIR$/../lazy_attribute/.idea/lazy-attribute.iml" />
|
6
|
-
</modules>
|
7
|
-
</component>
|
8
|
-
</project>
|