beef-active_form 1.0.3 → 1.1.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 +3 -0
- data/README.txt +51 -0
- data/Rakefile +46 -13
- data/VERSION +1 -0
- data/active_form.gemspec +45 -0
- data/lib/active_form.rb +13 -6
- data/test/basic_test.rb +2 -0
- metadata +19 -24
data/.gitignore
ADDED
data/README.txt
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
= active-form plugin for Rails
|
|
2
|
+
|
|
3
|
+
active-form is a plugin that makes it easy to have model objects that support the
|
|
4
|
+
ActiveRecord Validations but are not backed by database tables. The plugin is designed
|
|
5
|
+
to make it possible to use the ActiveForm derived classes in a very similar manner to
|
|
6
|
+
the ActiveRecord::Base derived objects.
|
|
7
|
+
|
|
8
|
+
Originally described at;
|
|
9
|
+
|
|
10
|
+
http://www.realityforge.org/articles/2005/12/02/validations-for-non-activerecord-model-objects
|
|
11
|
+
|
|
12
|
+
== How To Define An ActiveForm Object
|
|
13
|
+
|
|
14
|
+
class Search < ActiveForm
|
|
15
|
+
attr_accessor :text
|
|
16
|
+
validates_length_of :text, :maximum=>30
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
== How To Use ActiveForm Object In Controller
|
|
20
|
+
|
|
21
|
+
class NavigatorController < ApplicationController
|
|
22
|
+
def search
|
|
23
|
+
@search = Search.new(params[:search])
|
|
24
|
+
if @search.valid?
|
|
25
|
+
...do search here...
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
== How To Use ActiveForm Object In View
|
|
31
|
+
|
|
32
|
+
<%= start_form_tag(:action => 'search') %>
|
|
33
|
+
<%= error_messages_for('search') %>
|
|
34
|
+
<%= text_field('search', 'text', {"maxlength" => 30}) %>
|
|
35
|
+
<button type="submit">Save</button>
|
|
36
|
+
<%= end_form_tag %>
|
|
37
|
+
|
|
38
|
+
== Details
|
|
39
|
+
|
|
40
|
+
License: Released under the MIT license.
|
|
41
|
+
Latest Version: http://www.realityforge.org/svn/public/code/active-form/trunk/
|
|
42
|
+
|
|
43
|
+
== Credits
|
|
44
|
+
|
|
45
|
+
Peter Donald <peter at realityforge dot org>.
|
|
46
|
+
Dae San Hwang for fix to work with Rails 1.1.
|
|
47
|
+
Trevor Squires for suggestion to use Reloadable::Subclasses rather than dispatcher hack for Rails 1.1.
|
|
48
|
+
Tim Lucas for patch to allow bulk addition of attributes.
|
|
49
|
+
Geoff Schmidt for adding support for Callbacks.
|
|
50
|
+
Sean Christman for attributes getter.
|
|
51
|
+
Jack Christensen for attributes setter.
|
data/Rakefile
CHANGED
|
@@ -1,22 +1,55 @@
|
|
|
1
|
+
require 'rubygems'
|
|
1
2
|
require 'rake'
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'jeweler'
|
|
6
|
+
Jeweler::Tasks.new do |gem|
|
|
7
|
+
gem.name = "active_form"
|
|
8
|
+
gem.summary = %Q{Validations for Non Active Record Models}
|
|
9
|
+
gem.email = "steve@wearebeef.co.uk"
|
|
10
|
+
gem.homepage = "http://github.com/beef/active_form"
|
|
11
|
+
gem.authors = ["Steve England"]
|
|
12
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
rescue LoadError
|
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
|
17
|
+
end
|
|
18
|
+
|
|
2
19
|
require 'rake/testtask'
|
|
3
|
-
|
|
20
|
+
Rake::TestTask.new(:test) do |test|
|
|
21
|
+
test.libs << 'lib' << 'test'
|
|
22
|
+
test.pattern = 'test/**/*_test.rb'
|
|
23
|
+
test.verbose = true
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
begin
|
|
27
|
+
require 'rcov/rcovtask'
|
|
28
|
+
Rcov::RcovTask.new do |test|
|
|
29
|
+
test.libs << 'test'
|
|
30
|
+
test.pattern = 'test/**/*_test.rb'
|
|
31
|
+
test.verbose = true
|
|
32
|
+
end
|
|
33
|
+
rescue LoadError
|
|
34
|
+
task :rcov do
|
|
35
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
4
39
|
|
|
5
|
-
desc 'Default: run unit tests.'
|
|
6
40
|
task :default => :test
|
|
7
41
|
|
|
8
|
-
|
|
9
|
-
Rake::
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
42
|
+
require 'rake/rdoctask'
|
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
|
44
|
+
if File.exist?('VERSION.yml')
|
|
45
|
+
config = YAML.load(File.read('VERSION.yml'))
|
|
46
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
|
47
|
+
else
|
|
48
|
+
version = ""
|
|
49
|
+
end
|
|
14
50
|
|
|
15
|
-
desc 'Generate documentation for the ActiveForm plugin.'
|
|
16
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
17
51
|
rdoc.rdoc_dir = 'rdoc'
|
|
18
|
-
rdoc.title
|
|
19
|
-
rdoc.
|
|
20
|
-
rdoc.rdoc_files.include('README')
|
|
52
|
+
rdoc.title = "acts_as_content_node #{version}"
|
|
53
|
+
rdoc.rdoc_files.include('README*')
|
|
21
54
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
22
55
|
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.1.1
|
data/active_form.gemspec
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |s|
|
|
4
|
+
s.name = %q{active_form}
|
|
5
|
+
s.version = "1.1.1"
|
|
6
|
+
|
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
8
|
+
s.authors = ["Steve England"]
|
|
9
|
+
s.date = %q{2009-06-09}
|
|
10
|
+
s.email = %q{steve@wearebeef.co.uk}
|
|
11
|
+
s.extra_rdoc_files = [
|
|
12
|
+
"README.txt"
|
|
13
|
+
]
|
|
14
|
+
s.files = [
|
|
15
|
+
".gitignore",
|
|
16
|
+
"MIT-LICENCE",
|
|
17
|
+
"README.txt",
|
|
18
|
+
"Rakefile",
|
|
19
|
+
"VERSION",
|
|
20
|
+
"active_form.gemspec",
|
|
21
|
+
"init.rb",
|
|
22
|
+
"lib/active_form.rb",
|
|
23
|
+
"test/basic_test.rb",
|
|
24
|
+
"test/test_helper.rb"
|
|
25
|
+
]
|
|
26
|
+
s.homepage = %q{http://github.com/beef/active_form}
|
|
27
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
28
|
+
s.require_paths = ["lib"]
|
|
29
|
+
s.rubygems_version = %q{1.3.3}
|
|
30
|
+
s.summary = %q{Validations for Non Active Record Models}
|
|
31
|
+
s.test_files = [
|
|
32
|
+
"test/basic_test.rb",
|
|
33
|
+
"test/test_helper.rb"
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
if s.respond_to? :specification_version then
|
|
37
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
38
|
+
s.specification_version = 3
|
|
39
|
+
|
|
40
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
41
|
+
else
|
|
42
|
+
end
|
|
43
|
+
else
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/active_form.rb
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
class ActiveForm
|
|
2
2
|
def initialize(attributes = nil)
|
|
3
|
-
|
|
4
|
-
if attributes
|
|
5
|
-
attributes.each do |key, value|
|
|
6
|
-
self[key] = value
|
|
7
|
-
end
|
|
8
|
-
end
|
|
3
|
+
self.attributes=(attributes)
|
|
9
4
|
yield self if block_given?
|
|
10
5
|
end
|
|
11
6
|
|
|
7
|
+
def attributes=(attributes)
|
|
8
|
+
attributes.each do |key, value|
|
|
9
|
+
self[key] = value
|
|
10
|
+
end if attributes
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def attributes
|
|
14
|
+
attributes = instance_variables
|
|
15
|
+
attributes.delete("@errors")
|
|
16
|
+
Hash[*attributes.collect { |attribute| [attribute[1..-1].to_sym, instance_variable_get(attribute)] }.flatten]
|
|
17
|
+
end
|
|
18
|
+
|
|
12
19
|
def [](key)
|
|
13
20
|
instance_variable_get("@#{key}")
|
|
14
21
|
end
|
data/test/basic_test.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: beef-active_form
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Steve England
|
|
@@ -9,39 +9,34 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-06-
|
|
12
|
+
date: 2009-06-09 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
|
-
dependencies:
|
|
15
|
-
|
|
16
|
-
name: activerecord
|
|
17
|
-
type: :runtime
|
|
18
|
-
version_requirement:
|
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
20
|
-
requirements:
|
|
21
|
-
- - ">="
|
|
22
|
-
- !ruby/object:Gem::Version
|
|
23
|
-
version: 2.1.0
|
|
24
|
-
version:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
25
16
|
description:
|
|
26
|
-
email:
|
|
17
|
+
email: steve@wearebeef.co.uk
|
|
27
18
|
executables: []
|
|
28
19
|
|
|
29
20
|
extensions: []
|
|
30
21
|
|
|
31
|
-
extra_rdoc_files:
|
|
32
|
-
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- README.txt
|
|
33
24
|
files:
|
|
34
|
-
-
|
|
35
|
-
- lib
|
|
36
|
-
- lib/active_form.rb
|
|
25
|
+
- .gitignore
|
|
37
26
|
- MIT-LICENCE
|
|
27
|
+
- README.txt
|
|
38
28
|
- Rakefile
|
|
39
|
-
-
|
|
29
|
+
- VERSION
|
|
30
|
+
- active_form.gemspec
|
|
31
|
+
- init.rb
|
|
32
|
+
- lib/active_form.rb
|
|
33
|
+
- test/basic_test.rb
|
|
34
|
+
- test/test_helper.rb
|
|
40
35
|
has_rdoc: false
|
|
41
36
|
homepage: http://github.com/beef/active_form
|
|
42
37
|
post_install_message:
|
|
43
|
-
rdoc_options:
|
|
44
|
-
|
|
38
|
+
rdoc_options:
|
|
39
|
+
- --charset=UTF-8
|
|
45
40
|
require_paths:
|
|
46
41
|
- lib
|
|
47
42
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
@@ -61,8 +56,8 @@ requirements: []
|
|
|
61
56
|
rubyforge_project:
|
|
62
57
|
rubygems_version: 1.2.0
|
|
63
58
|
signing_key:
|
|
64
|
-
specification_version:
|
|
59
|
+
specification_version: 3
|
|
65
60
|
summary: Validations for Non Active Record Models
|
|
66
61
|
test_files:
|
|
67
|
-
- test/test_helper.rb
|
|
68
62
|
- test/basic_test.rb
|
|
63
|
+
- test/test_helper.rb
|