scopelist 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a59f5f7906af5da71e520adb072544888b536b65
4
+ data.tar.gz: 07c3975530a8808654695f00ef2928e45cd5d022
5
+ SHA512:
6
+ metadata.gz: 978c3aeed60e8f6a038ba9b4fb795061f578495e7cdf60e3e73871e62c6391e85b75ae5ac9929f6e31aff1118c6488963e4fec424ef440b42b50379a26c02591
7
+ data.tar.gz: 336b0784c42d7a77928d095ca91cd1ef6e888f46a5e49072d54c090decc7b67819aa60ae217def7b7758717837058e9a8ad41d7bc179e4b93f5a5ea5b00968c2
@@ -0,0 +1,18 @@
1
+ .DS_STORE
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
@@ -0,0 +1,2 @@
1
+ #### 0.0.1 (2014-07-03)
2
+ * Initial Release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in scope-list.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Tony Drake
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,58 @@
1
+ # Scopelist
2
+
3
+ A simple way to track scopes in ActiveRecord 4.0 and 4.1.
4
+
5
+ NOTE: Only Ruby 1.9.3 and later are supported
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'scopelist'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install scopelist
20
+
21
+ ## Usage
22
+
23
+ Get a list of scopes in any model:
24
+
25
+ ```ruby
26
+ class MyModel < ActiveRecord::Base
27
+ scope :a_scope, -> {...}
28
+ scope :another_scope, -> {...}
29
+ ...
30
+ end
31
+
32
+ MyModel.available_scopes
33
+ => [:a_scope, :another_scope, ...]
34
+ ```
35
+
36
+ Now scopes are really just class methods. If you'd like to include class methods that act like scopes, you can append the list easily.
37
+
38
+ ```ruby
39
+ class MyModel < ActiveRecord::Base
40
+ ...
41
+
42
+ def self.some_scope
43
+ where(...)
44
+ end
45
+ additional_available_scope :some_scope
46
+ end
47
+
48
+ MyModel.available_scopes
49
+ => [:a_scope, :another_scope, :some_scope, ...]
50
+ ```
51
+
52
+ ## Contributing
53
+
54
+ 1. Fork it ( http://github.com/t27duck/scopelist/fork )
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create new Pull Request
@@ -0,0 +1,16 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ # If you want to make this the default task
7
+ task :default => :spec
8
+
9
+ task :console do
10
+ require 'irb'
11
+ require 'irb/completion'
12
+ require 'active_record'
13
+ require 'scopelist'
14
+ ARGV.clear
15
+ IRB.start
16
+ end
@@ -0,0 +1,30 @@
1
+ require "scopelist/version"
2
+
3
+ module Scopelist
4
+
5
+ def self.included(base)
6
+ base.class_eval do
7
+ extend ClassMethods
8
+ class << self
9
+ alias_method_chain :scope, :scopelist
10
+ end
11
+ end
12
+ end
13
+
14
+ module ClassMethods
15
+ def scope_with_scopelist(name, body, &block)
16
+ available_scopes << name.to_sym
17
+ scope_without_scopelist(name, body, &block)
18
+ end
19
+
20
+ def available_scopes
21
+ @available_scopes ||= []
22
+ end
23
+
24
+ def additional_available_scope(name)
25
+ available_scopes << name.to_sym
26
+ end
27
+ end
28
+ end
29
+
30
+ ActiveRecord::Base.include Scopelist
@@ -0,0 +1,3 @@
1
+ module Scopelist
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'scopelist/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "scopelist"
8
+ spec.version = Scopelist::VERSION
9
+ spec.authors = ["Tony Drake"]
10
+ spec.email = ["t27duck@gmail.com"]
11
+ spec.summary = %q{Adds ability to track scopes on ActiveRecord models}
12
+ spec.description = %q{Adds ability to track scopes on ActiveRecord models}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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", ">= 4.0.0"
22
+ spec.add_dependency "activesupport", ">= 4.0.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "sqlite3"
28
+ end
@@ -0,0 +1,14 @@
1
+ class SomeThing < ActiveRecord::Base
2
+ scope :scope1, -> {where(nil)}
3
+ end
4
+
5
+ class SomeOtherThing < ActiveRecord::Base
6
+ end
7
+
8
+ class OneMoreThing < ActiveRecord::Base
9
+ scope :scope2, -> {where(nil)}
10
+
11
+ def self.class_method_as_a_scope
12
+ end
13
+ additional_available_scope :class_method_as_a_scope
14
+ end
@@ -0,0 +1,15 @@
1
+ ActiveRecord::Schema.define do
2
+ self.verbose = false
3
+
4
+ create_table :some_things, :force => true do |t|
5
+ t.timestamps
6
+ end
7
+
8
+ create_table :some_other_things, :force => true do |t|
9
+ t.timestamps
10
+ end
11
+
12
+ create_table :one_more_things, :force => true do |t|
13
+ t.timestamps
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe '.available_scopes' do
4
+ it 'should be an array' do
5
+ expect(SomeThing.available_scopes).to be_a_kind_of(Array)
6
+ end
7
+
8
+ it 'should contain an array of scope names' do
9
+ expect(SomeThing.available_scopes).to eq([:scope1])
10
+ end
11
+
12
+ it 'does not bleed into other models' do
13
+ expect(SomeOtherThing.available_scopes).to eq([])
14
+ end
15
+ end
16
+
17
+ describe '.additonal_available_scope' do
18
+ it 'appends to the available scope list' do
19
+ expect(OneMoreThing.available_scopes).to eq([:scope2, :class_method_as_a_scope])
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'active_record'
5
+ require 'active_support'
6
+ require 'scopelist'
7
+
8
+ ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
9
+
10
+ load File.dirname(__FILE__) + '/schema.rb'
11
+ require File.dirname(__FILE__) + '/models.rb'
12
+
13
+ RSpec.configure do |config|
14
+ # some (optional) config here
15
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scopelist
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tony Drake
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-04 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: 4.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: 4.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: 4.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: 4.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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: rspec
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
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Adds ability to track scopes on ActiveRecord models
98
+ email:
99
+ - t27duck@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - CHANGELOG.md
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - lib/scopelist.rb
111
+ - lib/scopelist/version.rb
112
+ - scopelist.gemspec
113
+ - spec/models.rb
114
+ - spec/schema.rb
115
+ - spec/scopelist_spec.rb
116
+ - spec/spec_helper.rb
117
+ homepage: ''
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.2.0
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Adds ability to track scopes on ActiveRecord models
141
+ test_files:
142
+ - spec/models.rb
143
+ - spec/schema.rb
144
+ - spec/scopelist_spec.rb
145
+ - spec/spec_helper.rb