Skip to content

Instantly share code, notes, and snippets.

@lwoodson
Created October 23, 2012 15:29
Show Gist options
  • Save lwoodson/3939459 to your computer and use it in GitHub Desktop.
Save lwoodson/3939459 to your computer and use it in GitHub Desktop.
Chord definitions DSL
module ChordDSL
def chord(file_path, &block)
chord = Chord.new
chord.file_path = file_path
chord_ctx = ChordContext.new chord
chord_ctx.instance_exec &block
chord.save!
end
class ChordContext
def initialize(chord)
@chord = chord
end
def one(tuning="E", fret_action="x")
@chord.one_tuning = tuning
@chord.fret = fret_action
end
def two(tuning="A", fret_action="x")
@chord.two_tuning = tuning
@chord.fret = fret_action
end
# more methods for strings 3-6
end
end
class Chord < ActiveRecord::Base
def before_save
# generate your image and tie to this chord.
end
end
class ChordMigration < ActiveRecord::Migration
extend ChordDSL
chord 'a_minor' do
one :x
two 0
three 2
four 2
five 1
six 0
end
# other chord definitions...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment