maintain 0.2.20 → 0.2.21

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ 0.2.21
2
+ * Added Enumerable support to bitmask values, so now you can parse
3
+ through flags with each, select, map, find, and more! This also
4
+ means `to_a` is now a method on @object.maintained_attribute.
5
+
1
6
  0.2.20
2
7
  * Removed accidental debugging `puts` calls from ActiveRecord backend
3
8
 
@@ -9,4 +14,4 @@
9
14
  usable state names
10
15
 
11
16
  0.2.18
12
- * Ruby 1.9.2 and Rails 3.1 compatibility updates (no API changes)
17
+ * Ruby 1.9.2 and Rails 3.1 compatibility updates (no API changes)
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ begin
17
17
  t.rcov_opts = ['--exclude', 'spec,gem']
18
18
  end
19
19
  rescue LoadError
20
- # puts "Could not load Rspec. To run tests, use `gem install rspec`"
20
+ puts "Could not load Rspec. To run tests, use `gem install rspec`"
21
21
  end
22
22
 
23
23
  begin
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.20
1
+ 0.2.21
data/autotest/discover.rb CHANGED
@@ -2,3 +2,4 @@ require 'autotest/fsevent'
2
2
  require 'autotest/growl'
3
3
 
4
4
  Autotest.add_discovery { "rspec2" }
5
+
@@ -1,6 +1,16 @@
1
1
  # encoding: UTF-8
2
2
  module Maintain
3
3
  class BitmaskValue < Value
4
+ include Enumerable
5
+
6
+ def to_a
7
+ @state.states.select {|key, options| options[:value] & @value > 0}.map(&:first)
8
+ end
9
+
10
+ def each(&block)
11
+ to_a.each {|state| yield state }
12
+ end
13
+
4
14
  def initialize(state, value = nil)
5
15
  @state = state
6
16
  @value = value
@@ -46,4 +56,4 @@ module Maintain
46
56
  end
47
57
  end
48
58
  end
49
- end
59
+ end
data/spec/bitwise_spec.rb CHANGED
@@ -64,6 +64,14 @@ describe Maintain do
64
64
  maintainer.permissions.foobar?
65
65
  }.should raise_error(NoMethodError)
66
66
  end
67
+
68
+ it "should be enumerable" do
69
+ maintainer = MaintainTest.new
70
+ maintainer.permissions = %w(edit update)
71
+ maintainer.permissions.to_a.should == %w(edit update).map(&:to_sym)
72
+ maintainer.permissions.should respond_to(:each)
73
+ maintainer.permissions.select {|permission| permission == :edit}.should == [:edit]
74
+ end
67
75
  end
68
76
 
69
77
  describe "setter methods" do
@@ -95,4 +103,4 @@ describe Maintain do
95
103
  end
96
104
  end
97
105
  end
98
- end
106
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maintain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.20
4
+ version: 0.2.21
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-02 00:00:00.000000000Z
12
+ date: 2011-12-20 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! "\n Maintain is a simple state machine mixin for Ruby objects.
15
15
  It supports comparisons, bitmasks,\n and hooks that really work. It can be