Sha256: e708c7edbdff19625b10acbf36197a263f361a65132e9a94be99681464219b75

Contents?: true

Size: 1001 Bytes

Versions: 6

Compression:

Stored size: 1001 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,
			additional_models: []
    }

    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

6 entries across 6 versions & 1 rubygems

Version Path
ts_schema-0.1.10 lib/ts_schema/configuration.rb
ts_schema-0.1.9 lib/ts_schema/configuration.rb
ts_schema-0.1.8 lib/ts_schema/configuration.rb
ts_schema-0.1.7 lib/ts_schema/configuration.rb
ts_schema-0.1.6 lib/ts_schema/configuration.rb
ts_schema-0.1.5 lib/ts_schema/configuration.rb