Skip to content

Commit

Permalink
Merge ab98c37 into 051ab03
Browse files Browse the repository at this point in the history
  • Loading branch information
kirs committed Mar 24, 2016
2 parents 051ab03 + ab98c37 commit 95b52d4
Show file tree
Hide file tree
Showing 16 changed files with 351 additions and 493 deletions.
17 changes: 3 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
language: ruby

rvm:
- 2.0
- 2.1
- 2.2
- 2.2.3
- 2.3.0
gemfile:
- gemfiles/Gemfile.ar-3.2
- gemfiles/Gemfile.ar-4.0
- gemfiles/Gemfile.ar-4.1
- gemfiles/Gemfile.ar-4.2
- gemfiles/Gemfile.ar-edge

Expand All @@ -19,16 +16,8 @@ addons:
postgresql: 9.3

sudo: false
cache: bundler

before_script:
- mysql -e 'create database typed_store_test;'
- psql -c 'create database typed_store_test;' -U postgres

matrix:
allow_failures:
- gemfile: gemfiles/Gemfile.ar-edge
exclude:
- gemfile: gemfiles/Gemfile.ar-edge
rvm: 2.1
- gemfile: gemfiles/Gemfile.ar-edge
rvm: 2.0
2 changes: 1 addition & 1 deletion activerecord-typedstore.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_dependency 'activerecord', '>= 3.2', '< 5'
spec.add_dependency 'activerecord', '>= 4.2', '< 5.1'

spec.add_development_dependency 'bundler', '~> 1.3'
spec.add_development_dependency 'rake', '~> 10'
Expand Down
3 changes: 2 additions & 1 deletion gemfiles/Gemfile.ar-edge
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
source 'https://rubygems.org'

gem 'rails', github: 'rails/rails'
gem 'activerecord', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'bundler', '~> 1.3'
gem 'rake'
gem 'rspec'
Expand Down
95 changes: 0 additions & 95 deletions lib/active_record/typed_store/ar_32_fallbacks.rb

This file was deleted.

28 changes: 0 additions & 28 deletions lib/active_record/typed_store/coder.rb

This file was deleted.

86 changes: 0 additions & 86 deletions lib/active_record/typed_store/column.rb

This file was deleted.

34 changes: 18 additions & 16 deletions lib/active_record/typed_store/dsl.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
module ActiveRecord::TypedStore
require 'active_record/typed_store/field'

module ActiveRecord::TypedStore
class DSL
attr_reader :fields, :coder

attr_reader :columns

def initialize(accessors=true)
@accessors = accessors
@columns = []
def initialize(options)
@coder = options.fetch(:coder) { default_coder }
@fields = {}
yield self
end

def accessors
@columns.select(&:accessor?).map(&:name)
def default_coder
ActiveRecord::Coders::YAMLColumn.new
end

[:string, :text, :integer, :float, :datetime, :date, :boolean, :any].each do |type|
define_method(type) do |name, options = {}|
@columns << Column.new(name, type, {accessor: @accessors}.merge(options))
end
def accessors
@fields.values.select { |v| v.accessor }.map(&:name)
end

def decimal(name, options = {})
@columns << Column.new(name, :decimal, {accessor: @accessors, limit: 20, scale: 6}.merge(options))
end
delegate :keys, to: :@fields

NO_DEFAULT_GIVEN = Object.new
[:string, :text, :integer, :float, :datetime, :date, :boolean, :decimal, :any].each do |type|
define_method(type) do |name, **options|
@fields[name] = Field.new(name, type, options)
end
end
alias_method :date_time, :datetime
end

end

0 comments on commit 95b52d4

Please sign in to comment.