rails_scopes 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1fd2b0ac0ed27c38c3f051ff6c8d121d8d5ba393
4
+ data.tar.gz: c1bcd5b7ce185c02792614d70df0e2f41de9e330
5
+ SHA512:
6
+ metadata.gz: b668e70d8272e99f31bf866bf759a2218500f5e54dd2a44ede3c341a6e02c5d858821e3d815779f6f4258d8bd1cba3eb3fb980a901c6b61a410b6cf1f93f708d
7
+ data.tar.gz: 9a7d878a9c6681db2b98f0b6f6c6481e709f28e55d33cf7387c779107af004b5edf5cc1b0c1c26f9c12a45fb83ab568be2843ee0e3f9b0fad050ac428c502515
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/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ group :test do
3
+ gem 'rspec'
4
+ end
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Rails Scopes
2
+
3
+ A gem that wraps up some meta programmed scopes generators. This gem is an attempt to put together useful code generation for active records common scopes.
4
+
5
+ Note: For now, as it is a POC, it is just working with scopes combiner that aims to create scopes based on hashs, like, status for a state machine.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'rails_scopes'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rails_scopes
20
+
21
+ ## Usage
22
+
23
+ As it relies on metaprogramming you just need to extend your active record
24
+
25
+ ### Example code
26
+
27
+ ```ruby
28
+ class Example < ActiveRecord::Base
29
+ extend RailsScopes::ScopesCombiner
30
+
31
+ enum status: { active: 22, inactive: 14, running: 32, stuck: 42, waiting: 465, dunno: 4880 }
32
+ combine_scopes_for_attribute :status, statuses
33
+
34
+ end
35
+ ```
36
+
37
+ ## Contributing to Rails Scopes
38
+ * Pull requests with unit tests or specs and a version branch are welcomed.
39
+ * Fork the project.
40
+ * Start a feature/bugfix branch.
41
+ * Commit and push as much as you want.
42
+ * Make sure to add tests for it.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ ZohoWrapper::Application.load_tasks
data/config.ru ADDED
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -0,0 +1,19 @@
1
+ module RailsScopes
2
+ module ScopesCombiner
3
+ def combined_methods_names(hash)
4
+ 2.upto(hash.size).map do |n|
5
+ hash.keys.combination(n).map { |combined| combined.join('_or_') }
6
+ end.flatten
7
+ end
8
+
9
+ def combine_scopes_for_attribute(attribute_name, hash)
10
+ 2.upto(hash.size).each do |n|
11
+ hash.keys.combination(n).each do |combined|
12
+ define_singleton_method(combined.join('_or_')) do
13
+ where(attribute_name => combined.map { |k| hash[k] })
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ require "rails_scopes/scopes_combiner"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails_scopes"
8
+ spec.version = "0.0.2"
9
+ spec.authors = ["marcelorxs"]
10
+ spec.email = ["marcelorxs@gmail.com"]
11
+ spec.summary = "A gem for generating rails active record common scopes"
12
+ spec.description = "A set of scopes generators."
13
+ spec.homepage = "http://github.com/marcelorxaviers/ruby/rails_scopes"
14
+ spec.license = "MIT"
15
+ spec.platform = Gem::Platform::RUBY
16
+ spec.required_ruby_version = ">= 2.1.5"
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+
19
+ spec.require_paths = ["lib"]
20
+ spec.add_development_dependency "bundler", "~> 1.5"
21
+ spec.add_development_dependency "rake", "~> 0"
22
+ spec.add_development_dependency "rspec", "~> 0"
23
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsScopes::ScopesCombiner do
4
+ let(:example) do
5
+ class Example
6
+ extend RailsScopes::ScopesCombiner
7
+
8
+ @statuses = { active: 22, inactive: 14, running: 32, stuck: 42, waiting: 465, dunno: 4880 }
9
+ class << self
10
+ attr_reader :statuses
11
+ end
12
+
13
+ combine_scopes_for_attribute :status, statuses
14
+ self
15
+ end
16
+ end
17
+
18
+ describe "RailsScopes::ScopesCombiner" do
19
+
20
+ it "extends ScopesCombiner" do
21
+ example.should respond_to :combined_methods_names
22
+ end
23
+
24
+ it "creates methods for statuses" do
25
+ example.combined_methods_names(example.statuses).each do |name|
26
+ example.should respond_to name
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,7 @@
1
+ require_relative '../lib/rails_scopes/scopes_combiner'
2
+
3
+ require 'yaml'
4
+
5
+ RSpec.configure do |config|
6
+ config.expect_with(:rspec) { |c| c.syntax = :should }
7
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_scopes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - marcelorxs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A set of scopes generators.
56
+ email:
57
+ - marcelorxs@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".ruby-version"
64
+ - Gemfile
65
+ - README.md
66
+ - Rakefile
67
+ - config.ru
68
+ - lib/rails_scopes.rb
69
+ - lib/rails_scopes/scopes_combiner.rb
70
+ - rails_scopes.gemspec
71
+ - spec/rails_scopes/scope_combiner_spec.rb
72
+ - spec/spec_helper.rb
73
+ homepage: http://github.com/marcelorxaviers/ruby/rails_scopes
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 2.1.5
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: A gem for generating rails active record common scopes
97
+ test_files: []