mongodb - mongoid configuration on ruby without framework -
i try write business logic of application. ruby classes. there no database or no ui framework rails, sinatra. have gem_file on business logic and, gem_file contain "mini_test" gem. use mini_test testing business logic. now, need add database system. how can this? mongoid configuration made in application.file on rails. ,i don't use rails or other framework. there anyway make configuration of mongoid without framework rails, sinatra. hope can explain problem. also, add codes in below:
this context-
class headteacherdefineacademicyearcontext attr_reader :person, :academicyear def initialize(person, academicyear) @person, @academicyear = person, academicyear @person.extend headteacher end def call @person.define_academic_year @academicyear end end
this role module
module headteacher def define_academic_year(academicyear) #i write db save process here using database end end
my model class
class academicyear attr_accessor :year end
you have include gem 'mongoid'
in gemfile , install it. after that, can require , initialize mongoid need it:
require 'mongoid' mongoid.load!("mongoid.yml", :development)
it expects mongoid.yml
file configuration. examlpe:
development: sessions: default: database: myapp_development hosts: - localhost:27017
of course, can use context :development
, maybe assign via environment variable. now, add mongoid::document
model:
class academicyear include mongoid::document field :year, type: integer end
Comments
Post a Comment