scoped 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/Gemfile +3 -0
 - data/History.txt +3 -0
 - data/README.md +39 -0
 - data/Rakefile +16 -0
 - data/lib/scoped.rb +15 -0
 - data/lib/scoped/scope_collection.rb +50 -0
 - data/lib/scoped/version.rb +3 -0
 - data/scoped.gemspec +24 -0
 - metadata +71 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA1:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: afcd7140f27e740f73d6b732543df70a0026a4c0
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 54ce2dac7b7dd04c1696f384b6f054128a1e0eb3
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: f7bc38329402cdbe4180fd68c9b5e755d9b244019408c58c3a4385d1e9f26c9115cde4bb313c7c6fc6bee97c6174135fb715f77cc9f0969d383aba097bd186a9
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 175e18de532071a6f9115d47dfe7fa4c756f9561d144b2e244d6a7a50abd999b8e4e9b4d63b8b99b0f27519e016bd58347cf9966aa555b0e841b696ca7e0b0de
         
     | 
    
        data/Gemfile
    ADDED
    
    
    
        data/History.txt
    ADDED
    
    
    
        data/README.md
    ADDED
    
    | 
         @@ -0,0 +1,39 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            A rigid, readable alternative for defining AR scopes.
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            ## Installation
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            `gem install scoped`
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            ## Usage
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 10 
     | 
    
         
            +
            require 'scoped'
         
     | 
| 
      
 11 
     | 
    
         
            +
            ```
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            Then in your `ActiveRecord` models:
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 16 
     | 
    
         
            +
            class Meme < ActiveRecord::Base
         
     | 
| 
      
 17 
     | 
    
         
            +
              include Scoped
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              scopes do
         
     | 
| 
      
 20 
     | 
    
         
            +
                sad_keanu { where(name: 'Keanu Reaves') }
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
      
 22 
     | 
    
         
            +
            end
         
     | 
| 
      
 23 
     | 
    
         
            +
            ```
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 26 
     | 
    
         
            +
            Meme.sad_keanu #=> an ActiveRecord::Relation of Memes!
         
     | 
| 
      
 27 
     | 
    
         
            +
            ```
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            ## Requirements
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            Requires ActiveRecord >= 3.1.0, <= 4.1.0, tested with Ruby 1.9.3, 2.0.0, and 2.1.0.
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            ## Running Tests
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
            `bundle exec rspec`
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            ## Authors
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
            * Evan Sherwood: http://github.com/neezer
         
     | 
    
        data/Rakefile
    ADDED
    
    | 
         @@ -0,0 +1,16 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'rubygems' unless ENV['NO_RUBYGEMS']
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'bundler'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'rspec/core/rake_task'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'rubygems/package_task'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            require './lib/scoped'
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            Bundler::GemHelper.install_tasks
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            task :default => :spec
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            desc 'Run specs'
         
     | 
| 
      
 14 
     | 
    
         
            +
            RSpec::Core::RakeTask.new do |t|
         
     | 
| 
      
 15 
     | 
    
         
            +
              t.pattern = './spec/**/*_spec.rb'
         
     | 
| 
      
 16 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/scoped.rb
    ADDED
    
    | 
         @@ -0,0 +1,15 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'active_record'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Scoped
         
     | 
| 
      
 4 
     | 
    
         
            +
              autoload :ScopeCollection, 'scoped/scope_collection'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              extend ActiveSupport::Concern
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              module ClassMethods
         
     | 
| 
      
 9 
     | 
    
         
            +
                def scopes(&block)
         
     | 
| 
      
 10 
     | 
    
         
            +
                  ScopeCollection.new(&block).all.each do |name, source|
         
     | 
| 
      
 11 
     | 
    
         
            +
                    scope(name, eval(source))
         
     | 
| 
      
 12 
     | 
    
         
            +
                  end
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,50 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Scoped
         
     | 
| 
      
 2 
     | 
    
         
            +
              class ScopeCollection
         
     | 
| 
      
 3 
     | 
    
         
            +
                def initialize(&block)
         
     | 
| 
      
 4 
     | 
    
         
            +
                  @scopes = {}
         
     | 
| 
      
 5 
     | 
    
         
            +
                  instance_eval &block
         
     | 
| 
      
 6 
     | 
    
         
            +
                end
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                def all
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @scopes
         
     | 
| 
      
 10 
     | 
    
         
            +
                end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                def method_missing(name, *args, &block)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  return super unless block_given?
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                  arg_list, block_contents = parse(block.source.split("\n"))
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  @scopes[name] = <<-RUBY
         
     | 
| 
      
 18 
     | 
    
         
            +
                    lambda do #{"|#{arg_list}|" if arg_list}
         
     | 
| 
      
 19 
     | 
    
         
            +
                      #{block_contents.join("\n")}
         
     | 
| 
      
 20 
     | 
    
         
            +
                    end
         
     | 
| 
      
 21 
     | 
    
         
            +
                  RUBY
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                private
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                def parse(block_source)
         
     | 
| 
      
 27 
     | 
    
         
            +
                  if block_source.size > 1
         
     | 
| 
      
 28 
     | 
    
         
            +
                    parse_multiline(block_source)
         
     | 
| 
      
 29 
     | 
    
         
            +
                  else
         
     | 
| 
      
 30 
     | 
    
         
            +
                    parse_single_line(block_source.first)
         
     | 
| 
      
 31 
     | 
    
         
            +
                  end
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                def parse_single_line(block_source)
         
     | 
| 
      
 35 
     | 
    
         
            +
                  block_source.strip.match(%r(^.+\{\s*(\|.*\|)?(.+?)\}.*$)).tap do |matchdata|
         
     | 
| 
      
 36 
     | 
    
         
            +
                    arg_list = (matchdata.captures[0] || '')[1..-2]
         
     | 
| 
      
 37 
     | 
    
         
            +
                    block_contents = matchdata.captures[1].strip
         
     | 
| 
      
 38 
     | 
    
         
            +
                    break [arg_list, [block_contents]]
         
     | 
| 
      
 39 
     | 
    
         
            +
                  end
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                def parse_multiline(block_source)
         
     | 
| 
      
 43 
     | 
    
         
            +
                  arg_list = block_source[0].match(%r(\|(.+?)\|)).tap do |match|
         
     | 
| 
      
 44 
     | 
    
         
            +
                    break (match && match.captures.any?) ? match.captures.first : nil
         
     | 
| 
      
 45 
     | 
    
         
            +
                  end
         
     | 
| 
      
 46 
     | 
    
         
            +
                  block_contents = block_source[1..-2]
         
     | 
| 
      
 47 
     | 
    
         
            +
                  [arg_list, block_contents]
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
            end
         
     | 
    
        data/scoped.gemspec
    ADDED
    
    | 
         @@ -0,0 +1,24 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            $:.unshift File.join(File.dirname(__FILE__), 'lib')
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'scoped/version'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            Gem::Specification.new do |s|
         
     | 
| 
      
 5 
     | 
    
         
            +
              s.name     = "scoped"
         
     | 
| 
      
 6 
     | 
    
         
            +
              s.version  = ::Scoped::VERSION
         
     | 
| 
      
 7 
     | 
    
         
            +
              s.authors  = ["Evan Sherwood"]
         
     | 
| 
      
 8 
     | 
    
         
            +
              s.email    = ["evan@sherwood.io"]
         
     | 
| 
      
 9 
     | 
    
         
            +
              s.homepage = "http://github.com/neezer"
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              s.description = s.summary = "A rigid, readable alternative for defining AR scopes."
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              s.platform = Gem::Platform::RUBY
         
     | 
| 
      
 14 
     | 
    
         
            +
              s.has_rdoc = true
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              if ENV["AR"]
         
     | 
| 
      
 17 
     | 
    
         
            +
                s.add_dependency 'activerecord', ENV["AR"]
         
     | 
| 
      
 18 
     | 
    
         
            +
              else
         
     | 
| 
      
 19 
     | 
    
         
            +
                s.add_dependency 'activerecord', '>= 3.1.0', '< 5'
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              s.require_path = 'lib'
         
     | 
| 
      
 23 
     | 
    
         
            +
              s.files = Dir["{lib,spec}/**/*", "Gemfile", "History.txt", "README.md", "Rakefile", "scoped.gemspec"]
         
     | 
| 
      
 24 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,71 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: scoped
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.1
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Evan Sherwood
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-05-30 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.1.0
         
     | 
| 
      
 20 
     | 
    
         
            +
                - - "<"
         
     | 
| 
      
 21 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 22 
     | 
    
         
            +
                    version: '5'
         
     | 
| 
      
 23 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 24 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 25 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 26 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 27 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 28 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 29 
     | 
    
         
            +
                    version: 3.1.0
         
     | 
| 
      
 30 
     | 
    
         
            +
                - - "<"
         
     | 
| 
      
 31 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 32 
     | 
    
         
            +
                    version: '5'
         
     | 
| 
      
 33 
     | 
    
         
            +
            description: A rigid, readable alternative for defining AR scopes.
         
     | 
| 
      
 34 
     | 
    
         
            +
            email:
         
     | 
| 
      
 35 
     | 
    
         
            +
            - evan@sherwood.io
         
     | 
| 
      
 36 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 37 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 38 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 39 
     | 
    
         
            +
            files:
         
     | 
| 
      
 40 
     | 
    
         
            +
            - Gemfile
         
     | 
| 
      
 41 
     | 
    
         
            +
            - History.txt
         
     | 
| 
      
 42 
     | 
    
         
            +
            - README.md
         
     | 
| 
      
 43 
     | 
    
         
            +
            - Rakefile
         
     | 
| 
      
 44 
     | 
    
         
            +
            - lib/scoped.rb
         
     | 
| 
      
 45 
     | 
    
         
            +
            - lib/scoped/scope_collection.rb
         
     | 
| 
      
 46 
     | 
    
         
            +
            - lib/scoped/version.rb
         
     | 
| 
      
 47 
     | 
    
         
            +
            - scoped.gemspec
         
     | 
| 
      
 48 
     | 
    
         
            +
            homepage: http://github.com/neezer
         
     | 
| 
      
 49 
     | 
    
         
            +
            licenses: []
         
     | 
| 
      
 50 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
      
 51 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 52 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 53 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 54 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 55 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 56 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 57 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 58 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 59 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 60 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 61 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 62 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 63 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 64 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 65 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 66 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 67 
     | 
    
         
            +
            rubygems_version: 2.2.2
         
     | 
| 
      
 68 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 69 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 70 
     | 
    
         
            +
            summary: A rigid, readable alternative for defining AR scopes.
         
     | 
| 
      
 71 
     | 
    
         
            +
            test_files: []
         
     |