Sha256: 90c7aa7dc68ebd268f14d767590facbb8bf40ad6c94c14c2d00edbba2379ac06

Contents?: true

Size: 1.19 KB

Versions: 5

Compression:

Stored size: 1.19 KB

Contents

require 'singleton'

require 'crowi/client/model/crowi_model_base'
require 'crowi/client/model/crowi_page'
require 'crowi/client/model/crowi_page_revision'
require 'crowi/client/model/crowi_user'
require 'crowi/client/model/crowi_attachment'

# Crowi model factory class
# @abstract include singleton class
# @attr_reader makers Model maker list
class CrowiModelFactory
  include Singleton
  attr_reader :makers

  # Constractor
  def initialize
    @makers = {}
    @makers.default = Proc.new { |param|
      next nil if param == nil
      case param
      when Array, String, Integer then
        ret = param
      when FalseClass then
        ret = false
      when TrueClass then
        ret = true
      end
      next ret
    }
  end

  # Register model maker
  # @param [Hash] Model factory list
  def register(makers = {})
    makers.each do |model_name, model_make_proc|
      unless model_make_proc.is_a?(Proc)
        raise ArgumentError.new('Maker is required sub class of Class.')
      end
    end
    @makers.merge!(makers)
  end

  # Get model maker
  # @param [String] model_name Model name
  # @return [Proc] Model maker
  def maker(model_name)
    return @makers[model_name&.to_sym]
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
crowi-client-0.1.4 lib/crowi/client/model/crowi_model.rb
crowi-client-0.1.3 lib/crowi/client/model/crowi_model.rb
crowi-client-0.1.2 lib/crowi/client/model/crowi_model.rb
crowi-client-0.1.1 lib/crowi/client/model/crowi_model.rb
crowi-client-0.1.0 lib/crowi/client/model/crowi_model.rb