arrayr 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/README +23 -0
- data/lib/arrayr.rb +50 -0
- metadata +81 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) Kristian Hellquist
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Arrayr
|
2
|
+
======
|
3
|
+
|
4
|
+
Module to use for letting attributes automatically return arrays for
|
5
|
+
comma separated values
|
6
|
+
|
7
|
+
Specify which attributes that should return array as values
|
8
|
+
and access the value by suffixing the attribute with "_multiple"
|
9
|
+
|
10
|
+
If a getter and setter doens't exists this module will create them for you.
|
11
|
+
|
12
|
+
Example
|
13
|
+
-------
|
14
|
+
|
15
|
+
class Foo
|
16
|
+
include Arrayr
|
17
|
+
attr_arrayr(:bar)
|
18
|
+
end
|
19
|
+
|
20
|
+
foo = Foo.new
|
21
|
+
foo.bar = "zoo, zum"
|
22
|
+
foo.bar_to_a => ["zoo", "zum"]
|
23
|
+
|
data/lib/arrayr.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module Arrayr
|
2
|
+
|
3
|
+
# Module to use for letting attributes automatically return arrays for
|
4
|
+
# comma separated values
|
5
|
+
#
|
6
|
+
# Specify which attributes that should return array as values
|
7
|
+
# and access the value by suffixing the attribute with "_multiple"
|
8
|
+
#
|
9
|
+
# If a getter and setter doens't exists this module will create them for you.
|
10
|
+
#
|
11
|
+
# Example
|
12
|
+
#
|
13
|
+
# class Foo
|
14
|
+
# include Array
|
15
|
+
# attr_array(:bar)
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# foo = Foo.new
|
19
|
+
# foo.bar = "zoo, zum"
|
20
|
+
# foo.bar_to_a => ["zoo", "zum"]
|
21
|
+
#
|
22
|
+
|
23
|
+
def self.included(klass)
|
24
|
+
klass.extend ClassMethods
|
25
|
+
end
|
26
|
+
|
27
|
+
class Value
|
28
|
+
def initialize(value=nil)
|
29
|
+
@value = value
|
30
|
+
end
|
31
|
+
def to_a
|
32
|
+
return nil if @value.nil?
|
33
|
+
@value.split(',').map(&:strip)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module ClassMethods
|
38
|
+
|
39
|
+
def attr_arrayr(*attrs)
|
40
|
+
attrs.each do |attr|
|
41
|
+
attr_reader(attr) unless self.instance_methods.include?(attr.to_s)
|
42
|
+
attr_writer(attr) unless self.instance_methods.include?("#{attr}=")
|
43
|
+
|
44
|
+
define_method "#{attr}_to_a" do
|
45
|
+
Value.new(send(attr)).to_a
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: arrayr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Kristian Hellquist
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-03-23 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
description: Let a defined attributes which contain strings return array values
|
35
|
+
email:
|
36
|
+
- kristian.hellquist@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- lib/arrayr.rb
|
45
|
+
- LICENSE
|
46
|
+
- README
|
47
|
+
homepage: http://github.com/meeiw/Arrayr
|
48
|
+
licenses: []
|
49
|
+
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
requirements: []
|
74
|
+
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 1.8.10
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: Let a defined set of attributes return arrays
|
80
|
+
test_files: []
|
81
|
+
|