Skip to content
Manage custom fields to a mongoid document or a collection
Ruby
Find file
Failed to load latest commit information.
config/locales use the time zone appropriately when dealing with date time
lib default value option for string, text, email, integer, float, boolean…
spec default value option for string, text, email, integer, float, boolean…
.gitignore [✔] Fixed `.gitignore`.
.rspec [➠] Upgrade RSpec (WIP).
.simplecov [➠] Updated `simplecov`.
.travis.yml [Travis] Bundler that comes with Ruby 2.1 is too old
Gemfile upgrade gems
Gemfile.lock upgrade gems
LICENSE [➠] Updated README.
README.md bump version to 2.5.0 + update README
Rakefile
TODO order select options + correct the namespace of the locales + fix a m…
custom_fields.gemspec upgrade gems

README.md

CustomFields

Travis CI Status Gemnasium Status

Manage custom fields to a Mongoid document or a collection. This module is one of the core features we implemented in our custom CMS, named LocomotiveCMS. Basically, its aim is to provide to editors a way to manage extra fields to a Mongoid document through, for instance, a web UI.

The main goals:

  • Offering a very secure way to add, edit and delete extra fields to a Mongoid document.
  • Scoping the modifications added to a Mongoid document, so that other documents of the same class won't be updated.

Requirements

  • MongoDB 3.x
  • Mongoid 5.x
  • ActiveSupport 4.2.x

Examples

On a has_many relationship

class Company
  include CustomFields::Source

  has_many :employees

  custom_fields_for :employees
end

class Employee
  include CustomFields::Target

  field :name, String

  belongs_to :company, inverse_of: :employees
end

company = Company.new
company.employees_custom_fields.build label: 'His/her position', name: 'position', type: 'string', required: true

company.save

company.employees.build name: 'Michael Scott', position: 'Regional manager'

another_company = Company.new
employee = another_company.employees.build
employee.position # Returns a `not defined method` error

On the class itself

IN PROGRESS

class Company
  custom_fields_for_itself
end

company = Company.new
company.self_metadata_custom_fields.build label: 'Shipping Address', name: 'address', type: 'text'

company.save

company.self_metadata.address = '700 S Laflin, 60607 Chicago'

another_company = Company.new
other_company.self_metadata.address # Returns a `not defined method` error

Development

Run specs

Run rspec or rake.

Test Coverage

Run COVERAGE=true rspec or COVERAGE=true rake.

Contact

Feel free to contact me at did at locomotivecms dot com.

License

Copyright (c) 2013-2016 NoCoffee, released under the MIT License (MIT), see LICENSE.

Something went wrong with that request. Please try again.