galetahub-enum_field 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 15aaf18aef53f29039a854952b1b5e44f0e4aa33
4
+ data.tar.gz: 4cb0b621ef38b6a5ba0ace8e8259e3b56b2872d8
5
+ SHA512:
6
+ metadata.gz: 759ab41e758a0a38e3186d1508a3b875a65044b3a5297ce89112231c3b7d93e80ebf7bc6072c40baaab773600460a179a0be68ccc1e1955521738c4de683bb39
7
+ data.tar.gz: 139d8b0a1dd4c9866d962c699ec3b3bdf47ec31b40b4637d97a98d39fbf902657107eab33aa217278c4adf444675c1506fdd16d24d58cf63b1b4d46791a6833a
@@ -36,14 +36,16 @@ module EnumField
36
36
  # +name_attribute+ with an +_id+ suffix.
37
37
  # * +class+: the class that will be instantiated when +name_attribute+ method is called. Defaults to
38
38
  # +name_attribute+ in camelcase form.
39
+ #
39
40
  def enumerated_attribute(name_attribute, options = {})
40
- id_attribute = options[:id_attribute] || (name_attribute.to_s + '_id').to_sym
41
- klass = options[:class] || name_attribute.to_s.camelcase.constantize
41
+ id_attribute = (options[:id_attribute] || "#{name_attribute}_id").to_sym
42
+ klass = options[:class] || (options[:class_name] || name_attribute).to_s.camelcase.constantize
43
+
42
44
  define_method(name_attribute) do
43
45
  (raw = read_attribute(id_attribute)) && klass.find_by_id(raw)
44
46
  end
45
47
 
46
- define_method(name_attribute.to_s + '=') do |value|
48
+ define_method("#{name_attribute}=") do |value|
47
49
  write_attribute(id_attribute, value ? value.id : nil)
48
50
  end
49
51
  end
@@ -1,3 +1,3 @@
1
1
  module EnumField
2
- VERSION = "0.2.1".freeze
2
+ VERSION = "0.2.2".freeze
3
3
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: galetahub-enum_field
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
5
- prerelease:
4
+ version: 0.2.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Igor Galeta
@@ -10,7 +9,7 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-10-23 00:00:00.000000000 Z
12
+ date: 2014-06-17 00:00:00.000000000 Z
14
13
  dependencies: []
15
14
  description: Enables Active Record attributes to point to enum like objects, by saving
16
15
  in your database only an integer ID
@@ -31,26 +30,25 @@ files:
31
30
  - README.rdoc
32
31
  homepage: https://github.com/galetahub/enum_field
33
32
  licenses: []
33
+ metadata: {}
34
34
  post_install_message:
35
35
  rdoc_options: []
36
36
  require_paths:
37
37
  - lib
38
38
  required_ruby_version: !ruby/object:Gem::Requirement
39
- none: false
40
39
  requirements:
41
- - - ! '>='
40
+ - - '>='
42
41
  - !ruby/object:Gem::Version
43
42
  version: '0'
44
43
  required_rubygems_version: !ruby/object:Gem::Requirement
45
- none: false
46
44
  requirements:
47
- - - ! '>='
45
+ - - '>='
48
46
  - !ruby/object:Gem::Version
49
47
  version: '0'
50
48
  requirements: []
51
49
  rubyforge_project: enum_field
52
- rubygems_version: 1.8.25
50
+ rubygems_version: 2.1.11
53
51
  signing_key:
54
- specification_version: 3
52
+ specification_version: 4
55
53
  summary: Enumerated attributes for Active Record
56
54
  test_files: []