Sha256: 0e657416f913caef18adeebb0040d290d2b190e186a7854eaa0ddd8a8270a297

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

require "pathname"

module TsSchema
  class Configuration
    DEFAULTS = {
      case: :camel,
      output: -> { Rails.root.join('app', 'assets', 'javascripts', 'schema.d.ts') },
      auto_generate: true,
      types: ->{ YAML.load_file(File.expand_path(__dir__) + '/conversion_table.yml').to_h },
      custom_types: {},
      default_type: :string,
      include_associated: true,
      parent_classes: ["ApplicationRecord"],
      additional_models: [],
      field_overrides: {
        "encrypted_password" => :password,
        "password" => :optional,
      },
      namespace: :schema,
      schema_type: :interface,
      indent: :tab,
      spaces: 2,
    }

    attr_accessor(*DEFAULTS.keys)

    def initialize(attributes = nil)
      assign(DEFAULTS)
      return unless attributes
      assign(attributes)
    end

    def assign(attributes = nil, &block)
      if !attributes && !block
        raise "Provide attributes or block"
      end
      tap(&block) if block
      if attributes
        attributes.each do |attribute, value|
          value = value.call if value.is_a?(Proc)
          send(:"#{attribute}=", value)
        end
      end
      self
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ts_schema-0.1.14 lib/ts_schema/configuration.rb
ts_schema-0.1.13 lib/ts_schema/configuration.rb