trimmable 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.
@@ -0,0 +1,4 @@
1
+ README.rdoc
2
+ Rakefile
3
+ lib/trimmable.rb
4
+ Manifest
File without changes
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('trimmable', '0.1.1') do |p|
6
+ p.description = "Trimmable removes leading and trailing white spaces from the AR attribute values."
7
+ p.url = "http://github.com/viola/trimmable"
8
+ p.author = "Wioletta Holownia"
9
+ p.email = "viola.holownia@gmail.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
@@ -0,0 +1,19 @@
1
+ module Trimmable
2
+ def self.included(base)
3
+ base.extend ClassMethods
4
+ end
5
+
6
+ module ClassMethods
7
+ def trimmable_attributes *attributes_list
8
+ before_validation do |model|
9
+ attributes_list.each do |attribute|
10
+ model[attribute] = model[attribute].strip if model[attribute].respond_to?(:strip)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ class ActiveRecord::Base
18
+ include Trimmable
19
+ end
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'active_record'
3
+ require 'test/unit'
4
+
5
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
6
+ require 'trimmable'
7
+
8
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
9
+
10
+ ActiveRecord::Schema.define(:version => 1) do
11
+ create_table :posts do |t|
12
+ t.string :title
13
+ t.text :comments
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ require File.join( File.dirname(__FILE__), 'test_helper' )
2
+ require File.join( File.dirname(__FILE__), 'models/post')
3
+
4
+ class TrimmableTest < Test::Unit::TestCase
5
+ def test_should_not_create_a_post_without_a_title
6
+ assert Post.create.errors[:title].any?
7
+ end
8
+
9
+ def test_should_not_create_a_post_with_a_empty_title
10
+ assert Post.create(:title => " ").errors[:title].any?
11
+ end
12
+
13
+ def test_trimmable_should_strip_white_spaces_from_the_title_and_comments
14
+ title = " Hello world. "
15
+ comments = "First comment. "
16
+ assert_equal title.strip, Post.create(:title => title).title
17
+ assert_equal comments.strip, Post.create(:title => title, :comments => comments).comments
18
+ end
19
+ end
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{trimmable}
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 = ["Wioletta Holownia"]
9
+ s.date = %q{2010-10-31}
10
+ s.description = %q{Trimmable removes leading and trailing white spaces from the AR attribute values.}
11
+ s.email = %q{viola.holownia@gmail.com}
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/trimmable.rb"]
13
+ s.files = ["README.rdoc", "Rakefile", "lib/trimmable.rb", "Manifest", "trimmable.gemspec", "test/test_helper.rb", "test/trimmable_test.rb"]
14
+ s.homepage = %q{http://github.com/viola/trimmable}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Trimmable", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{trimmable}
18
+ s.rubygems_version = %q{1.3.7}
19
+ s.summary = %q{Trimmable removes leading and trailing white spaces from the AR attribute values.}
20
+ s.test_files = ["test/test_helper.rb", "test/trimmable_test.rb"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
+ else
28
+ end
29
+ else
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trimmable
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Wioletta Holownia
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-31 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Trimmable removes leading and trailing white spaces from the AR attribute values.
23
+ email: viola.holownia@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ - lib/trimmable.rb
31
+ files:
32
+ - README.rdoc
33
+ - Rakefile
34
+ - lib/trimmable.rb
35
+ - Manifest
36
+ - trimmable.gemspec
37
+ - test/test_helper.rb
38
+ - test/trimmable_test.rb
39
+ has_rdoc: true
40
+ homepage: http://github.com/viola/trimmable
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options:
45
+ - --line-numbers
46
+ - --inline-source
47
+ - --title
48
+ - Trimmable
49
+ - --main
50
+ - README.rdoc
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ hash: 11
68
+ segments:
69
+ - 1
70
+ - 2
71
+ version: "1.2"
72
+ requirements: []
73
+
74
+ rubyforge_project: trimmable
75
+ rubygems_version: 1.3.7
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Trimmable removes leading and trailing white spaces from the AR attribute values.
79
+ test_files:
80
+ - test/test_helper.rb
81
+ - test/trimmable_test.rb