flexible_enum 0.2.2 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a885917e4b7e8bb397a0dab1d78711395ab49120
4
- data.tar.gz: b0baf4ab1c1bd0cfc3c337e5cc585c71043ff96f
3
+ metadata.gz: 583e2cdd2195fcf2ad05ab12cd8732b4e6102852
4
+ data.tar.gz: 9baa69b13d1bfbd5ce44b5885c47de174ea505f5
5
5
  SHA512:
6
- metadata.gz: cc8c6c0dc01306ccff5e961de08e66457486b4ef8f3e8ba5a716e356c8ad1b69a5403e51a158f8690e5d3b9a426bfea74c5807791a5dab83dd00d3fca1a7abc3
7
- data.tar.gz: da33ab81de96f8813b6cde44c4bafee0ec5b0de44a8f87749c0a2661a2464ca80d626648f6fb9ef31f0af41901d33267b5aafbff7caeea359bc669769e0caf2f
6
+ metadata.gz: 0480febf1a3dc4c81fcaa8e6b36304ed3e68f912b7340750ef38009f11e36583adbcddb37fc109476d5382fefe465f1499d01f023885fec194c4e3371f8baf22
7
+ data.tar.gz: f22e9e0d8754c3e99d24c223da23a1c686c92aa10e25fd25c1fef3be690b6e878c555edd4b355f0bc05d33f5803b99201dd50a9f8095c2d5bacdcb40cea9c9df
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ Current release (in development)
2
+ --------------------------------
3
+
4
+ * Adds `[option_name]_details` method to retrieve custom attributes of the
5
+ current enum option. #24
6
+
7
+ *Alex Robbin*
data/CONTRIBUTING.md CHANGED
@@ -12,6 +12,8 @@ To contribute to FlexibleEnum:
12
12
  4. Commit your changes (`git commit -am 'Add some feature'`)
13
13
  5. Push to the branch (`git push origin my-new-feature`)
14
14
  6. Create new Pull Request
15
+ 7. Commit a new entry at the top of [CHANGELOG.md](CHANGELOG.md) with a brief
16
+ description of your changes, the PR number, and your name.
15
17
 
16
18
  Want more detail on these steps? [Learn more about forking git
17
19
  repositories](https://guides.github.com/activities/forking/).
data/README.md CHANGED
@@ -1,3 +1,6 @@
1
+ [![Build Status](https://travis-ci.org/meyouhealth/flexible_enum.svg?branch=master)](https://travis-ci.org/meyouhealth/flexible_enum)
2
+ [![Code Climate](https://codeclimate.com/github/meyouhealth/flexible_enum/badges/gpa.svg)](https://codeclimate.com/github/meyouhealth/flexible_enum)
3
+
1
4
  # FlexibleEnum
2
5
 
3
6
  Give Ruby enum-like powers.
@@ -6,7 +9,7 @@ Give Ruby enum-like powers.
6
9
 
7
10
  Add this line to your application's Gemfile:
8
11
 
9
- gem "flexible_enum", git: 'git@github.com:meyouhealth/flexible_enum.git'
12
+ gem "flexible_enum"
10
13
 
11
14
  And then execute:
12
15
 
@@ -201,7 +204,7 @@ CashRegister.drawer_position_closed # => CashRegister.where(drawer_position: 1)
201
204
 
202
205
  ## Custom Options
203
206
 
204
- Configuration parameters passed to attribute options are saved even if they are unknown. Getting at custom configuration parameters is a little clumsy at the moment but this can still be useful in some cases:
207
+ Configuration parameters passed to attribute options are saved even if they are unknown.
205
208
 
206
209
  ```ruby
207
210
  class EmailEvent < ActiveRecord::Base
@@ -211,13 +214,15 @@ class EmailEvent < ActiveRecord::Base
211
214
  opened 3, processor_class: EmailOpenedProcessor
212
215
  delivered 4, processor_class: DeliveryProcessor
213
216
  end
214
-
215
- def process
216
- class.event_types[event_type][:processor_class].new(self).process
217
- end
218
217
  end
219
218
  ```
220
219
 
220
+ Custom configuration parameters are available as an instance method on the object as well.
221
+ ```
222
+ e = EmailEvent.new(event_type: 1)
223
+ e.event_type_details # => { processor_class: RejectedProcessor, value: 1 }
224
+ ```
225
+
221
226
  ## Option Introspection
222
227
 
223
228
  You may introspect on available options and their configuration parameters:
@@ -286,7 +291,7 @@ end
286
291
 
287
292
  ## Contributing
288
293
 
289
- Please see [CONTRIBUTING.md].
294
+ Please see [CONTRIBUTING.md](https://github.com/meyouhealth/flexible_enum/blob/master/CONTRIBUTING.md).
290
295
 
291
296
  ## About MeYou Health
292
297
 
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.test_files = spec.files.grep(%r{^spec/})
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_dependency "activesupport", ">= 3.0"
24
+ spec.add_dependency "activesupport", "~> 4.1"
25
25
 
26
26
  spec.add_development_dependency "appraisal"
27
27
  spec.add_development_dependency "bundler", "~> 1.3"
@@ -1,8 +1,13 @@
1
1
  module FlexibleEnum
2
- class NameConfigurator < AbstractConfigurator
2
+ class IdentityConfigurator < AbstractConfigurator
3
3
  def apply
4
4
  configurator = self
5
5
 
6
+ add_instance_method("#{attribute_name}_details") do
7
+ value = send(configurator.attribute_name)
8
+ configurator.details_for(value)
9
+ end
10
+
6
11
  add_instance_method("#{attribute_name}_name") do
7
12
  value = send(configurator.attribute_name)
8
13
  configurator.name_for(value)
@@ -26,6 +31,14 @@ module FlexibleEnum
26
31
  end
27
32
  end
28
33
 
34
+ def details_for(value)
35
+ if value
36
+ element_info(value).try(:last)
37
+ else
38
+ nil
39
+ end
40
+ end
41
+
29
42
  def human_name_for(value)
30
43
  if value
31
44
  element_name, element_config = element_info(value)
@@ -28,7 +28,7 @@ module FlexibleEnum
28
28
 
29
29
  # Configure the target object for the given attribute
30
30
  configurators = [ConstantConfigurator,
31
- NameConfigurator,
31
+ IdentityConfigurator,
32
32
  QuestionMethodConfigurator,
33
33
  SetterMethodConfigurator,
34
34
  ScopeConfigurator,
@@ -1,3 +1,3 @@
1
1
  module FlexibleEnum
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/flexible_enum.rb CHANGED
@@ -6,7 +6,7 @@ module FlexibleEnum
6
6
  autoload :Configuration, 'flexible_enum/configuration'
7
7
  autoload :AbstractConfigurator, 'flexible_enum/abstract_configurator'
8
8
  autoload :ConstantConfigurator, 'flexible_enum/constant_configurator'
9
- autoload :NameConfigurator, 'flexible_enum/name_configurator'
9
+ autoload :IdentityConfigurator, 'flexible_enum/identity_configurator'
10
10
  autoload :QuestionMethodConfigurator, 'flexible_enum/question_method_configurator'
11
11
  autoload :SetterMethodConfigurator, 'flexible_enum/setter_method_configurator'
12
12
  autoload :ScopeConfigurator, 'flexible_enum/scope_configurator'
@@ -1,6 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "name values" do
3
+ describe "identity values" do
4
+ it "retrieves the details for the current value" do
5
+ register = CashRegister.new
6
+ register.status = CashRegister::NOT_ACTIVE
7
+
8
+ expect(register.status_details).to eq(my_custom_option: "Nothing to see here", value: 10)
9
+ end
10
+
4
11
  it "retrieves the name for the current value" do
5
12
  register = CashRegister.new
6
13
  register.status = CashRegister::UNKNOWN
metadata CHANGED
@@ -1,124 +1,124 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexible_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Daubert
8
8
  - Alex Robbin
9
9
  - Adam Prescott
10
10
  - Matthew Daubert
11
- - Chad Dressler
12
11
  - Sean Santry
12
+ - Alex Robbin
13
+ - Chad Dressler
13
14
  - Adam Prescott
15
+ - David Larrabee
14
16
  - Sean Santry
15
- - jon.zeppieri
16
- - Alex Robbin
17
17
  - David C. Goldhirsch
18
- - David Larrabee
19
18
  - Guillermo Guerini
20
19
  - Matthew Daubert
20
+ - jon.zeppieri
21
21
  autorequire:
22
22
  bindir: bin
23
23
  cert_chain: []
24
- date: 2015-05-06 00:00:00.000000000 Z
24
+ date: 2015-06-12 00:00:00.000000000 Z
25
25
  dependencies:
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activesupport
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
- - - '>='
30
+ - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '3.0'
32
+ version: '4.1'
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - '>='
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '3.0'
39
+ version: '4.1'
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: appraisal
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - '>='
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  type: :development
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - '>='
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: bundler
56
56
  requirement: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - ~>
58
+ - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '1.3'
61
61
  type: :development
62
62
  prerelease: false
63
63
  version_requirements: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - ~>
65
+ - - "~>"
66
66
  - !ruby/object:Gem::Version
67
67
  version: '1.3'
68
68
  - !ruby/object:Gem::Dependency
69
69
  name: fury
70
70
  requirement: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - '>='
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  type: :development
76
76
  prerelease: false
77
77
  version_requirements: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - '>='
79
+ - - ">="
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: rake
84
84
  requirement: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - '>='
86
+ - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  type: :development
90
90
  prerelease: false
91
91
  version_requirements: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - '>='
93
+ - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  - !ruby/object:Gem::Dependency
97
97
  name: rspec
98
98
  requirement: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - '>='
100
+ - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  type: :development
104
104
  prerelease: false
105
105
  version_requirements: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - '>='
107
+ - - ">="
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  - !ruby/object:Gem::Dependency
111
111
  name: sqlite3
112
112
  requirement: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - '>='
114
+ - - ">="
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  type: :development
118
118
  prerelease: false
119
119
  version_requirements: !ruby/object:Gem::Requirement
120
120
  requirements:
121
- - - '>='
121
+ - - ">="
122
122
  - !ruby/object:Gem::Version
123
123
  version: '0'
124
124
  description: Helpers for enum-like fields
@@ -127,23 +127,24 @@ email:
127
127
  - alex.robbin@meyouhealth.com
128
128
  - adam@aprescott.com
129
129
  - mdaubert@gmail.com
130
- - chad@dresslerfamily.com
131
130
  - sean.santry@meyouhealth.com
131
+ - alex@robbinsweb.biz
132
+ - chad@dresslerfamily.com
132
133
  - adam.prescott@meyouhealth.com
134
+ - david.larrabee@meyouhealth.com
133
135
  - sean@seansantry.com
134
- - jon.zeppieri@meyouhealth.com
135
- - alex@robbinsweb.biz
136
136
  - dgoldhirsch@yahoo.com
137
- - david.larrabee@meyouhealth.com
138
137
  - guillermo@gguerini.com
139
138
  - mdaubert+github@gmail.com
139
+ - jon.zeppieri@meyouhealth.com
140
140
  executables: []
141
141
  extensions: []
142
142
  extra_rdoc_files: []
143
143
  files:
144
- - .gitignore
145
- - .travis.yml
144
+ - ".gitignore"
145
+ - ".travis.yml"
146
146
  - Appraisals
147
+ - CHANGELOG.md
147
148
  - CONTRIBUTING.md
148
149
  - Gemfile
149
150
  - LICENSE.txt
@@ -156,8 +157,8 @@ files:
156
157
  - lib/flexible_enum/abstract_configurator.rb
157
158
  - lib/flexible_enum/configuration.rb
158
159
  - lib/flexible_enum/constant_configurator.rb
160
+ - lib/flexible_enum/identity_configurator.rb
159
161
  - lib/flexible_enum/mixin.rb
160
- - lib/flexible_enum/name_configurator.rb
161
162
  - lib/flexible_enum/potential_values_configurator.rb
162
163
  - lib/flexible_enum/question_method_configurator.rb
163
164
  - lib/flexible_enum/scope_configurator.rb
@@ -166,8 +167,8 @@ files:
166
167
  - spec/constant_definition_spec.rb
167
168
  - spec/custom_options_spec.rb
168
169
  - spec/enum_introspection_spec.rb
170
+ - spec/identity_values_spec.rb
169
171
  - spec/inheritance_spec.rb
170
- - spec/name_values_spec.rb
171
172
  - spec/potential_values_spec.rb
172
173
  - spec/predicate_methods_spec.rb
173
174
  - spec/scopes_spec.rb
@@ -183,17 +184,17 @@ require_paths:
183
184
  - lib
184
185
  required_ruby_version: !ruby/object:Gem::Requirement
185
186
  requirements:
186
- - - '>='
187
+ - - ">="
187
188
  - !ruby/object:Gem::Version
188
189
  version: '0'
189
190
  required_rubygems_version: !ruby/object:Gem::Requirement
190
191
  requirements:
191
- - - '>='
192
+ - - ">="
192
193
  - !ruby/object:Gem::Version
193
194
  version: '0'
194
195
  requirements: []
195
196
  rubyforge_project:
196
- rubygems_version: 2.0.14
197
+ rubygems_version: 2.4.5
197
198
  signing_key:
198
199
  specification_version: 4
199
200
  summary: Helpers for enum-like fields
@@ -201,8 +202,8 @@ test_files:
201
202
  - spec/constant_definition_spec.rb
202
203
  - spec/custom_options_spec.rb
203
204
  - spec/enum_introspection_spec.rb
205
+ - spec/identity_values_spec.rb
204
206
  - spec/inheritance_spec.rb
205
- - spec/name_values_spec.rb
206
207
  - spec/potential_values_spec.rb
207
208
  - spec/predicate_methods_spec.rb
208
209
  - spec/scopes_spec.rb