mongoid_enumerable 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9af51c7b47d1e09b22dd640e385adb4af4222417311bc9e03cedf68e783b8a0d
4
+ data.tar.gz: 92869fa82757e9fab2ecc95c4721e1ccac09eeb66df1d302132fec2c61ab3b4c
5
+ SHA512:
6
+ metadata.gz: 4114bf4ea3e50eee951783b9b707fbe5cdcd61fe29c528a0585d77819d61935cd0980e9e63636f91bfd803f0e7250fdbffde7214a79b5f175ef928538125d10a
7
+ data.tar.gz: a03cfd99dbc231ec593d867781221dc067e165991234293cce6cbb122605f10a42c56a9a0177eb4a763d72df9edb247ddf20e3aa48b534a301e2db2c3d83a22b
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,8 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ - 2.4.3
6
+ - 2.3.6
7
+ - 2.2.9
8
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in mongoid_enumerable.gemspec
6
+ gemspec
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mongoid_enumerable (0.1.0)
5
+ mongoid
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (5.2.0)
11
+ activesupport (= 5.2.0)
12
+ activesupport (5.2.0)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 0.7, < 2)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ bson (4.3.0)
18
+ byebug (10.0.2)
19
+ concurrent-ruby (1.0.5)
20
+ diff-lcs (1.3)
21
+ i18n (1.0.1)
22
+ concurrent-ruby (~> 1.0)
23
+ minitest (5.11.3)
24
+ mongo (2.5.3)
25
+ bson (>= 4.3.0, < 5.0.0)
26
+ mongoid (7.0.1)
27
+ activemodel (>= 5.1, < 6.0.0)
28
+ mongo (>= 2.5.1, < 3.0.0)
29
+ rake (10.5.0)
30
+ rspec (3.7.0)
31
+ rspec-core (~> 3.7.0)
32
+ rspec-expectations (~> 3.7.0)
33
+ rspec-mocks (~> 3.7.0)
34
+ rspec-core (3.7.1)
35
+ rspec-support (~> 3.7.0)
36
+ rspec-expectations (3.7.0)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.7.0)
39
+ rspec-mocks (3.7.0)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.7.0)
42
+ rspec-nc (0.3.0)
43
+ rspec (>= 3)
44
+ terminal-notifier (>= 1.4)
45
+ rspec-support (3.7.1)
46
+ terminal-notifier (2.0.0)
47
+ thread_safe (0.3.6)
48
+ tzinfo (1.2.5)
49
+ thread_safe (~> 0.1)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ bundler (~> 1.16)
56
+ byebug
57
+ mongoid
58
+ mongoid_enumerable!
59
+ rake (~> 10.0)
60
+ rspec (~> 3.0)
61
+ rspec-nc
62
+
63
+ BUNDLED WITH
64
+ 1.16.1
@@ -0,0 +1,109 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ guard 'livereload' do
19
+ extensions = {
20
+ css: :css,
21
+ scss: :css,
22
+ sass: :css,
23
+ js: :js,
24
+ coffee: :js,
25
+ html: :html,
26
+ png: :png,
27
+ gif: :gif,
28
+ jpg: :jpg,
29
+ jpeg: :jpeg,
30
+ # less: :less, # uncomment if you want LESS stylesheets done in browser
31
+ }
32
+
33
+ rails_view_exts = %w(erb haml slim)
34
+
35
+ # file types LiveReload may optimize refresh for
36
+ compiled_exts = extensions.values.uniq
37
+ watch(%r{public/.+\.(#{compiled_exts * '|'})})
38
+
39
+ extensions.each do |ext, type|
40
+ watch(%r{
41
+ (?:app|vendor)
42
+ (?:/assets/\w+/(?<path>[^.]+) # path+base without extension
43
+ (?<ext>\.#{ext})) # matching extension (must be first encountered)
44
+ (?:\.\w+|$) # other extensions
45
+ }x) do |m|
46
+ path = m[1]
47
+ "/assets/#{path}.#{type}"
48
+ end
49
+ end
50
+
51
+ # file needing a full reload of the page anyway
52
+ watch(%r{app/views/.+\.(#{rails_view_exts * '|'})$})
53
+ watch(%r{app/helpers/.+\.rb})
54
+ watch(%r{config/locales/.+\.yml})
55
+ end
56
+
57
+ # Note: The cmd option is now required due to the increasing number of ways
58
+ # rspec may be run, below are examples of the most common uses.
59
+ # * bundler: 'bundle exec rspec'
60
+ # * bundler binstubs: 'bin/rspec'
61
+ # * spring: 'bin/rspec' (This will use spring if running and you have
62
+ # installed the spring binstubs per the docs)
63
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
64
+ # * 'just' rspec: 'rspec'
65
+
66
+ guard :rspec, cmd: "bundle exec rspec --format Nc --format documentation" do
67
+ require "guard/rspec/dsl"
68
+ dsl = Guard::RSpec::Dsl.new(self)
69
+
70
+ # Feel free to open issues for suggestions and improvements
71
+
72
+ # RSpec files
73
+ rspec = dsl.rspec
74
+ watch(rspec.spec_helper) { rspec.spec_dir }
75
+ watch(rspec.spec_support) { rspec.spec_dir }
76
+ watch(rspec.spec_files)
77
+
78
+ # Ruby files
79
+ ruby = dsl.ruby
80
+ dsl.watch_spec_files_for(ruby.lib_files)
81
+
82
+ # Rails files
83
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
84
+ dsl.watch_spec_files_for(rails.app_files)
85
+ dsl.watch_spec_files_for(rails.views)
86
+
87
+ watch(rails.controllers) do |m|
88
+ [
89
+ rspec.spec.call("routing/#{m[1]}_routing"),
90
+ rspec.spec.call("controllers/#{m[1]}_controller"),
91
+ rspec.spec.call("acceptance/#{m[1]}")
92
+ ]
93
+ end
94
+
95
+ # Rails config changes
96
+ watch(rails.spec_helper) { rspec.spec_dir }
97
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
98
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
99
+
100
+ # Capybara features specs
101
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
102
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
103
+
104
+ # Turnip features and steps
105
+ watch(%r{^spec/acceptance/(.+)\.feature$})
106
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
107
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
108
+ end
109
+ end
@@ -0,0 +1,52 @@
1
+ # Mongoid Enumerable
2
+
3
+ [![Build Status](https://travis-ci.org/douglaslise/mongoid_enumerable.svg?branch=master)](https://travis-ci.org/douglaslise/mongoid_enumerable)
4
+ [![Gem Version](https://badge.fury.io/rb/mongoid_enumerable.svg)](https://badge.fury.io/rb/mongoid_enumerable)
5
+
6
+ Define custom methods for your MongoId documents:
7
+ ```ruby
8
+ class Task
9
+ include Mongoid::Document
10
+ include MongoidEnumerable
11
+
12
+ enumerable :status, %w(completed running failed waiting), default: "waiting"
13
+ end
14
+ ```
15
+
16
+ Now we have methods in this model:
17
+ ```ruby
18
+ task = Task.new
19
+
20
+ task.status # "waiting"
21
+ task.waiting? # true
22
+
23
+ task.running!
24
+ task.running? # true
25
+ task.waiting? # false
26
+ ```
27
+
28
+ ## Installation
29
+
30
+ Add this line to your application's Gemfile:
31
+
32
+ ```ruby
33
+ gem 'mongoid_enumerable'
34
+ ```
35
+
36
+ And then execute:
37
+
38
+ $ bundle
39
+
40
+ Or install it yourself as:
41
+
42
+ $ gem install mongoid_enumerable
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/douglaslise/mongoid_enumerable.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mongoid_enumerable"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ require "mongoid_enumerable/version"
2
+ require "mongoid"
3
+
4
+ module MongoidEnumerable
5
+ def self.included(base)
6
+ base.class.redefine_method :enumerable do |field_name, values, options = {}|
7
+ field_name = String(field_name)
8
+ values.collect!(&:to_s)
9
+
10
+ prefix = options.fetch(:prefix, "")
11
+ default = options.fetch(:default, values.first)
12
+
13
+ field(field_name, type: String, default: default)
14
+
15
+ values.each do |value|
16
+ method_name = "#{prefix}#{value}"
17
+
18
+ define_method("#{method_name}!") do
19
+ update!(field_name => value)
20
+ end
21
+
22
+ define_method("#{method_name}?") do
23
+ send(field_name) == value
24
+ end
25
+
26
+ base.class.redefine_method(method_name) do
27
+ base.where(field_name => value)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module MongoidEnumerable
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "mongoid_enumerable/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mongoid_enumerable"
8
+ spec.version = MongoidEnumerable::VERSION
9
+ spec.authors = ["Douglas Lise"]
10
+ spec.email = ["douglaslise@gmail.com"]
11
+
12
+ spec.summary = %q{Mongoid Enumerable}
13
+ spec.description = %q{Mongoid Enumerable}
14
+ spec.homepage = "https://github.com/douglaslise/mongoid_enumerable"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.16"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "rspec-nc"
27
+ spec.add_development_dependency "mongoid"
28
+ spec.add_development_dependency "byebug"
29
+ spec.add_dependency "mongoid"
30
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid_enumerable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Douglas Lise
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-nc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mongoid
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mongoid
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Mongoid Enumerable
112
+ email:
113
+ - douglaslise@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - Guardfile
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - lib/mongoid_enumerable.rb
129
+ - lib/mongoid_enumerable/version.rb
130
+ - mongoid_enumerable.gemspec
131
+ homepage: https://github.com/douglaslise/mongoid_enumerable
132
+ licenses: []
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.7.6
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Mongoid Enumerable
154
+ test_files: []