Sha256: fb8215cf55051efb4ef0d28e246dc2524e4d34119fb31aafffe060a5a8d52ef2

Contents?: true

Size: 1.05 KB

Versions: 7

Compression:

Stored size: 1.05 KB

Contents

module ActiveData
  class Config
    include Singleton

    attr_accessor :include_root_in_json, :i18n_scope, :logger, :primary_attribute, :base_class, :base_concern,
      :_normalizers, :_typecasters

    def self.delegated
      public_instance_methods - superclass.public_instance_methods - Singleton.public_instance_methods
    end

    def initialize
      @include_root_in_json = false
      @i18n_scope = :active_data
      @logger = Logger.new(STDERR)
      @primary_attribute = :id
      @_normalizers = {}
      @_typecasters = {}
    end

    def normalizer(name, &block)
      if block
        _normalizers[name.to_sym] = block
      else
        _normalizers[name.to_sym] or raise NormalizerMissing, name
      end
    end

    def typecaster(*classes, &block)
      classes = classes.flatten
      if block
        _typecasters[classes.first.to_s.camelize] = block
      else
        _typecasters[classes.detect do |klass|
          _typecasters[klass.to_s.camelize]
        end.to_s.camelize] or raise TypecasterMissing, classes
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
active_data-1.2.0 lib/active_data/config.rb
active_data-1.1.7 lib/active_data/config.rb
active_data-1.1.6 lib/active_data/config.rb
active_data-1.1.5 lib/active_data/config.rb
active_data-1.1.4 lib/active_data/config.rb
active_data-1.1.3 lib/active_data/config.rb
active_data-1.1.2 lib/active_data/config.rb