gdagley-validatable_form 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Geoffrey Dagley
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,32 @@
1
+ = validatable_form
2
+
3
+ I wanted to validatable models without needing to create a table for ActiveRecord or having to
4
+ override/hack ActiveRecord methods. There may be other ways to do this, but this is what I came up with.
5
+
6
+ Now I can do this:
7
+
8
+ class ContactForm < ValidatableForm
9
+ form_fields :name, :email
10
+ validates_presence_of :name
11
+ validates_presence_of :email
12
+ end
13
+
14
+ f = ContactForm.new(:name => "John Doe", :email => "jdoe@example.com")
15
+ f.valid?
16
+
17
+ All the validations come from the validatable[http://validatable.rubyforge.org] gem.
18
+
19
+ == Note on Patches/Pull Requests
20
+
21
+ * Fork the project.
22
+ * Make your feature addition or bug fix.
23
+ * Add tests for it. This is important so I don't break it in a
24
+ future version unintentionally.
25
+ * Commit, do not mess with rakefile, version, or history.
26
+ (if you want to have your own version, that is fine but
27
+ bump version in a commit by itself I can ignore when I pull)
28
+ * Send me a pull request. Bonus points for topic branches.
29
+
30
+ == Copyright
31
+
32
+ Copyright (c) 2009 Geoffrey Dagley. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "validatable_form"
8
+ gem.summary = %Q{Create validatable, tableless models for forms without hacking ActiveRecord.}
9
+ gem.email = "gdagley@gmail.com"
10
+ gem.homepage = "http://github.com/gdagley/validatable_form"
11
+ gem.authors = ["Geoffrey Dagley"]
12
+ gem.add_dependency "validatable"
13
+ gem.add_development_dependency "rspec"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'spec/rake/spectask'
21
+ Spec::Rake::SpecTask.new(:spec) do |spec|
22
+ spec.libs << 'lib' << 'spec'
23
+ spec.spec_files = FileList['spec/**/*_spec.rb']
24
+ end
25
+
26
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
27
+ spec.libs << 'lib' << 'spec'
28
+ spec.pattern = 'spec/**/*_spec.rb'
29
+ spec.rcov = true
30
+ end
31
+
32
+ task :spec => :check_dependencies
33
+
34
+ task :default => :spec
35
+
36
+ require 'rake/rdoctask'
37
+ Rake::RDocTask.new do |rdoc|
38
+ if File.exist?('VERSION')
39
+ version = File.read('VERSION')
40
+ else
41
+ version = ""
42
+ end
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "validatable_form #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,22 @@
1
+ require 'validatable'
2
+
3
+ class ValidatableForm
4
+ include Validatable
5
+
6
+ def self.form_fields(*form_fields)
7
+ return if form_fields.empty?
8
+ attr_accessor *form_fields # !> `*' interpreted as argument prefix
9
+ initializations = form_fields.map { |field| "@#{field} = params[:#{field}]"}.join("\n")
10
+ module_eval "def initialize(params={})\n #{initializations}\n end"
11
+ end
12
+
13
+ # used by some of the Rails view helpers like form_for
14
+ def id
15
+ nil
16
+ end
17
+
18
+ # used by some of the Rails view helpers like form_for
19
+ def new_record?
20
+ true
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'validatable_form'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe ValidatableForm do
4
+ before(:all) do
5
+ class ContactForm < ValidatableForm
6
+ form_fields :name, :email
7
+ validates_presence_of :name
8
+ validates_presence_of :email
9
+ end
10
+
11
+ class EmptyForm < ValidatableForm
12
+ end
13
+ end
14
+
15
+ it "should register the form fields as attributes" do
16
+ ContactForm.new.respond_to?(:name).should be_true
17
+ end
18
+
19
+ it "should not register the form fields from other classes as attributes" do
20
+ EmptyForm.new.respond_to?(:name).should be_false
21
+ end
22
+
23
+ it "should allow initializing attributes with a hash" do
24
+ f = ContactForm.new(:name => "John Doe", :email => "jdoe@example.com")
25
+ f.name.should == "John Doe"
26
+ f.email.should == "jdoe@example.com"
27
+ end
28
+
29
+ it "should always be a new record" do
30
+ ContactForm.new.should be_new_record
31
+ end
32
+
33
+ it "should not have an id" do
34
+ ContactForm.new.id.should be_nil
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gdagley-validatable_form
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Geoffrey Dagley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-05 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: validatable
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description:
36
+ email: gdagley@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - lib/validatable_form.rb
52
+ - spec/spec_helper.rb
53
+ - spec/validatable_form_spec.rb
54
+ has_rdoc: false
55
+ homepage: http://github.com/gdagley/validatable_form
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --charset=UTF-8
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.2.0
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Create validatable, tableless models for forms without hacking ActiveRecord.
80
+ test_files:
81
+ - spec/spec_helper.rb
82
+ - spec/validatable_form_spec.rb