enumlogic 1.0.3 → 1.0.4

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YWUxNDcwYzJkNmVjYmI0YWZkYjg2NDhjZGE1ZTU5MGZjZjU5OTA5MQ==
5
+ data.tar.gz: !binary |-
6
+ MjViMmM3MDFmOTgyZDc0ZmViNjE4YWJiNzk4ZjNiMDAwMzM0MDRjZA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZGQ3MTIyYTQxMTQxODkxNGUyNGM5YWEwODNkZWVlMWRmMDMyOWM0OTk5OTJk
10
+ YWFiZDFjMmMyNTY0OTAwMjk4Y2I5MTFiOGI1MjczMmQyZWIwNDkxMTkxZjMw
11
+ YThjNWNhZDI5ZWMyOGY4YTM4OTZmOTQ3NDliYTUyYzYzOTMxODE=
12
+ data.tar.gz: !binary |-
13
+ YTZlNWY1Y2E2NWEwZGM1MTg4NTg4ZWIxNzhkMTU0MGUwZWUxMGRiNDI5MmU2
14
+ MTIwZjRiZjc5YjI2YTZiNDc5NzBjYTAyNWFlZWM5MjFmYjIzOWJlODEwODAy
15
+ YjZjYjEyYTZmMWYyOGJjNGQ3ZTY4NDAxNzNlMWY4N2M3ZDUzMGQ=
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ enumlogic (1.0.4)
5
+ activesupport (>= 2.3.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activemodel (3.2.13)
11
+ activesupport (= 3.2.13)
12
+ builder (~> 3.0.0)
13
+ activerecord (3.2.13)
14
+ activemodel (= 3.2.13)
15
+ activesupport (= 3.2.13)
16
+ arel (~> 3.0.2)
17
+ tzinfo (~> 0.3.29)
18
+ activesupport (3.2.13)
19
+ i18n (= 0.6.1)
20
+ multi_json (~> 1.0)
21
+ arel (3.0.2)
22
+ builder (3.0.4)
23
+ i18n (0.6.1)
24
+ multi_json (1.7.1)
25
+ rake (10.0.3)
26
+ rspec (1.3.2)
27
+ sqlite3 (1.3.7)
28
+ tzinfo (0.3.37)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ activerecord
35
+ enumlogic!
36
+ rake
37
+ rspec (~> 1)
38
+ sqlite3
data/Rakefile CHANGED
@@ -1,23 +1,7 @@
1
1
  require 'rubygems'
2
- require 'rake'
2
+ require 'bundler'
3
3
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "enumlogic"
8
- gem.summary = "Adds enumerations to your models"
9
- gem.description = "Adds enumerations to your models"
10
- gem.email = "bjohnson@binarylogic.com"
11
- gem.homepage = "http://github.com/binarylogic/enumlogic"
12
- gem.authors = ["binarylogic"]
13
- gem.rubyforge_project = "enumlogic"
14
- gem.add_development_dependency "rspec"
15
- end
16
- Jeweler::GemcutterTasks.new
17
- Jeweler::RubyforgeTasks.new
18
- rescue LoadError
19
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
- end
4
+ Bundler.setup
21
5
 
22
6
  require 'spec/rake/spectask'
23
7
  Spec::Rake::SpecTask.new(:spec) do |spec|
@@ -25,12 +9,17 @@ Spec::Rake::SpecTask.new(:spec) do |spec|
25
9
  spec.spec_files = FileList['spec/**/*_spec.rb']
26
10
  end
27
11
 
28
- Spec::Rake::SpecTask.new(:rcov) do |spec|
29
- spec.libs << 'lib' << 'spec'
30
- spec.pattern = 'spec/**/*_spec.rb'
31
- spec.rcov = true
12
+ begin
13
+ require 'rcov/rcovtask'
14
+ Rcov::RcovTask.new do |test|
15
+ test.libs << 'test'
16
+ test.pattern = 'test/**/*_test.rb'
17
+ test.verbose = true
18
+ end
19
+ rescue LoadError
20
+ task :rcov do
21
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
22
+ end
32
23
  end
33
24
 
34
- task :spec => :check_dependencies
35
-
36
- task :default => :spec
25
+ task :default => :test
data/enumlogic.gemspec CHANGED
@@ -1,58 +1,24 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
5
3
 
6
4
  Gem::Specification.new do |s|
7
- s.name = %q{enumlogic}
8
- s.version = "1.0.3"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["binarylogic"]
12
- s.date = %q{2009-11-18}
5
+ s.name = "enumlogic"
6
+ s.version = "1.0.4"
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Ben Johnson"]
9
+ s.email = ["bjohnson@binarylogic.com"]
10
+ s.homepage = "http://github.com/binarylogic/enumlogic"
11
+ s.summary = %q{Adds enumerations to your models}
13
12
  s.description = %q{Adds enumerations to your models}
14
- s.email = %q{bjohnson@binarylogic.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "CHANGELOG.rdoc",
23
- "LICENSE",
24
- "README.rdoc",
25
- "Rakefile",
26
- "VERSION.yml",
27
- "enumlogic.gemspec",
28
- "init.rb",
29
- "lib/enumlogic.rb",
30
- "rails/init.rb",
31
- "spec/enumlogic_spec.rb",
32
- "spec/spec_helper.rb"
33
- ]
34
- s.homepage = %q{http://github.com/binarylogic/enumlogic}
35
- s.rdoc_options = ["--charset=UTF-8"]
36
- s.require_paths = ["lib"]
37
- s.rubyforge_project = %q{enumlogic}
38
- s.rubygems_version = %q{1.3.5}
39
- s.summary = %q{Adds enumerations to your models}
40
- s.test_files = [
41
- "spec/enumlogic_spec.rb",
42
- "spec/spec_helper.rb"
43
- ]
44
13
 
45
- if s.respond_to? :specification_version then
46
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
- s.specification_version = 3
48
-
49
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
- s.add_development_dependency(%q<rspec>, [">= 0"])
51
- else
52
- s.add_dependency(%q<rspec>, [">= 0"])
53
- end
54
- else
55
- s.add_dependency(%q<rspec>, [">= 0"])
56
- end
57
- end
14
+ s.add_dependency 'activesupport', '>= 2.3.0'
15
+ s.add_development_dependency 'activerecord'
16
+ s.add_development_dependency 'rake'
17
+ s.add_development_dependency 'rspec', '~> 1'
18
+ s.add_development_dependency 'sqlite3'
58
19
 
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+ end
data/lib/enumlogic.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "activerecord"
1
+ require "active_record"
2
2
 
3
3
  # See the enum class level method for more info.
4
4
  module Enumlogic
@@ -14,7 +14,7 @@ module Enumlogic
14
14
  # Computer::KINDS # passes back the defined enum keys as array
15
15
  # Computer.kind_options # gives you a friendly hash that you can easily pass into the select helper for forms
16
16
  # Computer.new(:kind => "unknown").valid? # false, automatically validates inclusion of the enum field
17
- #
17
+ #
18
18
  # c = Computer.new(:kind => "apple")
19
19
  # c.apple? # true
20
20
  # c.kind_key # :apple
@@ -28,30 +28,30 @@ module Enumlogic
28
28
  else
29
29
  values
30
30
  end
31
-
31
+
32
32
  values_array = values.is_a?(Hash) ? values.keys : values
33
-
33
+
34
34
  constant_name = options[:constant] || field.to_s.pluralize.upcase
35
35
  const_set constant_name, values_array unless const_defined?(constant_name)
36
-
36
+
37
37
  new_hash = {}
38
38
  values_hash.each { |key, text| new_hash[text] = key }
39
39
  (class << self; self; end).send(:define_method, "#{field}_options") { new_hash }
40
-
40
+
41
41
  define_method("#{field}_key") do
42
42
  value = send(field)
43
43
  return nil if value.nil?
44
44
  value.to_s.gsub(/[-\s]/, '_').downcase.to_sym
45
45
  end
46
-
46
+
47
47
  define_method("#{field}_text") do
48
48
  value = send(field)
49
49
  return nil if value.nil?
50
50
  values_hash[value]
51
51
  end
52
-
52
+
53
53
  values_array.each do |value|
54
- method_name = value.downcase.gsub(/[-\s]/, '_')
54
+ method_name = value.underscore.gsub(/[-\s]/, '_')
55
55
  method_name = "#{method_name}_#{field}" if options[:namespace]
56
56
  define_method("#{method_name}?") do
57
57
  self.send(field) == value
@@ -64,4 +64,6 @@ module Enumlogic
64
64
  def enum?(name)
65
65
  method_defined?("#{name}_key")
66
66
  end
67
- end
67
+ end
68
+
69
+ ActiveRecord::Base.extend(Enumlogic)
@@ -5,45 +5,45 @@ describe "Enumlogic" do
5
5
  Computer.enum :kind, ["apple", "dell", "hp"], :namespace => true
6
6
  Computer::KINDS.should == ["apple", "dell", "hp"]
7
7
  end
8
-
8
+
9
9
  it "constant should always return an array" do
10
10
  hash = ActiveSupport::OrderedHash.new
11
11
  hash["apple"] = "Apple"
12
12
  hash["dell"] = "Dell"
13
13
  hash["hp"] = "HP"
14
-
14
+
15
15
  Computer.enum :kind, hash, :namespace => true
16
16
  Computer::KINDS.should == ["apple", "dell", "hp"]
17
17
  end
18
-
18
+
19
19
  it "should create a class level options method" do
20
20
  Computer.enum :kind, ["apple", "dell", "hp"]
21
21
  Computer.kind_options.should == {"apple" => "apple", "dell" => "dell", "hp" => "hp"}
22
22
  end
23
-
23
+
24
24
  it "should create a class level options method for hashes" do
25
25
  Computer.enum :kind, {"apple" => "Apple", "dell" => "Dell", "hp" => "HP"}
26
26
  Computer.kind_options.should == {"Apple" => "apple", "Dell" => "dell", "HP" => "hp"}
27
27
  end
28
-
28
+
29
29
  it "should create key methods" do
30
30
  Computer.enum :kind, ["apple", "dell", "hp"]
31
31
  c = Computer.new(:kind => "apple")
32
32
  c.kind_key.should == :apple
33
33
  end
34
-
34
+
35
35
  it "should create key methods for hashes" do
36
36
  Computer.enum :kind, {"apple" => "Apple", "dell" => "Dell", "hp" => "HP"}
37
37
  c = Computer.new(:kind => "apple")
38
38
  c.kind_key.should == :apple
39
39
  end
40
-
40
+
41
41
  it "should create text methods" do
42
42
  Computer.enum :kind, {"apple" => "Apple", "dell" => "Dell", "hp" => "HP"}
43
43
  c = Computer.new(:kind => "hp")
44
44
  c.kind_text.should == "HP"
45
45
  end
46
-
46
+
47
47
  it "should create text methods for hashes" do
48
48
  Computer.enum :kind, {"apple" => "Apple", "dell" => "Dell", "hp" => "HP"}
49
49
  c = Computer.new(:kind => "hp")
@@ -55,19 +55,21 @@ describe "Enumlogic" do
55
55
  c = Computer.new :kind => 'ibm'
56
56
  c.kind_text.should == nil
57
57
  end
58
-
58
+
59
59
  it "should create boolean methods" do
60
- Computer.enum :kind, ["apple", "dell", "hp"]
60
+ Computer.enum :kind, ["apple", "dell", "hp", "HelloThere"]
61
61
  c = Computer.new(:kind => "apple")
62
62
  c.should be_apple
63
+ c = Computer.new(:kind => "HelloThere")
64
+ c.should be_hello_there
63
65
  end
64
-
66
+
65
67
  it "should namespace boolean methods" do
66
68
  Computer.enum :kind, ["apple", "dell", "hp"], :namespace => true
67
69
  c = Computer.new(:kind => "apple")
68
70
  c.should be_apple_kind
69
71
  end
70
-
72
+
71
73
  it "should validate inclusion" do
72
74
  Computer.enum :kind, ["apple", "dell", "hp"]
73
75
  c = Computer.new
@@ -75,32 +77,32 @@ describe "Enumlogic" do
75
77
  c.should_not be_valid
76
78
  c.errors[:kind].should include("is not included in the list")
77
79
  end
78
-
80
+
79
81
  it "should allow nil during validations" do
80
82
  Computer.enum :kind, ["apple", "dell", "hp"], :allow_nil => true
81
83
  c = Computer.new
82
84
  c.should be_valid
83
85
  end
84
-
86
+
85
87
  it "should implement the if option during validation" do
86
88
  Computer.enum :kind, ["apple", "dell", "hp"], :if => :return_false
87
89
  c = Computer.new
88
90
  c.should be_valid
89
91
  end
90
-
92
+
91
93
  it "should be included in the list" do
92
94
  Computer.enum :kind, ["apple", "dell", "hp", "custom made"]
93
95
  c = Computer.new(:kind => "custom made")
94
96
  c.should be_valid
95
97
  end
96
-
98
+
97
99
  it "should find a defined enum" do
98
100
  Computer.enum :kind, ["apple", "dell", "hp"]
99
-
101
+
100
102
  Computer.enum?(:kind).should == true
101
103
  Computer.enum?(:some_other_field).should == false
102
104
  end
103
-
105
+
104
106
  it "should check for defined enums if there isn't any" do
105
107
  Computer.enum?(:kind).should == false
106
108
  end
data/spec/spec_helper.rb CHANGED
@@ -4,7 +4,7 @@ require 'spec'
4
4
  require 'spec/autorun'
5
5
  require 'rubygems'
6
6
  require 'active_record'
7
- require "#{File.dirname(__FILE__)}/../init"
7
+ require 'enumlogic'
8
8
 
9
9
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
10
10
  ActiveRecord::Base.configurations = true
@@ -25,7 +25,7 @@ Spec::Runner.configure do |config|
25
25
  end
26
26
  end
27
27
  end
28
-
28
+
29
29
  config.after(:each) do
30
30
  Object.send(:remove_const, :Computer)
31
31
  end
metadata CHANGED
@@ -1,78 +1,126 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: enumlogic
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
5
  platform: ruby
6
- authors:
7
- - binarylogic
6
+ authors:
7
+ - Ben Johnson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2009-11-18 00:00:00 -05:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
11
+ date: 2013-03-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
16
56
  name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
17
76
  type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
25
83
  description: Adds enumerations to your models
26
- email: bjohnson@binarylogic.com
84
+ email:
85
+ - bjohnson@binarylogic.com
27
86
  executables: []
28
-
29
87
  extensions: []
30
-
31
- extra_rdoc_files:
32
- - LICENSE
33
- - README.rdoc
34
- files:
35
- - .document
88
+ extra_rdoc_files: []
89
+ files:
36
90
  - .gitignore
37
91
  - CHANGELOG.rdoc
92
+ - Gemfile
93
+ - Gemfile.lock
38
94
  - LICENSE
39
95
  - README.rdoc
40
96
  - Rakefile
41
- - VERSION.yml
42
97
  - enumlogic.gemspec
43
- - init.rb
44
98
  - lib/enumlogic.rb
45
- - rails/init.rb
46
99
  - spec/enumlogic_spec.rb
47
100
  - spec/spec_helper.rb
48
- has_rdoc: true
49
101
  homepage: http://github.com/binarylogic/enumlogic
50
102
  licenses: []
51
-
103
+ metadata: {}
52
104
  post_install_message:
53
- rdoc_options:
54
- - --charset=UTF-8
55
- require_paths:
105
+ rdoc_options: []
106
+ require_paths:
56
107
  - lib
57
- required_ruby_version: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: "0"
62
- version:
63
- required_rubygems_version: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: "0"
68
- version:
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
69
118
  requirements: []
70
-
71
- rubyforge_project: enumlogic
72
- rubygems_version: 1.3.5
119
+ rubyforge_project:
120
+ rubygems_version: 2.0.3
73
121
  signing_key:
74
- specification_version: 3
122
+ specification_version: 4
75
123
  summary: Adds enumerations to your models
76
- test_files:
124
+ test_files:
77
125
  - spec/enumlogic_spec.rb
78
126
  - spec/spec_helper.rb
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/VERSION.yml DELETED
@@ -1,5 +0,0 @@
1
- ---
2
- :minor: 0
3
- :patch: 3
4
- :major: 1
5
- :build:
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require File.dirname(__FILE__) + "/rails/init.rb"
data/rails/init.rb DELETED
@@ -1,3 +0,0 @@
1
- require 'enumlogic'
2
-
3
- ActiveRecord::Base.extend(Enumlogic)