Skip to content

Instantly share code, notes, and snippets.

Avatar

Matthew Millsaps-Brewer macfanatic

View GitHub Profile
@macfanatic
macfanatic / account.rb
Created Mar 3, 2017
See usage.rb below for an example of Rails Association Extensions at their finest
View account.rb
class Account < ActiveRecord::Base
has_many :conversations, dependent: :destroy, extend: Voting::Resource::AssociationActions
end
View active_admin-state_machine.rb
module ActiveAdmin
module StateMachine
module DSL
#
# Easily tie into a state_machine action
#
# @param [Symbol] state machine event, ie: :publish
# @param [Hash] options
# - permission [Symbol] permission to check authorization against
View post_state_machine.rb
# app/models/post.rb
class Post < ActiveRecord::Base
attr_accessible :body, :status, :title
validates :title, presence: true, uniqueness: true
validates :body, presence: true
DRAFT = 'draft'
REVIEWED = 'reviewed'
PUBLISHED = 'published'
@macfanatic
macfanatic / simplest_indicator.rb
Last active Jul 7, 2016
Simple indicator class showing how we might implement managing state definitions
View simplest_indicator.rb
class StatusIndicator
OFF = 'off'.freeze
CHARGING = 'charging'.freeze
CHARGED = 'charged'.freeze
def self.states
[ OFF, CHARGING, CHARGED ]
end
def self.renderings
View example_systemd.service
[Unit]
Description=udp-listener
After=multi-user.target
[Service]
Type=idle
WorkingDirectory=/var/apps/our-software
ExecStart=/var/apps/our-software/bin/udp-listener
User=pi
Group=pi
View init-v-template.sh
#!/bin/sh
### BEGIN INIT INFO
# Provides:
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
View filter_state_input.rb
module ActiveAdmin
module Inputs
class FilterStateInput < FilterSelectInput
include FilterBase
def collection
{
'AL' => 'Alabama',
'AK' => 'Alaska',
'AZ' => 'Arizona',
View filter_country_input.rb
module ActiveAdmin
module Inputs
class FilterCountryInput < FilterSelectInput
include FilterBase
def collection
::ActionView::Helpers::FormOptionsHelper::COUNTRIES
end
end
You can’t perform that action at this time.