galetahub-enum_field 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +7 -1
- data/Rakefile +0 -19
- data/lib/enum_field.rb +0 -1
- data/lib/enum_field/builder.rb +0 -1
- data/lib/enum_field/define_enum.rb +25 -9
- data/lib/enum_field/version.rb +1 -1
- metadata +28 -47
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 Aimbulance
|
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.rdoc
CHANGED
@@ -32,6 +32,8 @@ If you are not confortable with any of this options, maybe +enum_field+ is an an
|
|
32
32
|
== BASIC USAGE:
|
33
33
|
|
34
34
|
class Role
|
35
|
+
include EnumField::DefineEnum
|
36
|
+
|
35
37
|
define_enum do |builder|
|
36
38
|
builder.member :admin
|
37
39
|
builder.member :manager
|
@@ -55,6 +57,8 @@ If you are not confortable with any of this options, maybe +enum_field+ is an an
|
|
55
57
|
Your enum classes can have all the methods you need:
|
56
58
|
|
57
59
|
class PhoneType
|
60
|
+
include EnumField::DefineEnum
|
61
|
+
|
58
62
|
def initialize(name)
|
59
63
|
@name = name
|
60
64
|
end
|
@@ -83,6 +87,8 @@ You have some +AR+ like methods in enum classes
|
|
83
87
|
The library also mimics has_many :through behavior, for cases such as:
|
84
88
|
|
85
89
|
class Role
|
90
|
+
include EnumField::DefineEnum
|
91
|
+
|
86
92
|
define_enum do |builder|
|
87
93
|
builder.member :admin
|
88
94
|
builder.member :manager
|
@@ -118,7 +124,7 @@ The library also mimics has_many :through behavior, for cases such as:
|
|
118
124
|
|
119
125
|
== INSTALL:
|
120
126
|
|
121
|
-
|
127
|
+
gem 'galetahub-enum_field', :require => 'enum_field'
|
122
128
|
|
123
129
|
== LICENSE:
|
124
130
|
|
data/Rakefile
CHANGED
@@ -23,22 +23,3 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
23
23
|
rdoc.rdoc_files.include('README.rdoc')
|
24
24
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
25
25
|
end
|
26
|
-
|
27
|
-
begin
|
28
|
-
require 'jeweler'
|
29
|
-
Jeweler::Tasks.new do |s|
|
30
|
-
s.name = "galetahub-enum_field"
|
31
|
-
s.version = EnumField::VERSION
|
32
|
-
s.summary = "Enumerated attributes"
|
33
|
-
s.description = "Enables Active Record attributes to point to enum like objects, by saving in your database only an integer ID"
|
34
|
-
s.email = "galeta.igor@gmail.com"
|
35
|
-
s.homepage = "https://github.com/galetahub/enum_field"
|
36
|
-
s.authors = ["Igor Galeta", "Pavlo Galeta"]
|
37
|
-
s.files = FileList["[A-Z]*", "lib/**/*"]
|
38
|
-
s.extra_rdoc_files = FileList["[A-Z]*"] - %w(Rakefile)
|
39
|
-
end
|
40
|
-
|
41
|
-
Jeweler::GemcutterTasks.new
|
42
|
-
rescue LoadError
|
43
|
-
puts "Jeweler not available. Install it with: gem install jeweler"
|
44
|
-
end
|
data/lib/enum_field.rb
CHANGED
data/lib/enum_field/builder.rb
CHANGED
@@ -1,17 +1,33 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module EnumField
|
3
3
|
module DefineEnum
|
4
|
-
def
|
5
|
-
|
6
|
-
|
4
|
+
def self.included(base)
|
5
|
+
base.send :include, InstanceMethods
|
6
|
+
base.send :extend, ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def self.extended(base)
|
11
|
+
base.class_eval do
|
12
|
+
attr_reader :id
|
13
|
+
end
|
14
|
+
end
|
7
15
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
16
|
+
def define_enum(&block)
|
17
|
+
@enum_builder ||= EnumField::Builder.new(self)
|
18
|
+
yield @enum_builder
|
19
|
+
|
20
|
+
[:all, :names, :find_by_id, :find, :first, :last].each do |method|
|
21
|
+
instance_eval <<-END
|
22
|
+
def #{method}(*args, &block)
|
23
|
+
@enum_builder.send(:#{method}, *args, &block)
|
24
|
+
end
|
25
|
+
END
|
26
|
+
end
|
14
27
|
end
|
15
28
|
end
|
29
|
+
|
30
|
+
module InstanceMethods
|
31
|
+
end
|
16
32
|
end
|
17
33
|
end
|
data/lib/enum_field/version.rb
CHANGED
metadata
CHANGED
@@ -1,75 +1,56 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: galetahub-enum_field
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 4
|
10
|
-
version: 0.1.4
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Igor Galeta
|
14
9
|
- Pavlo Galeta
|
15
10
|
autorequire:
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
|
-
|
19
|
-
date: 2011-06-16 00:00:00 +03:00
|
20
|
-
default_executable:
|
13
|
+
date: 2012-04-29 00:00:00.000000000 Z
|
21
14
|
dependencies: []
|
22
|
-
|
23
|
-
|
15
|
+
description: Enables Active Record attributes to point to enum like objects, by saving
|
16
|
+
in your database only an integer ID
|
24
17
|
email: galeta.igor@gmail.com
|
25
18
|
executables: []
|
26
|
-
|
27
19
|
extensions: []
|
28
|
-
|
29
|
-
extra_rdoc_files:
|
20
|
+
extra_rdoc_files:
|
30
21
|
- README.rdoc
|
31
|
-
files:
|
32
|
-
- README.rdoc
|
33
|
-
- Rakefile
|
22
|
+
files:
|
34
23
|
- lib/enum_field.rb
|
24
|
+
- lib/enum_field/enumerated_attribute.rb
|
25
|
+
- lib/enum_field/version.rb
|
35
26
|
- lib/enum_field/builder.rb
|
36
27
|
- lib/enum_field/define_enum.rb
|
37
|
-
- lib/enum_field/enumerated_attribute.rb
|
38
28
|
- lib/enum_field/railtie.rb
|
39
|
-
-
|
40
|
-
|
29
|
+
- MIT-LICENSE
|
30
|
+
- Rakefile
|
31
|
+
- README.rdoc
|
41
32
|
homepage: https://github.com/galetahub/enum_field
|
42
33
|
licenses: []
|
43
|
-
|
44
34
|
post_install_message:
|
45
35
|
rdoc_options: []
|
46
|
-
|
47
|
-
require_paths:
|
36
|
+
require_paths:
|
48
37
|
- lib
|
49
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
39
|
none: false
|
51
|
-
requirements:
|
52
|
-
- -
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
|
55
|
-
|
56
|
-
- 0
|
57
|
-
version: "0"
|
58
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
45
|
none: false
|
60
|
-
requirements:
|
61
|
-
- -
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
|
64
|
-
segments:
|
65
|
-
- 0
|
66
|
-
version: "0"
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
67
50
|
requirements: []
|
68
|
-
|
69
|
-
|
70
|
-
rubygems_version: 1.6.2
|
51
|
+
rubyforge_project: enum_field
|
52
|
+
rubygems_version: 1.8.24
|
71
53
|
signing_key:
|
72
54
|
specification_version: 3
|
73
|
-
summary: Enumerated attributes
|
55
|
+
summary: Enumerated attributes for Active Record
|
74
56
|
test_files: []
|
75
|
-
|