Sha256: 28cbc1428a1b89dd189084fad6d2d467e65ecc808598c6a1a1adc7c9138154f9
Contents?: true
Size: 1.45 KB
Versions: 2
Compression:
Stored size: 1.45 KB
Contents
module Puffer module Controller module Dsl def self.included base base.class_eval do extend ClassMethods include ActionMethods extend ActionMethods %w(index show form create update).each do |action| class_attribute "_#{action}_fields" send "_#{action}_fields=", Puffer::Fields.new unless send("_#{action}_fields").present? helper_method "#{action}_fields" end end end module ClassMethods %w(index show form create update).each do |action| define_method action do |&block| @_fields = send "_#{action}_fields" @_fields.clear block.call if block @_fields = nil end end def field name, options = {} field = @_fields.field(model, name, options) if @_fields #generate_association_actions field if field.association? #generate_change_actions field if field.toggable? end end module ActionMethods def index_fields _index_fields end def show_fields _show_fields.presence || _index_fields end def form_fields _form_fields end def create_fields _create_fields.presence || _form_fields end def update_fields _update_fields.presence || _form_fields end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
puffer-0.0.7 | lib/puffer/controller/dsl.rb |
puffer-0.0.6 | lib/puffer/controller/dsl.rb |