railsieve 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.
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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in railsieve.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 AOKI Yuuto
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,29 @@
1
+ # Railsieve
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'railsieve'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install railsieve
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/lib/railsieve.rb ADDED
@@ -0,0 +1,2 @@
1
+ module Railsieve
2
+ end
@@ -0,0 +1,50 @@
1
+ module Railsieve
2
+ module Generator
3
+ def generate_sieve(name)
4
+ generate_sieve_configurator(name)
5
+ generate_accessors(name)
6
+ end
7
+
8
+ private
9
+ def generate_sieve_configurator(name)
10
+ [:max, :min, :default].each do |attribute|
11
+ basename = "#{name}_#{attribute}"
12
+ instance_eval do
13
+ define_singleton_method("#{basename}") do |arg = nil|
14
+ instance_variable_set("@#{basename}", arg) if arg
15
+ instance_variable_get("@#{basename}")
16
+ end
17
+ define_method("#{basename}") do |arg = nil|
18
+ self.class.__send__("#{basename}", arg)
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ def generate_accessors(name)
25
+ generate_getter(name)
26
+ generate_setter(name)
27
+ end
28
+
29
+ def generate_getter(name)
30
+ define_method("#{name}") do
31
+ variable = params[name]
32
+ if variable
33
+ min = __send__("#{name}_min")
34
+ max = __send__("#{name}_max")
35
+ variable = min if min && variable.to_i < min.to_i
36
+ variable = max if max && variable.to_i > max.to_i
37
+ else
38
+ variable = __send__("#{name}_default")
39
+ end
40
+ variable
41
+ end
42
+ end
43
+
44
+ def generate_setter(name)
45
+ define_method("#{name}=") do |arg|
46
+ params[name] = arg
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module Railsieve
2
+ VERSION = "0.0.1"
3
+ end
data/railsieve.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/railsieve/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["AOKI Yuuto"]
6
+ gem.email = ["wx.aoki@gmail.com"]
7
+ gem.description = %q{Normalizing Numeric Ranges and Make Default for params}
8
+ gem.summary = %q{Normalizing Numeric Ranges and Make Default for params. for example, `per_page_min', `per_page_max' and `per_page_default'}
9
+ gem.homepage = "http://u-ne.co"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "railsieve"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Railsieve::VERSION
17
+
18
+ gem.add_dependency 'rails', '>= 3.0.0'
19
+ gem.add_development_dependency 'rspec'
20
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ class ApplicationController
4
+ end
5
+
6
+ describe Railsieve do
7
+ pending "write it"
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'railsieve' # and any other gems you need
5
+
6
+ RSpec.configure do |config|
7
+ # some (optional) config here
8
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: railsieve
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - AOKI Yuuto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &2157204140 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2157204140
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &2157203520 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2157203520
36
+ description: Normalizing Numeric Ranges and Make Default for params
37
+ email:
38
+ - wx.aoki@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - .rspec
45
+ - Gemfile
46
+ - LICENSE
47
+ - README.md
48
+ - Rakefile
49
+ - lib/railsieve.rb
50
+ - lib/railsieve/generator.rb
51
+ - lib/railsieve/version.rb
52
+ - railsieve.gemspec
53
+ - spec/railsieve_spec.rb
54
+ - spec/spec_helper.rb
55
+ homepage: http://u-ne.co
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.11
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Normalizing Numeric Ranges and Make Default for params. for example, `per_page_min',
79
+ `per_page_max' and `per_page_default'
80
+ test_files:
81
+ - spec/railsieve_spec.rb
82
+ - spec/spec_helper.rb
83
+ has_rdoc: