coded_options 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +0 -0
- data/LICENSE +20 -0
- data/README.md +19 -0
- data/ROADMAP.md +0 -0
- data/lib/coded_options/base.rb +29 -0
- data/lib/coded_options/version.rb +3 -0
- data/lib/coded_options.rb +1 -0
- metadata +76 -0
data/CHANGELOG.md
ADDED
File without changes
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Jason Dew
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
CodedOptions
|
2
|
+
============
|
3
|
+
|
4
|
+
Just a way to clean up my normal way to deal with coded options. Basically,
|
5
|
+
it turns
|
6
|
+
|
7
|
+
coded_options :state, %w(initial active closed)
|
8
|
+
|
9
|
+
into
|
10
|
+
|
11
|
+
STATES = %w(initial active closed)
|
12
|
+
STATE_OPTIONS = [["initial", 0], ["active", 1], ["closed", 2]]
|
13
|
+
|
14
|
+
def state
|
15
|
+
return unless state_id
|
16
|
+
STATES[state_id]
|
17
|
+
end
|
18
|
+
|
19
|
+
Enjoy!
|
data/ROADMAP.md
ADDED
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module CodedOptions
|
2
|
+
module Constants
|
3
|
+
end
|
4
|
+
|
5
|
+
def self.extended base
|
6
|
+
base.send(:include, Constants)
|
7
|
+
end
|
8
|
+
|
9
|
+
def coded_options singular_name, values
|
10
|
+
plural_name = singular_name.to_s.pluralize
|
11
|
+
|
12
|
+
Constants.const_set plural_name.upcase, values
|
13
|
+
Constants.const_set "#{singular_name}_options".upcase, to_options(values)
|
14
|
+
|
15
|
+
class_eval <<-EOT, __FILE__, (__LINE__+1)
|
16
|
+
def #{singular_name} # def state
|
17
|
+
return unless #{singular_name}_id # return unless state_id
|
18
|
+
Constants::#{plural_name.upcase}[#{singular_name}_id] # STATES[state_id]
|
19
|
+
end # end
|
20
|
+
EOT
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def to_options values
|
26
|
+
values.zip((0..values.length).to_a)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "coded_options/base"
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coded_options
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jason Dew
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-07-12 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: A gem for making fields with coded values easier
|
23
|
+
email:
|
24
|
+
- jason.dew@gmail.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- lib/coded_options/base.rb
|
33
|
+
- lib/coded_options/version.rb
|
34
|
+
- lib/coded_options.rb
|
35
|
+
- LICENSE
|
36
|
+
- CHANGELOG.md
|
37
|
+
- README.md
|
38
|
+
- ROADMAP.md
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/jasondew/coded_options
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
hash: 3
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 23
|
63
|
+
segments:
|
64
|
+
- 1
|
65
|
+
- 3
|
66
|
+
- 6
|
67
|
+
version: 1.3.6
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project: coded_options
|
71
|
+
rubygems_version: 1.3.7
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Making options easier
|
75
|
+
test_files: []
|
76
|
+
|