Sha256: ce57704b32697aed6c58f1947cf3d3a485c139ae4d07d75b0197cf98ea796626

Contents?: true

Size: 932 Bytes

Versions: 21

Compression:

Stored size: 932 Bytes

Contents

require 'virtus'
module SuperForm
  class Basic
    include ActiveModel::Model
    extend ActiveModel::Naming
    include ActiveModel::Conversion
    include ActiveModel::Validations
    include Virtus.model

    def sync_params(params)
      params.each do |attr, value|
        public_send("#{attr}=", value) if respond_to?("#{attr}=")
      end
    end

    class << self
      def form_name(name)
        # 定義 form name (給 form 用的)
        define_singleton_method :model_name do
          active_model_name_for(name.to_s.camelize)
        end
      end

      # default is forms
      def i18n_scope
        :forms
      end

      # 定義 i18n scope
      def i18n_prefix(i18n_scope)
        define_singleton_method :i18n_scope do
          i18n_scope.to_sym
        end
      end

      private

      def active_model_name_for(string)
        ::ActiveModel::Name.new(self, nil, string)
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
super_tools-2.1.0 lib/super_form/basic.rb
super_tools-0.0.26 lib/super_form/basic.rb
super_tools-0.0.25 lib/super_form/basic.rb
super_tools-0.0.21 lib/super_form/basic.rb
super_tools-0.0.20 lib/super_form/basic.rb
super_tools-0.0.17 lib/super_form/basic.rb
super_tools-0.0.15 lib/super_form/basic.rb
super_tools-0.0.14 lib/super_form/basic.rb
super_tools-0.0.13 lib/super_form/basic.rb
super_tools-0.0.12 lib/super_form/basic.rb
super_tools-0.0.11 lib/super_form/basic.rb
super_tools-0.0.10 lib/super_form/basic.rb
super_tools-0.0.9 lib/super_form/basic.rb
super_tools-0.0.8 lib/super_form/basic.rb
super_tools-0.0.7 lib/super_form/basic.rb
super_tools-0.0.6 lib/super_form/basic.rb
super_tools-0.0.5 lib/super_form/basic.rb
super_tools-0.0.4 lib/super_form/basic.rb
super_tools-0.0.3 lib/super_form/basic.rb
super_tools-0.0.2 lib/super_form/basic.rb