web47core
Core components used commonly among all web apps for both App47 and RedMonocle
We don't need no sticking badges
Requirements
- Ruby 2.4.1
Working with Bundler and RVM
This project manages Ruby versions via RVM and manages dependencies via Bundler.
You must first install RVM. Then install Ruby 2.4.1 (version 2.4.1-p111) via RVM.
rvm install 2.4.1
You'll now notice that this project (as well as other App47 ones) contains a .rvmc file, which is executed upon opening the project's root directory in a terminal (and IDE's like RubyMine). The .rvmc file simply states rvm ruby-2.4.1 which tells RVM to ensure the Ruby version to use for this project is 2.4.1.
Please note, your Ruby 2.4.1 version might need bundler installed:
gem install bundler -v 1.17.3
To set up this project's dependencies, which are defined in the file, Gemfile, you should first run
bundle install --path vendor
The --path vendor simply puts all gem files in a vendor directory.
Development
Your RubyMine environment should be setup now, however to verify all is well, please run the test suite
bundle exec rake test
Deployment
The web47core project is a gem that will be deployed via Ruby Gems. When an update is ready, the following steps should be followed
- Build the gem
gem build web47core.gemspec - Push the new gem to Ruby Gems
gem push web47core-version.gem - There may be a delay when using the gem file
Usage
Importing the gem
To use the app47core gem in a project, first add the gem to your Gemfile in one of two ways
Using the gem from Ruby Gems
gem 'web47core'
If you need the gem immediately or need to pull from development branch, you can use the git repo
gem 'web47core', git: '[email protected]:App47/web47core.git', branch: :master
or from the develop branch
gem 'web47core', git: '[email protected]:App47/web47core.git', branch: :develop
Please do not ship to production code using the git repo, as the production servers will not have keys to pull from the web47core repo
Remove the following files
-
StandardModel- Includes the common set of includes, Mongoid, Auditable, AutoClearCache, etc. -
CdnUrl- Provide CDN URLs of your classes URLs when cdn_url is configured in system configuration -
AutoClearCache- Clears your objects cache out of Rails.cache using the object's id -
Formable- Consolidated into StandardModel, was used to provide common form operations for mongoid documents -
EmailNotification -
EmailTemplate -
Notification -
NotificationTemplate -
SlackNotification -
SmsNotification -
Template -
App47LoggerandApp47LoggerTest -
EmailableorEmailAbleandEamailbleTest, be sure to changeEmailabletoEmailAble -
RedisConfigurationandRedisConfgurationTest -
SearchableandSearchableTest, be sure to changeSearchabletoSearchAble -
TimezoneAbleandTimezoneAbleTest -
CronJobServerandCronJobServerTest -
JobCronTabandJobCronTabTest -
CronTab
Models
Concerns
-
StandardModel- Includes the common set of includes, Mongoid, etc. -
CoreSystemConfiguration- Base system configuration to be included in the app's SystemConfiguration Object -
CoreAccount- Base account object that is related to notifications and the ilk. ##### System Configuration Define aSystemConfigurationclass in your project and import the core concern.
class SystemConfiguration
include StandardModel
include CoreSystemConfiguration
# Include your additional system configuration fields and methods
field :google_sso_client_id, type: String
end
Account
Define a Account class in your project and import the core concern.
class Account
include StandardModel
include CoreAccount
# Include your additional system configuration fields and methods
has_many :users
end
Cron
Cron infrastructure for running jobs every minute, hour, day, week, month or some combination
- Remove
config/initializers/job_cron_tabs.rbthat was previous used to ensure cron tabs, they will be loaded automatically now - Remove the
Delayed::Backend::Mongoid::Jobclass definition, not the settings fromconfig/initializers/delayed_job.rb, these are included in this gem now. - Cron jobs should extend from
Cron::Jobnow and specifycron_tab_entrywithin the class.ruby module Cron class MyJob < Job cron_tab_entry :daily def perform # do your work end end endAllowed values of cron_tab_entry are - :always - run every minute
- :hourly - run every hour
- :daily - run every day
- :weekly - run every week on Sunday
- :monthly - run every month on the first day of the month
'*/5 1,3 * 2 *' - Run according to unix crontab entry format. This would run every tuesday on the 1st and 3rd hour, for any minute divisable by 5, so 0, 5, 10, 15, etc..