rubyenum 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a718b495502c60b4dec9bf7c376002b048e0b7f9
4
- data.tar.gz: 7fae00b9100fa0182f0c297baf38949625080b38
3
+ metadata.gz: a13d9004ed30ecc48f10fde6c097a520b74c6769
4
+ data.tar.gz: 194d40e10e92cdf7f656d3a11dd86e01f510cb05
5
5
  SHA512:
6
- metadata.gz: 11d49609389439c0db76e1b53b1247bbada4b8514bdcd9f703a726d6d2ae1cece2108e7b7bec9ee43df7f7a2755573102cab30558a06c556e7e60d607844ce7b
7
- data.tar.gz: 714bf55633f10941568cb87461536011516ae9d63f294b5f349af7e97b841d2ebeda82338edb7ff8ba16e468f41000c1751cb79891588101510601f958b8b2fa
6
+ metadata.gz: 3c3bd66a2856d0b927a3912bcc27ea44b27af11e85578434a37edf4109d236bc451cebb61a3711d9c1671588879597780514eb6fcbc157826a479c32389a014f
7
+ data.tar.gz: dddcba56f810aa9668c0da97d929503276415d4a8457c8a694d8506507cf04246b561dfc72beab0ff21e2ee566ac523db515d975df8bfcfbe7152b603d81d5ae
data/lib/rubyenum.rb CHANGED
@@ -26,9 +26,9 @@ module RubyEnum
26
26
  enumObj = EnumObj.new symbol.to_s
27
27
  const_set(symbol.to_s, enumObj)
28
28
  vals.each_with_index do |val, i|
29
- # define a constant mouse on the class that points to the object with these
30
- # fields
31
-
29
+ if get_fields[i].nil?
30
+ raise "too many arguments passed to enum. Each enum may only have as many values as fields defined."
31
+ end
32
32
  enumObj.add_attribute(get_fields[i], val)
33
33
  end
34
34
  @@all << enumObj
@@ -51,7 +51,32 @@ module RubyEnum
51
51
  end
52
52
  end
53
53
 
54
+ end
54
55
 
56
+ ## depends on rails
57
+ module Associations
58
+
59
+ def enumify(method_name, hash)
60
+ klass = Object.const_get(hash[:with].to_s.camelize)
61
+
62
+ define_method(method_name) do
63
+ enum_to_return = nil
64
+ var = read_attribute(method_name)
65
+ klass.all.each do |item|
66
+ if item.send(hash[:use]) == var
67
+ enum_to_return = item
68
+ break;
69
+ end
70
+ end
71
+ enum_to_return
72
+ end
73
+
74
+ define_method(:"#{method_name.to_s}=") do |enum|
75
+ write_attribute(method_name, enum.send(hash[:use]))
76
+ nil
77
+ end
78
+
79
+ end
55
80
 
56
81
  end
57
82
 
@@ -69,4 +94,21 @@ end
69
94
  # enum :FISH, 3, "nemo"
70
95
 
71
96
  # end
97
+
98
+ # class Zoo
99
+
100
+ # extend RubyEnum::Associations
101
+
102
+ # attr_accessor :animal
103
+
104
+ # enumify :animal, :with => :animal_example, :use => :id
105
+
106
+ # # overides getter and setter methods
107
+ # # animal=(EnumObj), sets the property to the :via value
108
+ # # animal => EnumObj, gets the property from the :via value
109
+
110
+
111
+ # end
112
+
113
+
72
114
 
@@ -1,3 +1,3 @@
1
1
  module Rubyenum
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyenum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - georgemayer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-13 00:00:00.000000000 Z
11
+ date: 2015-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler