rails-mark_requirements 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 @@
1
+ --colour
data/.rvmrc ADDED
@@ -0,0 +1,47 @@
1
+ # Pick one EVENT or SWIFTIPLY
2
+ # To run a Rails app in evented mode (eventmachine gem)
3
+ export EVENT=1
4
+
5
+ # To run in swiftiplied mode (swiftiply gem)
6
+ #export SWIFTIPLY=1
7
+
8
+ # HACK: broken locales
9
+ my_hosttype="${HOSTTYPE:='unknown_hosttype'}"
10
+ my_kernel="${OSTYPE:='unknown_kernel'}"
11
+ my_hosttype=$(uname -a)
12
+ my_kernel=$(uname -s)
13
+
14
+ if [ "${my_kernel}" != 'Darwin' ]; then
15
+ my_kernel="${my_kernel/SunOS/solaris}"
16
+ fi
17
+
18
+ # TODO: re-write my_osver detection to include major-minor-patch
19
+ my_ostype="${my_kernel/Darwin*/darwin}"
20
+ my_osver="${my_kernel/darwin/}"
21
+
22
+ if [ "${my_ostype}" != 'darwin' ]; then
23
+ my_ostype="${my_kernel/Linux*/linux}"
24
+ if [ "${my_ostype}" != 'linux' ]; then
25
+ my_ostype="${my_kernel/-gnu/}"
26
+ fi
27
+ my_osver="${my_kernel/linux-/}"
28
+ if [ ${my_ostype} != 'linux' ]; then
29
+ my_ostype="${my_kernel/solaris*/solaris}"
30
+ my_osver="${my_kernel/solaris/}"
31
+ fi
32
+ fi
33
+
34
+ case "${my_ostype}" in
35
+ 'darwin' )
36
+ LC_CTYPE='en_US.UTF-8'; builtin export LC_CTYPE
37
+ LC_ALL='en_US.UTF-8'; builtin export LC_ALL # Mnt. Lion
38
+ ;;
39
+ 'linux' )
40
+ LANG='en_US.UTF-8'; builtin export LANG
41
+ ;;
42
+ * )
43
+ echo "Unsupported OS: ${my_ostype}"
44
+ ;;
45
+ esac
46
+
47
+ rvm 1.9.3-p392-patched@rails-mark_requirements
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails-mark_requirements.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Paul Belt
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,30 @@
1
+ rails-mark_requirements
2
+ =======================
3
+
4
+ expose presence-validation in a more controller-friendly manner
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'rails-mark_requirements'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install rails-mark_requirements
19
+
20
+ ## Usage
21
+
22
+ TODO: Write usage instructions here
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,13 @@
1
+ module Rails
2
+ module MarkRequirements
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ desc 'creates initialization files'
7
+
8
+ def generate_configuration_files
9
+ copy_file 'features/mark_requirements.rb', 'config/features/mark_requirements.rb'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ Configuration.for('mark_requirements') do
2
+ enabled true
3
+ end
@@ -0,0 +1,36 @@
1
+ require 'rails/mark_requirements/version'
2
+
3
+ module Rails
4
+ module MarkRequirements
5
+
6
+ # Allow the developer to be lazy and auto-extend the class methods, which
7
+ # is required for the instance method to work anyway
8
+ def self.included(klass) # :nodoc:
9
+ klass.extend ClassMethods
10
+ end
11
+
12
+ module ClassMethods
13
+ # :call-seq:
14
+ # Klass.mark_required? :attribute
15
+ #
16
+ # does field_for(object.attribute) require 'a presence'
17
+
18
+ def mark_required?(attribute)
19
+ validation_classes = self.validators_on(attribute).map(&:class)
20
+ ret = false
21
+ ret = true if validation_classes.include?(ActiveModel::Validations::PresenceValidator)
22
+ ret
23
+ end
24
+ end # /class_methods
25
+
26
+ # :call-seq:
27
+ # mark_required? :attribute
28
+ #
29
+ # does field_for(object.attribute) require 'a presence'
30
+
31
+ def mark_required?(attribute)
32
+ self.class.mark_required?(attribute)
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ module Rails
2
+ module MarkRequirements
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,49 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails/mark_requirements/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rails-mark_requirements'
8
+ spec.version = Rails::MarkRequirements::VERSION
9
+ spec.authors = ['Paul Belt']
10
+ spec.email = %w(saprb@channing.harvard.edu)
11
+ spec.description = %q{expose presence-validation in a more controller-friendly manner}
12
+ spec.summary = %q{expose presence-validation in a more controller-friendly manner}
13
+ spec.homepage = 'https://github.com/belt/rails-mark_requirements'
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 = %w(lib)
20
+
21
+ spec.required_ruby_version = Gem::Requirement.new('>= 1.9.2')
22
+ spec.required_rubygems_version = Gem::Requirement.new('>= 0') if spec.respond_to? :required_rubygems_version=
23
+
24
+ if spec.respond_to? :specification_version
25
+ spec.specification_version = 3
26
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0')
27
+ spec.add_runtime_dependency 'activemodel', '~> 3.2.13'
28
+ spec.add_runtime_dependency 'rails', '~> 3.2'
29
+ spec.add_development_dependency 'bundler', '~> 1.3'
30
+ spec.add_development_dependency 'rake'
31
+ spec.add_development_dependency 'rspec'
32
+ spec.add_development_dependency 'sqlite3'
33
+ else
34
+ spec.add_dependency 'activemodel', '~> 3.2.13'
35
+ spec.add_runtime_dependency 'rails', '~> 3.2'
36
+ spec.add_dependency 'bundler', '~> 1.3'
37
+ spec.add_dependency 'rake'
38
+ spec.add_dependency 'rspec'
39
+ spec.add_dependency 'sqlite3'
40
+ end
41
+ else
42
+ spec.add_dependency 'activemodel', '~> 3.2.13'
43
+ spec.add_runtime_dependency 'rails', '~> 3.2'
44
+ spec.add_dependency 'bundler', '~> 1.3'
45
+ spec.add_dependency 'rake'
46
+ spec.add_dependency 'rspec'
47
+ spec.add_dependency 'sqlite3'
48
+ end
49
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Model do
4
+ context 'class method' do
5
+ it 'should mark name as required' do
6
+ Model.mark_required?(:name).should be_true
7
+ end
8
+ it 'should not mark color as required' do
9
+ Model.mark_required?(:color).should_not be_true
10
+ end
11
+ end
12
+ context 'instance method' do
13
+ before do
14
+ @model = Model.create(:name => 'Bob', :color => 'green')
15
+ end
16
+ it 'should mark name as required' do
17
+ @model.mark_required?(:name).should be_true
18
+ end
19
+ it 'should not mark color as required' do
20
+ @model.mark_required?(:color).should_not be_true
21
+ end
22
+ end
23
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,5 @@
1
+ +--colour
2
+ +--format progress
3
+ +--loadby mtime
4
+ +--reverse
5
+
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'rails'
5
+ require 'active_record'
6
+ require 'rails/mark_requirements'
7
+
8
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
9
+
10
+ ActiveRecord::Schema.define(:version => 1) do
11
+ create_table :models do |t|
12
+ t.string :name
13
+ t.string :color
14
+ end
15
+ end
16
+
17
+ class Model < ActiveRecord::Base
18
+ include Rails::MarkRequirements
19
+ attr_accessible :name, :color
20
+ validates :name, :presence => true
21
+ end
22
+
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-mark_requirements
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Paul Belt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activemodel
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.13
22
+ requirement: !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 3.2.13
28
+ type: :runtime
29
+ prerelease: false
30
+ - !ruby/object:Gem::Dependency
31
+ name: rails
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.2'
38
+ requirement: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '3.2'
44
+ type: :runtime
45
+ prerelease: false
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ requirement: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: '1.3'
60
+ type: :development
61
+ prerelease: false
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirement: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirement: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ - !ruby/object:Gem::Dependency
95
+ name: sqlite3
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirement: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ type: :development
109
+ prerelease: false
110
+ description: expose presence-validation in a more controller-friendly manner
111
+ email:
112
+ - saprb@channing.harvard.edu
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - .rspec
119
+ - .rvmrc
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - lib/generators/rails/mark_requirements/install_generator.rb
125
+ - lib/generators/rails/mark_requirements/templates/features/mark_requirements.rb
126
+ - lib/rails/mark_requirements.rb
127
+ - lib/rails/mark_requirements/version.rb
128
+ - rails-mark_requirements.gemspec
129
+ - spec/rails-mark_requirements/mark_requirements_spec.rb
130
+ - spec/spec.opts
131
+ - spec/spec_helper.rb
132
+ homepage: https://github.com/belt/rails-mark_requirements
133
+ licenses:
134
+ - MIT
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ! '>='
143
+ - !ruby/object:Gem::Version
144
+ version: 1.9.2
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 1.8.25
154
+ signing_key:
155
+ specification_version: 3
156
+ summary: expose presence-validation in a more controller-friendly manner
157
+ test_files:
158
+ - spec/rails-mark_requirements/mark_requirements_spec.rb
159
+ - spec/spec.opts
160
+ - spec/spec_helper.rb