Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

better macros

  • Loading branch information...
commit 636c4168174988ce3ee35903f5cc76c15cc92f46 1 parent 3c46bc5
@kristianmandrup authored
Showing with 20 additions and 13 deletions.
  1. +5 −5 lib/classy_enum/macros.rb
  2. +15 −8 spec/classy_enum/macros_spec.rb
View
10 lib/classy_enum/macros.rb
@@ -1,6 +1,6 @@
def enum name, parent_class = nil, &block
clazz_name = name.to_s.camelize
- if parent_class != :no_context
+ if parent_class != :none
context = self.inspect == 'main' ? Object : self
parent_class ||= context unless context == Object
else
@@ -53,11 +53,11 @@ def enum name, parent_class = nil, &block
end
def enums *names
- names.each {|name| enum name }
+ names.flatten.compact.each {|name| enum name }
end
-def enum_for name, list, options = {}
- enum name, options[:parent] do
- enums *list.flatten.compact
+def enum_for name, list
+ enum name, :none do
+ enums list
end
end
View
23 spec/classy_enum/macros_spec.rb
@@ -4,14 +4,14 @@
describe 'ClassyEnum macros: #enum and #enums' do
before :all do
- enum :number, :no_context do
+ enum :number, :none do
enum :one do
def send_email?
true
end
end
- enums :two, :three
+ enums %w{two three}
end
end
@@ -41,9 +41,18 @@ def send_email?
end
end
-describe 'ClassyEnum macros: #enum and #enums' do
+describe 'ClassyEnum macros: #enum_for' do
before :all do
- enum_for :color, [:red, :blue], parent: :no_context
+ enum_for :color, [:red, :blue]
+
+ enum_for :state, %w{start done}
+ end
+
+ context 'state' do
+ describe 'state: start' do
+ subject { State.build(:start) }
+ it { should be_a(::State::Start) }
+ end
end
context '.build' do
@@ -59,10 +68,8 @@ def send_email?
end
context 'symbol option' do
- describe 'two' do
- subject { Color.build(:blue) }
- it { should be_a(::Color::Blue) }
- end
+ subject { Color.build(:blue) }
+ it { should be_a(::Color::Blue) }
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.