mongoid-sex 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/README.md ADDED
@@ -0,0 +1 @@
1
+ README
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ require 'mongoid'
2
+
3
+ require 'mongoid-sex/value'
4
+ require 'mongoid-sex/mongoid-sex'
5
+ require 'mongoid-sex/version'
@@ -0,0 +1,30 @@
1
+
2
+ require 'mongoid'
3
+
4
+ module Mongoid
5
+ module Sex
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ field :male_boolean, type: Boolean
10
+ end
11
+
12
+ def sex
13
+ Value.new(male_boolean) if !male_boolean.nil?
14
+ end
15
+
16
+ def sex=(value)
17
+ case value.to_s.chars.first.downcase
18
+ when 'm'
19
+ write_attribute :male_boolean, true
20
+ when 'f'
21
+ write_attribute :male_boolean, false
22
+ else
23
+ raise 'Not a supported value for sex'
24
+ end
25
+ rescue
26
+ raise 'Not a supported value for sex'
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,49 @@
1
+
2
+ require 'i18n'
3
+
4
+ module Mongoid
5
+ module Sex
6
+ class Value
7
+
8
+ def initialize(value)
9
+ @male = value
10
+ end
11
+
12
+ def male?
13
+ @male
14
+ end
15
+
16
+ def female?
17
+ !@male
18
+ end
19
+
20
+ def text
21
+ if male?
22
+ I18n.t 'sex.male', default: 'male'
23
+ else
24
+ I18n.t 'sex.female', default: 'female'
25
+ end
26
+ end
27
+ alias :to_s :text
28
+
29
+ def hisher
30
+ if male?
31
+ I18n.t 'sex.his', default: 'his'
32
+ else
33
+ I18n.t 'sex.her', default: 'her'
34
+ end
35
+ end
36
+ alias :his_her :hisher
37
+
38
+ def heshe
39
+ if male?
40
+ I18n.t 'sex.he', default: 'he'
41
+ else
42
+ I18n.t 'sex.she', default: 'she'
43
+ end
44
+ end
45
+ alias :he_she :heshe
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module Mongoid
3
+ module Sex
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "mongoid-sex/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "mongoid-sex"
7
+ s.version = Mongoid::Sex::VERSION
8
+ s.authors = ["ryanlower"]
9
+ s.email = ["rpjlower@gmail.com"]
10
+ s.homepage = "https://github.com/ryanlower/mongoid-sex"
11
+ s.summary = "Adds sex field (with helpers) to a mongoid model"
12
+ s.description = "Adds sex field (with helpers) to a mongoid model"
13
+
14
+ s.rubyforge_project = "mongoid-sex"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_dependency('mongoid', '~> 2.0')
20
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid-sex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - ryanlower
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-12 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mongoid
16
+ requirement: &70175815753440 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70175815753440
25
+ description: Adds sex field (with helpers) to a mongoid model
26
+ email:
27
+ - rpjlower@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.md
35
+ - Rakefile
36
+ - lib/mongoid-sex.rb
37
+ - lib/mongoid-sex/mongoid-sex.rb
38
+ - lib/mongoid-sex/value.rb
39
+ - lib/mongoid-sex/version.rb
40
+ - mongoid-sex.gemspec
41
+ homepage: https://github.com/ryanlower/mongoid-sex
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project: mongoid-sex
61
+ rubygems_version: 1.8.6
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Adds sex field (with helpers) to a mongoid model
65
+ test_files: []