Sha256: 20bb4963e23b84558233c325e1128f8599b72fa2871dfe3eb1fc7865e3e0aefa

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module CanTango
  module Permit
    class MissingTypeError < StandardError; end
    class MissingNameError < StandardError; end
  end
  
  module Macros
    module Permit
      def tango_permit options = {}
        name = options[:name] || CanTango::Macros::Permit.permit_name(self)
        account = options[:account] || CanTango::Macros::Permit.account_name(self)
        super_class = self.superclass
        class_type = unless super_class == Object
          super_class.respond_to?(:type) ? super_class.type : nil
        end
        type = options[:type] || class_type

        raise CanTango::Permit::MissingNameError, "Name of permit could not be determined, try specifying a :name option" if name.nil?
        raise CanTango::Permit::MissingTypeError, "Type of permit could not be determined, try specifying a :type option" if type.nil?

        reg_options = {:name => name, :type => type, :account => account}
        CanTango.config.permits.register self, reg_options
        reg_options
      end      
      extend CanTango::Permit::Helper::Naming
    end
  end
end

class Class
  include CanTango::Macros::Permit
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cantango-permits-0.1.1 lib/cantango/permits_ext/macros/permit.rb