modify 0.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.
Files changed (7) hide show
  1. data/Manifest +5 -0
  2. data/README.rdoc +25 -0
  3. data/Rakefile +14 -0
  4. data/init.rb +1 -0
  5. data/lib/modify.rb +24 -0
  6. data/modify.gemspec +30 -0
  7. metadata +74 -0
data/Manifest ADDED
@@ -0,0 +1,5 @@
1
+ Manifest
2
+ README.rdoc
3
+ Rakefile
4
+ init.rb
5
+ lib/modify.rb
data/README.rdoc ADDED
@@ -0,0 +1,25 @@
1
+ = Modify
2
+
3
+ Rails gem for modifying model's attributes before validation.
4
+
5
+
6
+ = Usage
7
+
8
+ class Person < ActiveRecord::Base
9
+ modify :first_name, :last_name do |old_value|
10
+ old_value.upcase
11
+ end
12
+ end
13
+
14
+
15
+ p = Person.new :first_name => 'John', :last_name => 'Doe'
16
+ p.first_name #=> John
17
+ p.last_name #=> Doe
18
+ p.valid?
19
+ p.first_name #=> JOHN
20
+ p.last_name #=> DOE
21
+
22
+
23
+ = Installation
24
+
25
+ = License
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('modify', '0.1.1') do |p|
6
+ p.description = "Modify model fields before validation"
7
+ p.url = "http://github.com/cutalion/modify"
8
+ p.author = "Alexander Glushkov"
9
+ p.email = "cutalion@gmail.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*", "*.swp"]
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 'modify'
data/lib/modify.rb ADDED
@@ -0,0 +1,24 @@
1
+ module Modify
2
+ def self.included(base)
3
+ base.extend ClassMethods
4
+ end
5
+
6
+ module ClassMethods
7
+
8
+ def modify(*fields, &block)
9
+ before_validation do |record|
10
+ fields.each do |field|
11
+ old_value = record.send(field)
12
+ new_value = block.call old_value
13
+
14
+ record.send( "#{field}=", new_value )
15
+ end
16
+ end
17
+ end
18
+
19
+ end
20
+ end
21
+
22
+ class ActiveRecord::Base
23
+ include Modify
24
+ end
data/modify.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{modify}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Alexander Glushkov"]
9
+ s.date = %q{2011-07-28}
10
+ s.description = %q{Modify model fields before validation}
11
+ s.email = %q{cutalion@gmail.com}
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/modify.rb"]
13
+ s.files = ["Manifest", "README.rdoc", "Rakefile", "init.rb", "lib/modify.rb", "modify.gemspec"]
14
+ s.homepage = %q{http://github.com/cutalion/modify}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Modify", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{modify}
18
+ s.rubygems_version = %q{1.3.6}
19
+ s.summary = %q{Modify model fields before validation}
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,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: modify
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - Alexander Glushkov
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-07-28 00:00:00 +03:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Modify model fields before validation
22
+ email: cutalion@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.rdoc
29
+ - lib/modify.rb
30
+ files:
31
+ - Manifest
32
+ - README.rdoc
33
+ - Rakefile
34
+ - init.rb
35
+ - lib/modify.rb
36
+ - modify.gemspec
37
+ has_rdoc: true
38
+ homepage: http://github.com/cutalion/modify
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options:
43
+ - --line-numbers
44
+ - --inline-source
45
+ - --title
46
+ - Modify
47
+ - --main
48
+ - README.rdoc
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 1
64
+ - 2
65
+ version: "1.2"
66
+ requirements: []
67
+
68
+ rubyforge_project: modify
69
+ rubygems_version: 1.3.6
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Modify model fields before validation
73
+ test_files: []
74
+