Sha256: 70ee0a81814da372dc10bfb2898d84663ee9acc17717419f01e7cfe4a15d3997

Contents?: true

Size: 811 Bytes

Versions: 1

Compression:

Stored size: 811 Bytes

Contents

module ClassyEnum
  class SemanticFormBuilder < Formtastic::SemanticFormBuilder
    def enum_select_input(method, options)
      enum_class = object.send(method)

      if enum_class.nil?
        enum_class = method.to_s.capitalize.constantize rescue Error.invalid_classy_enum_object(method)
        options[:collection] = enum_class.select_options
      else
        Error.invalid_classy_enum_object unless enum_class.respond_to? :enum_classes
        options[:collection] = enum_class.class.superclass.select_options
        options[:selected] = enum_class.to_s
      end
      
      options[:include_blank] = false
      
      select_input(method, options)
    end
  end
  
  module Error
    def self.invalid_classy_enum_object(method)
      raise "#{method} is not a ClassyEnum object"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
classy_enum-0.6.0 lib/classy_enum/semantic_form_builder.rb