Code Monkey home page Code Monkey logo

mongoid-enum's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mongoid-enum's Issues

Change in criteria prefixing

I've just updated to mongoid5 and mongoid-enum 0.4, and noticed a change in how criteria is built.

In emongoid-enum 0.2 Model.where(enum_name: :value) would translate to the mongo query for {_enum_name: "value"} that is, it added the field prefix to the query. That doesn't seem to be working anymore.

Is this the expected behaviour?

Mongoid 7.0 and 7.2 support

Help !!!

base) ➜  raceday git:(master) ✗ bundle
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Bundler could not find compatible versions for gem "mongoid":
  In snapshot (Gemfile.lock):
    mongoid (= 7.0.2)

  In Gemfile:
    mongoid (~> 7.0, >= 7.0.2)

    mongoid_enum was resolved to 1.1.0, which depends on
      mongoid (~> 5.0)

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

Transfer mongoid-enum to github.com/mongoid?

I had https://github.com/mongoid kindly donated to the community by the nice folks at MongoDB. The three people who have org level admin access are currently @durran, @estolfo and myself.

I want to invite this project to be moved to the org. I think it makes good sense to group mongoid projects together and have continuous support from MongoDB, the company, over the long term. All admins of this project will continue having admin access of course, but this would reduce the bus factor since currently only @thetron can add maintainers here.

If you think it's a good idea, please transfer this project to me and I'll move it into the org and please add [email protected], [email protected] and [email protected] to rubygems.

Underscore in Enum field name while creating an index

What is the correct syntax for creating an index on an enum field?
I've already created an enum named action like this.
enum :action, Enum::Task::ACTION, default: :something

I wanted to know if the correct syntax is index _action: 1 or index action: 1.

How can resolve this problem

I have error

SyntaxError (/home/silver/ProRails/triip/app/models/lapor.rb:12: syntax error, unexpected tCONSTANT, expecting ']'
...tan, :Pelanggaran, :Lampu Jalan Rusak, :Sampah, :Jalan,
SyntaxError (/home/silver/ProRails/triip/app/models/lapor.rb:12: syntax error, unexpected tCONSTANT, expecting ']'
...tan, :Pelanggaran, :Lampu Jalan Rusak, :Sampah, :Jalan,

Here source code Model :


  enum :category, [:Kemacetan, :Pelanggaran, :Lampu Jalan Rusak, :Sampah, :Jalan,
                  :Fasilitas, :Parkir, :Pengemis, :Kaki, :Kriminal,
                  :Banjir,:Pohon,:Kebakaran,:Pajak,:PelanggaranIzinBangunan,
                  :PotensiTeroris,:LansiaHilang,

search translation in superclass if it's not in subclass.

When i have a inherited model and a enum in the superclass, I need to repeat the translation. E.g

class Employee
 enum :foo,  [:bar, :baz, :zaz]

class Manager < Employee

and in translation .yml file I need to have

enums:
  employee:
    foo:
      bar: BAR
      baz: BAZ
      zaz: ZAZ

  employees/manager:
    foo:
      bar: BAR
      baz: BAZ
      zaz: ZAZ

So if I don't have the employees/manager defined, its should search in the employee

No support for explicitly mapped values

I get an error when trying to map enum values explicitly (as can be done with ActiveRecord::Enum).

For example:

# see https://en.wikipedia.org/wiki/ISO/IEC_5218
enum :sex, {
  unknown: 0,
  male: 1,
  female: 2,
  not_applicable: 9
}

The error is in create_validations:

undefined method `to_sym' for [:unknown, 0]:Array

Mongoid 5.0 support

I've just realized new mongoid 5.0.0 showed up. Do you plan for next version support?

P.S. Thanks for the great gem.

Symbol type is deprecated

The "symbol" type is deprecated in BSON and in Mongo 3.2.
https://docs.mongodb.com/manual/reference/bson-types/

I believe mongoid-enum should be updated to use Strings instead of Symbols for storing the enum value to reduce future data migrations when Symbol is finally removed as a supported type.

Alternatively, mongoid-enum could be made to be indifferent as to whether strings or symbols are stored - including in the auto-generated accessor methods.

value can not include dash

I defined enum :lang, [:'zh-TW', :jp]

and I got exception.

.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/mongoid-enum-0.3.0/lib/mongoid/enum.rb:69:in `class_eval': (eval):1: syntax error, unexpected '-', expecting ';' or '\n'
def zh-TW?() self._lang == :zh-TW end
       ^
(eval):1: syntax error, unexpected keyword_self, expecting end-of-input
def zh-TW?() self._lang == :zh-TW end
                 ^ (SyntaxError)

Dependence for mongoid and Rails4

Error msg while running 'bundle install':

Bundler could not find compatible versions for gem "mongoid":
  In Gemfile:
    mongoid-enum (>= 0) ruby depends on
      mongoid (~> 3.1) ruby

    mongoid (4.0.0.alpha2)

Gemfile:

gem 'mongoid', git: 'git://github.com/mongoid/mongoid.git'
gem 'mongoid-enum', git: 'git://github.com/thetron/mongoid-enum.git'

Is there something wrong with the version comparing?

I18n helpers

Way before DHH enum arrived there was a lot of solutions for this and one I took to maintain (AR pain) was Symbolize.

A nice feature I've ported from it is i18n helpers: _text to get the value translated quickly and _values to get all translations (good for drop down).

They are pretty cheap oneliners, but very handy (at least for my apps).
If you would like I'll create a pull request.
https://github.com/nofxx/mongoid-enum/tree/merge

Saving a multiple enum

Hi Thetron,

I just have a simple question, I have an enum with option multiple equal to true. What is the correct way to send the params for autosave?

I mean my form is sending day => [ 'day1', 'day2' ] but the i have error with the validation.

Underscore in field name

What is the reason for using underscore in fieldname?

> Meeting.new.attributes
=> {"_id"=>BSON::ObjectId('549d746563616c2168060000'), "_meeting_quality"=>:hd, "_status"=>:inactive}

Actually we get another attribute that differ one we created

whats the status on this gem?

Just looking through and noticing that there has not been a commit in 2 years, and PRs that seem to have been ignored for some time as well. Does this gem need new maintainers? Is there an alternative people have switched to?

Accessor prefixes

Hi
Are there any plans to support configurable prefixes for the accessors?
Thanks

Scopes can silently override existing methods

In the process of converting a project from using symbolize/mongoid to mongoid-enum, I had a model that declares the following enum:

    # old symbolize/mongoid declaration
    # symbolize :status, in: [:new, :success, :fail], default: :new

    # new mongoid-enum declaration
    enum :status, [:new, :success, :fail]

The enum declaration creates scope methods for the enum values:

MyModel.new # => Mongoid::Criteria
MyModel.success # => Mongoid::Criteria
MyModel.fail # => Mongoid::Criteria

So now mongoid-enum has overridden the new method, which blows up calls to MyModel.create or MyModel.create!.

There are a couple of ways this can be fixed (ideally, both could be implemented).

  1. Add a new option to disable scopes for an enum:

        enum :status, [:new, :success, :fail], :scopes => false
  2. Add a scope method prefix configuration option to avoid namespace collisions (e.g., scope_ or s_ for brevity):

module Mongoid
  module Enum
    class Configuration
      attr_accessor :field_name_prefix
      attr_accessor :scope_method_prefix

      def initialize
        self.field_name_prefix = "_"
        self.scope_method_prefix = "s_"
      end
    end

    def self.configuration
      @configuration ||= Configuration.new
    end

    def self.configure
      yield(configuration) if block_given?
    end
  end
end

Bundler could not find compatible versions for gem "mongoid":

i using mongoid 7
ruby 2.6.1
rails 5.2.2

when i run bundle on my gem i get these error

In snapshot (Gemfile.lock):
mongoid (= 7.0.2)

In Gemfile:
   mongoid-enum was resolved to 0.1.1, which depends on
      mongoid (~> 3.1)

mongoid-paperclip was resolved to 0.0.11, which depends on
  mongoid

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict. 

what shoul d i do

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.