Sha256: a4104759b46b70facc89de95c33556cef2935d47e2cf88864fb8d8b2342fb4e5

Contents?: true

Size: 976 Bytes

Versions: 3

Compression:

Stored size: 976 Bytes

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,
      namespace: :schema,
      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

3 entries across 3 versions & 1 rubygems

Version Path
ts_schema-0.1.4 lib/ts_schema/configuration.rb
ts_schema-0.1.3 lib/ts_schema/configuration.rb
ts_schema-0.1.1 lib/ts_schema/configuration.rb