galetahub-enum_field 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
- rails plugin install git://github.com/galetahub/enum_field.git
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
@@ -18,5 +18,4 @@ module EnumField
18
18
  class ObjectNotFound < StandardError; end
19
19
  end
20
20
 
21
- Module.send(:include, EnumField::DefineEnum)
22
21
  require 'enum_field/railtie'
@@ -45,7 +45,6 @@ module EnumField
45
45
 
46
46
  def assign_id(obj, candidate_id)
47
47
  id = new_id(candidate_id)
48
- obj.class.send(:attr_reader, :id)
49
48
  obj.instance_variable_set(:@id, id)
50
49
  end
51
50
 
@@ -1,17 +1,33 @@
1
1
  # encoding: utf-8
2
2
  module EnumField
3
3
  module DefineEnum
4
- def define_enum(&block)
5
- @enum_builder ||= EnumField::Builder.new(self)
6
- yield @enum_builder
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
- [:all, :names, :find_by_id, :find, :first, :last].each do |method|
9
- instance_eval <<-END
10
- def #{method}(*args, &block)
11
- @enum_builder.send(:#{method}, *args, &block)
12
- end
13
- END
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
@@ -1,3 +1,3 @@
1
1
  module EnumField
2
- VERSION = "0.1.4".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
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
- hash: 19
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
- description: Enables Active Record attributes to point to enum like objects, by saving in your database only an integer ID
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
- - lib/enum_field/version.rb
40
- has_rdoc: true
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
- hash: 3
55
- segments:
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
- hash: 3
64
- segments:
65
- - 0
66
- version: "0"
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
67
50
  requirements: []
68
-
69
- rubyforge_project:
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
-