jcnetdev-acts_as_applyable 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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Jacques Crocker
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 ADDED
@@ -0,0 +1,26 @@
1
+ ActsAsApplyable
2
+ ===============
3
+
4
+ acts_as_applyable is a Rails plugin that allows you to ditch attr_accessible and attr_protected, in favor of a cleaner way of dealing with mass assignment
5
+
6
+ Example
7
+ =======
8
+
9
+ Old way:
10
+ @user = User.new(params[:user])
11
+ @user.save
12
+
13
+ New way:
14
+ @user = User.new
15
+ @user.params = params[:user]
16
+ @user.apply(:username, :email, :password, :password_confirmation)
17
+
18
+ In order to enable it, run this on your model
19
+ acts_as_applyable
20
+
21
+ If you want to act similar to attr_accessible, you can pass it in a list of default attributes
22
+ acts_as_applyable :username, :email, :password, :password_confirmation
23
+
24
+ that way you can run @user.apply and it will use these
25
+
26
+ Copyright (c) 2008 RailsJedi.com, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the acts_as_applyable plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the acts_as_applyable plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'ActsAsApplyable'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
@@ -0,0 +1,29 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'acts_as_applyable'
3
+ s.version = '0.1'
4
+ s.date = '2008-09-16'
5
+
6
+ s.summary = "A better (and safer) way of applying model attributes from your controller params"
7
+ s.description = "Rid yourself of attr_accessible and attr_protected. This plugin allows you to stop using mass assignment, and gives you a more flexible way of interacting with your controller params."
8
+
9
+ s.authors = ['RailsJedi']
10
+ s.email = 'railsjedi@gmail.com'
11
+ s.homepage = 'http://github.com/jcnetdev/acts_as_applyable'
12
+
13
+ s.has_rdoc = true
14
+ s.rdoc_options = ["--main", "README"]
15
+ s.extra_rdoc_files = ["README"]
16
+
17
+ s.add_dependency 'activerecord', ['>= 2.1']
18
+
19
+ s.files = ["MIT-LICENSE",
20
+ "README",
21
+ "Rakefile",
22
+ "acts_as_applyable.gemspec",
23
+ "init.rb",
24
+ "lib/acts_as_applyable.rb",
25
+ "rails/init.rb"]
26
+
27
+ s.test_files = ["test/acts_as_applyable_test.rb"]
28
+
29
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/rails/init"
@@ -0,0 +1,66 @@
1
+ module ActiveRecord
2
+ module Acts
3
+ module Applyable
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def acts_as_applyable(*accessible_attributes)
10
+ cattr_accessor :accessible_attributes
11
+ self.accessible_attributes = accessible_attributes
12
+
13
+ include ActiveRecord::Acts::Applyable::InstanceMethods
14
+ end
15
+ end
16
+
17
+ module InstanceMethods
18
+ def params
19
+ @params ||= {}
20
+ @params
21
+ end
22
+
23
+ def params=(new_params)
24
+ @params = new_params
25
+ end
26
+
27
+ def apply_set_attributes(*attribute_list)
28
+ self.params.stringify_keys!
29
+
30
+ # build attributes hash
31
+ attributes = {}
32
+ attribute_list = accessible_attributes if attribute_list.empty?
33
+ attribute_list.each do |attribute|
34
+ attributes[attribute] = self.params[attribute.to_s]
35
+ end
36
+
37
+ # set attributes, ignoring protected
38
+ send :attributes=, attributes, false
39
+ end
40
+
41
+ def apply(*attributes)
42
+ apply_set_attributes(*attributes)
43
+ save
44
+ end
45
+
46
+ def apply!(*attributes)
47
+ apply_set_attributes(*attributes)
48
+ save!
49
+ end
50
+
51
+ # alias for save
52
+ def apply_all
53
+ self.attributes = params
54
+ save
55
+ end
56
+
57
+ # alias for save!
58
+ def apply_all!
59
+ self.attributes = params
60
+ save!
61
+ end
62
+
63
+ end
64
+ end
65
+ end
66
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'acts_as_applyable'
2
+
3
+ ActiveRecord::Base.send :include, ActiveRecord::Acts::Applyable
@@ -0,0 +1,17 @@
1
+ require 'test/unit'
2
+
3
+ class ActsAsApplyableTest < Test::Unit::TestCase
4
+ # Replace this with your real tests.
5
+ def test_set_params
6
+ flunk
7
+ end
8
+
9
+ def test_apply
10
+ flunk
11
+ end
12
+
13
+ def test_apply_all
14
+ flunk
15
+ end
16
+
17
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jcnetdev-acts_as_applyable
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - RailsJedi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-09-16 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activerecord
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "2.1"
23
+ version:
24
+ description: Rid yourself of attr_accessible and attr_protected. This plugin allows you to stop using mass assignment, and gives you a more flexible way of interacting with your controller params.
25
+ email: railsjedi@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README
32
+ files:
33
+ - MIT-LICENSE
34
+ - README
35
+ - Rakefile
36
+ - acts_as_applyable.gemspec
37
+ - init.rb
38
+ - lib/acts_as_applyable.rb
39
+ - rails/init.rb
40
+ has_rdoc: true
41
+ homepage: http://github.com/jcnetdev/acts_as_applyable
42
+ post_install_message:
43
+ rdoc_options:
44
+ - --main
45
+ - README
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.2.0
64
+ signing_key:
65
+ specification_version: 2
66
+ summary: A better (and safer) way of applying model attributes from your controller params
67
+ test_files:
68
+ - test/acts_as_applyable_test.rb