Sha256: 8f421b340676f560d052b168e5064c73efdb64ed181d7931f7d86e339759a7f1

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

module RubyLess
  class ColumnMock
    def initialize(opts = {})
      @opts = opts
    end

    def default
      @opts[:default]
    end

    def type
      @opts[:type]
    end

    # Returns +true+ if the column is either of type string or text.
    def text?
      type == :string || type == :text
    end

    # Returns +true+ if the column is either of type integer, float or decimal.
    def number?
      type == :integer || type == :float || type == :decimal
    end

    # Returns the Ruby class that corresponds to the abstract data type.
    def klass
      case type
        when :integer       then Fixnum
        when :float         then Float
        when :decimal       then BigDecimal
        when :datetime      then Time
        when :date          then Date
        when :timestamp     then Time
        when :time          then Time
        when :text, :string then String
        when :binary        then String
        when :boolean       then Object
      end
    end

  end

  class ActiveRecordMock
    COLUMNS = {
      'format' => ColumnMock.new(:default => '%d.%m.%Y', :type   => :text),
      'age'    => ColumnMock.new(:default => 5,  :type => :float),
      'friend_id' => ColumnMock.new(:type => :integer),
      'log_at' => ColumnMock.new(:type => :datetime),
    }
    def self.columns_hash
      COLUMNS
    end

    COLUMNS.each do |k, v|
      define_method(k) do
        v.default
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rubyless-0.5.0 test/mock/active_record_mock.rb
rubyless-0.4.0 test/mock/active_record_mock.rb
rubyless-0.3.5 test/mock/active_record_mock.rb
rubyless-0.3.4 test/mock/active_record_mock.rb
rubyless-0.3.3 test/mock/active_record_mock.rb
rubyless-0.3.2 test/mock/active_record_mock.rb
rubyless-0.3.1 test/mock/active_record_mock.rb