activerecord-endoscope 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7ffc4aa6014a91480e0d25a484bda55984815727
4
+ data.tar.gz: eb1ee58bb40c9dbda50cd7b65fda57abc2189523
5
+ SHA512:
6
+ metadata.gz: 246dbe488914684dac0ff3a684479164fb79959fa0a48aa2f46058113f0e03f18383f404ebe0268bbbea7f52d335759b0a67c398b34256c9a5ab98a7e018b8cd
7
+ data.tar.gz: a3710de8de3a0eb1b6e9376ad2a5b942577aece07e885250a5b8f76de40d49430c038fa1befaaedab2b17c0ad9144d9f0d86510f8c082ee29eb772f7bc6c17a6
data/.gitignore ADDED
@@ -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 active_record-endoscope.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Toru KAWAMURA
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.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # activerecord-endoscope
2
+
3
+ Endoscope enables scope to apply to model instance
4
+
5
+ ## Example
6
+
7
+ ```ruby
8
+ class User < ActiveRecord::Base
9
+ extend ActiveRecord::Endoscope # add this before using scope
10
+ scope :admin, -> {
11
+ where(role: 'admin')
12
+ }
13
+ scope :not_admin, -> {
14
+ where.not(role: 'admin')
15
+ }
16
+ scope :admin_or_manager, -> {
17
+ where(role: ['admin', 'manager'])
18
+ }
19
+ scope :minor, -> {
20
+ where(age: 0..19)
21
+ }
22
+ scope :have_no_email, -> {
23
+ where(email: nil)
24
+ }
25
+ scope :have_email, -> {
26
+ where.not(email: nil).where.not(email: '')
27
+ }
28
+ end
29
+ ```
30
+
31
+ Then these methods are defined automatically:
32
+
33
+ ```ruby
34
+ u = User.new(role: 'ordinary', age: 20, email: 'foobar@example.com')
35
+ u.admin? # => false
36
+ u.not_admin? # => true
37
+ u.admin_or_manager? # => false
38
+ u.minor? # => false
39
+ u.has_no_email? # => false
40
+ u.has_email? # => true
41
+ ```
42
+
43
+ With no SQL execution.
44
+
45
+
46
+ ## Restriction
47
+
48
+ Limited queries have been supported yet.
49
+
50
+ SQL literal such as `where('email IS NOT NULL')` is not supported
51
+
52
+ If your query is not supported, you can override the method manually.
53
+
54
+
55
+ ## Installation
56
+
57
+ Add these lines to your application's Gemfile:
58
+
59
+ gem 'activerecord-endoscope'
60
+ gem 'arel_ruby', github: 'tkawa/arel_ruby'
61
+
62
+ And then execute:
63
+
64
+ $ bundle
65
+
66
+
67
+ ## Contributing
68
+
69
+ 1. Fork it
70
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
71
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
72
+ 4. Push to the branch (`git push origin my-new-feature`)
73
+ 5. Create new Pull Request
74
+
75
+ ## Acknowledgment
76
+
77
+ The features of this gem almost depend on arel_ruby.
78
+
79
+ https://github.com/amatsuda/arel_ruby
80
+
81
+ Thanks @amatsuda!
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_record/endoscope/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'activerecord-endoscope'
8
+ spec.version = ActiveRecord::Endoscope::VERSION
9
+ spec.authors = ['Toru KAWAMURA']
10
+ spec.email = ['tkawa@4bit.net']
11
+ spec.description = %q{Endoscope enables scope to apply to model instance}
12
+ spec.summary = %q{Endoscope enables scope to apply to model instance}
13
+ spec.homepage = 'https://github.com/tkawa/activerecord-endoscope'
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 'activerecord', '>= 3.0.0'
22
+ spec.add_dependency 'activesupport', '>= 3.0.0'
23
+ spec.add_dependency 'arel_ruby'
24
+ spec.add_development_dependency 'bundler', '~> 1.3'
25
+ spec.add_development_dependency 'rake'
26
+ end
@@ -0,0 +1,16 @@
1
+ require 'active_record/endoscope/version'
2
+
3
+ module ActiveRecord
4
+ module Endoscope
5
+ def scope(name, scope_options = {})
6
+ super
7
+
8
+ instance_method_name = "#{name.to_s.sub(/^have_/, 'has_')}?"
9
+ class_eval <<-ENDOSCOPE, __FILE__, __LINE__ + 1
10
+ def #{instance_method_name}
11
+ self.class.#{name}.arel.to_ruby.call([self]).present?
12
+ end
13
+ ENDOSCOPE
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveRecord
2
+ module Endoscope
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require 'active_record/endoscope'
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-endoscope
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Toru KAWAMURA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: arel_ruby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: bundler
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
+ - !ruby/object:Gem::Dependency
70
+ name: rake
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: Endoscope enables scope to apply to model instance
84
+ email:
85
+ - tkawa@4bit.net
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - activerecord-endoscope.gemspec
96
+ - lib/active_record/endoscope.rb
97
+ - lib/active_record/endoscope/version.rb
98
+ - lib/activerecord-endoscope.rb
99
+ homepage: https://github.com/tkawa/activerecord-endoscope
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.0.3
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Endoscope enables scope to apply to model instance
123
+ test_files: []