pdobb-update_attribute 0.1.4
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/CHANGELOG +6 -0
- data/Manifest +7 -0
- data/README.rdoc +51 -0
- data/Rakefile +14 -0
- data/init.rb +1 -0
- data/lib/update_attribute.rb +20 -0
- data/update_attribute.gemspec +30 -0
- metadata +67 -0
data/CHANGELOG
ADDED
data/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
= update_attribute
|
2
|
+
|
3
|
+
Rails gem for simplifying calls to update_attribute on Active Record objects by allowing you to replace *attribute* in update_*attribute* with the actual name of the attribute to be updated and then just pass in the value to update that attribute to. The passed in value may be a string or a symbol (symbols will be converted to a string for you).
|
4
|
+
|
5
|
+
== INSTALL:
|
6
|
+
|
7
|
+
sudo gem install pdobb-update_attribute --source http://gems.github.com
|
8
|
+
|
9
|
+
== USAGE:
|
10
|
+
|
11
|
+
Wihtout update_attribute:
|
12
|
+
|
13
|
+
<active_record_object>.update_attribute(<attribute>, <value>)
|
14
|
+
|
15
|
+
With update_attribute:
|
16
|
+
|
17
|
+
<active_record_object>.update_<attribute>(<value>)
|
18
|
+
|
19
|
+
Example:
|
20
|
+
|
21
|
+
user = User.find_by_username("Paul") # => #<User id: 1, username: "Paul", ...>
|
22
|
+
user.update_username "Muad'Dib" # => true
|
23
|
+
user.reload.username # => "Muad'Dib"
|
24
|
+
|
25
|
+
user.update_username :Atreides # => true
|
26
|
+
user.reload.username # => "Atreides"
|
27
|
+
|
28
|
+
== LICENSE:
|
29
|
+
|
30
|
+
(The MIT License)
|
31
|
+
|
32
|
+
Copyright (c) 2009 Paul Dobbins
|
33
|
+
|
34
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
35
|
+
a copy of this software and associated documentation files (the
|
36
|
+
'Software'), to deal in the Software without restriction, including
|
37
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
38
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
39
|
+
permit persons to whom the Software is furnished to do so, subject to
|
40
|
+
the following conditions:
|
41
|
+
|
42
|
+
The above copyright notice and this permission notice shall be
|
43
|
+
included in all copies or substantial portions of the Software.
|
44
|
+
|
45
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
46
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
47
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
48
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
49
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
50
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
51
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('update_attribute', '0.1.4') do |p|
|
6
|
+
p.description = %q{Simplifies calls to update_attribute on ActiveRecord objects by allowing you to replace "attribute" with the actual name of the attribute to be updated.}
|
7
|
+
p.url = "http://github.com/pdobb/update_attribute"
|
8
|
+
p.author = "Paul Dobbins"
|
9
|
+
p.email = "pdobbins@gmail.com"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.development_dependencies = []
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'update_attribute'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module UpdateAttribute
|
2
|
+
VERSION = "0.1.4"
|
3
|
+
end
|
4
|
+
|
5
|
+
class ActiveRecord::Base
|
6
|
+
def method_missing(method, *args, &block)
|
7
|
+
pattern = /^update_([a-z][a-z_]*)$/
|
8
|
+
if match = pattern.match(method.to_s)
|
9
|
+
attribute = match[1]
|
10
|
+
if self.respond_to?(attribute)
|
11
|
+
value = args.first
|
12
|
+
value = value.to_s if value.is_a?(Symbol)
|
13
|
+
return self.update_attribute(attribute, value, &block)
|
14
|
+
else
|
15
|
+
raise NoMethodError, "undefined attribute `#{attribute}' for #{self}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{update_attribute}
|
5
|
+
s.version = "0.1.4"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Paul Dobbins"]
|
9
|
+
s.date = %q{2009-09-26}
|
10
|
+
s.description = %q{Simplifies calls to update_attribute on ActiveRecord objects by allowing you to replace "attribute" with the actual name of the attribute to be updated.}
|
11
|
+
s.email = %q{pdobbins@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "lib/update_attribute.rb"]
|
13
|
+
s.files = ["CHANGELOG", "Manifest", "README.rdoc", "Rakefile", "init.rb", "lib/update_attribute.rb", "update_attribute.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/pdobb/update_attribute}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Update_attribute", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{update_attribute}
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
19
|
+
s.summary = %q{Simplifies calls to update_attribute on ActiveRecord objects by allowing you to replace "attribute" with the actual name of the attribute to be updated.}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
else
|
27
|
+
end
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pdobb-update_attribute
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Dobbins
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-26 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Simplifies calls to update_attribute on ActiveRecord objects by allowing you to replace "attribute" with the actual name of the attribute to be updated.
|
17
|
+
email: pdobbins@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- CHANGELOG
|
24
|
+
- README.rdoc
|
25
|
+
- lib/update_attribute.rb
|
26
|
+
files:
|
27
|
+
- CHANGELOG
|
28
|
+
- Manifest
|
29
|
+
- README.rdoc
|
30
|
+
- Rakefile
|
31
|
+
- init.rb
|
32
|
+
- lib/update_attribute.rb
|
33
|
+
- update_attribute.gemspec
|
34
|
+
has_rdoc: false
|
35
|
+
homepage: http://github.com/pdobb/update_attribute
|
36
|
+
licenses:
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options:
|
39
|
+
- --line-numbers
|
40
|
+
- --inline-source
|
41
|
+
- --title
|
42
|
+
- Update_attribute
|
43
|
+
- --main
|
44
|
+
- README.rdoc
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "1.2"
|
58
|
+
version:
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project: update_attribute
|
62
|
+
rubygems_version: 1.3.5
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Simplifies calls to update_attribute on ActiveRecord objects by allowing you to replace "attribute" with the actual name of the attribute to be updated.
|
66
|
+
test_files: []
|
67
|
+
|