hash_accessor 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Rakefile +8 -0
- data/hash_accessor.gemspec +1 -0
- data/lib/hash_accessor.rb +3 -3
- data/lib/{class_methods.rb → hash_accessor/class_methods.rb} +2 -0
- data/lib/{railtie.rb → hash_accessor/railtie.rb} +0 -0
- data/test/hash_accessor_test.rb +55 -0
- metadata +19 -5
data/.gitignore
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/Rakefile
ADDED
data/hash_accessor.gemspec
CHANGED
@@ -14,6 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.required_rubygems_version = ">= 1.3.6"
|
16
16
|
s.platform = Gem::Platform::RUBY
|
17
|
+
s.add_dependency('active_support', '>=3.0')
|
17
18
|
|
18
19
|
s.files = `git ls-files`.split("\n")
|
19
20
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/lib/hash_accessor.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
|
-
require 'railtie' if defined?(Rails)
|
4
|
+
require 'hash_accessor/railtie' if defined?(Rails)
|
5
5
|
|
6
6
|
module HashAccessor
|
7
|
-
VERSION = "0.0
|
7
|
+
VERSION = "0.1.0"
|
8
8
|
|
9
|
-
autoload :ClassMethods, 'class_methods'
|
9
|
+
autoload :ClassMethods, 'hash_accessor/class_methods'
|
10
10
|
|
11
11
|
def self.included(mod)
|
12
12
|
mod.extend(ClassMethods)
|
File without changes
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.expand_path("../lib/hash_accessor", File.dirname(__FILE__))
|
3
|
+
|
4
|
+
class HashAccessorTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
class TestClassWithHash
|
7
|
+
include HashAccessor
|
8
|
+
attr_accessor :options
|
9
|
+
|
10
|
+
hash_accessor :options, :unspecified_variable
|
11
|
+
hash_accessor :options, :test_integer, :type => :integer
|
12
|
+
hash_accessor :options, :test_bool, :type => :bool
|
13
|
+
hash_accessor :options, :test_array_1, :type => :array, :collects => lambda{|item| item.gsub(/li_/, "").to_i }
|
14
|
+
hash_accessor :options, :test_array_2, :type => :array, :reject_blanks => true
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
options = {}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def setup
|
22
|
+
@tester = TestClassWithHash.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_accessors_being_added_correct
|
26
|
+
assert @tester.respond_to?(:unspecified_variable)
|
27
|
+
|
28
|
+
@tester.unspecified_variable = "some test"
|
29
|
+
assert_equal "some test", @tester.unspecified_variable
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_accessors_being_casted_correctly
|
33
|
+
@tester.test_integer = "3"
|
34
|
+
assert_equal 3, @tester.test_integer
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_boolean_question_mark_method_being_added
|
38
|
+
assert !@tester.test_bool?
|
39
|
+
@tester.test_bool = true
|
40
|
+
assert @tester.test_bool?
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_array_collect_method
|
44
|
+
assert_equal [], @tester.test_array_1
|
45
|
+
@tester.test_array_1 = ["li_1", "li_2", "li_3"]
|
46
|
+
assert_equal [1, 2, 3], @tester.test_array_1
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_array_reject_blank_method
|
50
|
+
@tester.test_array_2 = ["", "1", "2"]
|
51
|
+
assert_equal ["1", "2"], @tester.test_array_2
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_accessor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,18 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2011-10-16 00:00:00.000000000Z
|
13
|
-
dependencies:
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: active_support
|
16
|
+
requirement: &2152987980 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2152987980
|
14
25
|
description: This gem provides accessor methods to hash keys.
|
15
26
|
email:
|
16
27
|
- development@forrestzeisler.com
|
@@ -22,11 +33,13 @@ files:
|
|
22
33
|
- .gitignore
|
23
34
|
- MIT-LICENSE
|
24
35
|
- README.rdoc
|
36
|
+
- Rakefile
|
25
37
|
- hash_accessor.gemspec
|
26
|
-
- lib/class_methods.rb
|
27
38
|
- lib/hash_accessor.rb
|
28
|
-
- lib/
|
39
|
+
- lib/hash_accessor/class_methods.rb
|
40
|
+
- lib/hash_accessor/railtie.rb
|
29
41
|
- rails/init.rb
|
42
|
+
- test/hash_accessor_test.rb
|
30
43
|
homepage:
|
31
44
|
licenses: []
|
32
45
|
post_install_message:
|
@@ -54,4 +67,5 @@ summary: This gem provides extended functionality to serialized hashed in rails.
|
|
54
67
|
allows you to define accessor methods for variable that rest inside a serialized
|
55
68
|
hash. This is very useful if you have a large list of often changing DB variables
|
56
69
|
on a model which don't get queried against.
|
57
|
-
test_files:
|
70
|
+
test_files:
|
71
|
+
- test/hash_accessor_test.rb
|