attr_symbol 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Justin Wienckowski
1
+ Copyright (c) 2011 Justin Wienckowski
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -18,6 +18,9 @@ stored in string columns in the underlying data store.
18
18
  thing.a = 'urk'
19
19
  thing.a ### Returns :urk
20
20
 
21
+ If any of the attributes passed to #attr_symbol are not database columns of type string, an
22
+ ArgumentError exception will be raised.
23
+
21
24
  == Copyright
22
25
 
23
- Copyright (c) 2010 Justin Wienckowski. See LICENSE for details.
26
+ Copyright (c) 2011 Justin Wienckowski. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{attr_symbol}
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Justin Wienckowski"]
12
+ s.date = %q{2011-01-27}
13
+ s.description = %q{Attributes marked with the attr_symbol method can be set using strings or symbols, but when accessed will always return symbols.}
14
+ s.email = %q{jwinky+gems@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rvmrc",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "attr_symbol.gemspec",
27
+ "lib/attr_symbol.rb",
28
+ "test/helper.rb",
29
+ "test/test_attr_symbol.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/jwinky/attr_symbol}
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.3.7}
34
+ s.summary = %q{Declare one or more ActiveRecord attributes stored in string columns to be returned as symbols.}
35
+ s.test_files = [
36
+ "test/helper.rb",
37
+ "test/test_attr_symbol.rb"
38
+ ]
39
+
40
+ if s.respond_to? :specification_version then
41
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
46
+ s.add_development_dependency(%q<activerecord>, [">= 0"])
47
+ else
48
+ s.add_dependency(%q<shoulda>, [">= 0"])
49
+ s.add_dependency(%q<activerecord>, [">= 0"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<shoulda>, [">= 0"])
53
+ s.add_dependency(%q<activerecord>, [">= 0"])
54
+ end
55
+ end
56
+
data/lib/attr_symbol.rb CHANGED
@@ -8,11 +8,15 @@ module ActiveRecord::AttrSymbol
8
8
 
9
9
  def attr_symbol(*attributes)
10
10
  attributes.each do |attr|
11
+ unless columns_hash[attr.to_s] && columns_hash[attr.to_s].type == :string
12
+ raise ArgumentError, "Attribute :#{attr} is not a database column of type string"
13
+ end
14
+
11
15
  define_method(attr) do
12
16
  self[attr].try(:to_sym)
13
17
  end
14
18
 
15
- define_method(:"#{attr}=") do |value|
19
+ define_method("#{attr}=") do |value|
16
20
  self[attr] = value.try(:to_s)
17
21
  end
18
22
  end
@@ -21,4 +25,4 @@ module ActiveRecord::AttrSymbol
21
25
 
22
26
  end
23
27
 
24
- ActiveRecord::Base.send(:include, ActiveRecord::AttrSymbol)
28
+ ActiveRecord::Base.send(:include, ActiveRecord::AttrSymbol)
@@ -2,6 +2,8 @@ require 'helper'
2
2
 
3
3
  class Thing < ActiveRecord::Tableless
4
4
  column :foo, :string
5
+ column :bar, :integer
6
+
5
7
  attr_symbol :foo
6
8
  end
7
9
 
@@ -40,4 +42,26 @@ class TestAttrSymbol < Test::Unit::TestCase
40
42
  end
41
43
  end
42
44
  end
45
+
46
+ context "Calling #attr_symbol with a column that does not exist" do
47
+ should "raise ArgumentError" do
48
+ begin
49
+ Thing.send(:attr_symbol, :missing_attr)
50
+ fail "Expected ArgumentError but no exception thrown"
51
+ rescue ArgumentError => e
52
+ assert_equal "Attribute :missing_attr is not a database column of type string", e.message
53
+ end
54
+ end
55
+ end
56
+
57
+ context "Calling #attr_symbol with a column that is not a string" do
58
+ should "raise ArgumentError" do
59
+ begin
60
+ Thing.send(:attr_symbol, :bar)
61
+ fail "Expected ArgumentError but no exception thrown"
62
+ rescue ArgumentError => e
63
+ assert_equal "Attribute :bar is not a database column of type string", e.message
64
+ end
65
+ end
66
+ end
43
67
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attr_symbol
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Justin Wienckowski
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-08 00:00:00 -08:00
18
+ date: 2011-01-27 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -62,6 +62,7 @@ files:
62
62
  - README.rdoc
63
63
  - Rakefile
64
64
  - VERSION
65
+ - attr_symbol.gemspec
65
66
  - lib/attr_symbol.rb
66
67
  - test/helper.rb
67
68
  - test/test_attr_symbol.rb