anonymous_active_record 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f98e9d83df30da94c3734c15029a884b89b128208c95036fd24f1f6575f919cd
4
- data.tar.gz: 15f9c85d4bd048b4dd5bf94600976b7dc62df326fde06fb140f8a15b166a9cf7
3
+ metadata.gz: 2821534f820ee07bf62491921ae0c29fa0e5b67cfdd9bca791463b5ab5721d5e
4
+ data.tar.gz: 3983d86271c42fec4c2f988fed2ec0d1f38d74b922ac6460fadd6b4477ab91db
5
5
  SHA512:
6
- metadata.gz: 70c19951a270ef60b83296617029def5b5e24d8cf7e997c414a68eeb6730486f552f4ca27583344f2e3a91627cca583eea278aace70c07641c25c4c75146bb2e
7
- data.tar.gz: 8848311f3fa1c4f3293a8a5be74621a1da710cf570dab69dc4b139e3b6fb69d7561c628d78f640b1b3f1ec827269453207c3a85ff9397a20ae39662ac63f318b
6
+ metadata.gz: 194e3d6dcb2471a5000f6fd2a2a4e33aa79d38169a5e7a1d02a340f86e2f17155fdaf4689b97c8673ca92882b68a78f24b146d494dbf5d56eec87fd1e1118c7f
7
+ data.tar.gz: 8fa56bcd1f489028d715039b64feff6caf7f22dc93ae6f08edf35b779c7ec1eaa5a9281972a6f00b73505168056b297f6a0aabe6956b1cb87cd135eb8a9078ef
data/Gemfile CHANGED
@@ -3,16 +3,9 @@ source 'https://rubygems.org'
3
3
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  group :test do
6
- ruby_version = Gem::Version.new(RUBY_VERSION)
7
- if ruby_version >= Gem::Version.new('2.1')
8
- gem 'rubocop', '~> 0.60.0'
9
- gem 'rubocop-rspec', '~> 1.30.0'
10
- end
11
- if ruby_version >= Gem::Version.new('2.0')
12
- gem 'byebug', '~> 10', platform: :mri, require: false
13
- gem 'pry', '~> 0', platform: :mri, require: false
14
- gem 'pry-byebug', '~> 3', platform: :mri, require: false
15
- end
6
+ gem 'byebug', '~> 10', platform: :mri, require: false
7
+ gem 'pry', '~> 0', platform: :mri, require: false
8
+ gem 'pry-byebug', '~> 3', platform: :mri, require: false
16
9
  gem 'simplecov', '~> 0', require: false
17
10
  end
18
11
 
data/README.md CHANGED
@@ -100,11 +100,16 @@ AnonymousActiveRecord.generate(
100
100
  # default is a unique random table name
101
101
  klass_basename: 'anons', # is default
102
102
  columns: ['name'],
103
- # default is [],
103
+ # columns default is [],
104
104
  # meaning class will have ['id', 'created_at', 'updated_at'], as the AR defaults
105
105
  # Optionally provide an array of hashes and thereby designate column type:
106
106
  # [{name: 'name', type: 'string'}, {name: 'baked_at', type: 'time'}]
107
107
  timestamps: true, # is default
108
+ indexes: [{columns: ['name'], unique: true}],
109
+ # indexes default is [],
110
+ # meaning class will have no indexes, as the AR defaults
111
+ # Optionally provide an array of hashes of index options (similar to those used in Rails migrations):
112
+ # [{columns: ['name'], unique: true}, {columns: ['baked_at']}]
108
113
  connection_params: { adapter: 'sqlite3', encoding: 'utf8', database: ':memory:' } # is default
109
114
  ) do
110
115
  # code which becomes part of the class definition
@@ -25,6 +25,9 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'bundler', '~> 1'
26
26
  spec.add_development_dependency 'rake', '~> 12'
27
27
  spec.add_development_dependency 'rspec', '~> 3'
28
+ spec.add_development_dependency 'rspec-block_is_expected', '~> 1.0'
29
+ spec.add_development_dependency 'rubocop', '~> 0.60'
30
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.30'
28
31
  spec.add_development_dependency 'sqlite3', '~> 1'
29
32
  spec.add_dependency 'activerecord', '~> 5'
30
33
  end
@@ -1,3 +1,3 @@
1
1
  module AnonymousActiveRecord
2
- VERSION = '0.1.3'.freeze
2
+ VERSION = '0.1.4'.freeze
3
3
  end
@@ -42,7 +42,7 @@ module AnonymousActiveRecord
42
42
  }.freeze
43
43
 
44
44
  # Defines a pseudo anonymous class in a particular namespace of your choosing.
45
- def generate(table_name: nil, klass_namespaces: [], klass_basename: nil, columns: [], timestamps: true, connection_params: DEFAULT_CONNECTION_PARAMS, &block)
45
+ def generate(table_name: nil, klass_namespaces: [], klass_basename: nil, columns: [], indexes: [], timestamps: true, connection_params: DEFAULT_CONNECTION_PARAMS, &block)
46
46
  gen = AnonymousActiveRecord::Generator.new(table_name, klass_namespaces, klass_basename)
47
47
  klass = gen.generate(&block)
48
48
  connection_params = YAML.load_file(connection_params) if connection_params.is_a?(String)
@@ -56,27 +56,31 @@ module AnonymousActiveRecord
56
56
  t.column col, :string
57
57
  end
58
58
  end
59
+ indexes.each do |idx_options|
60
+ column_names = idx_options.delete(:columns)
61
+ t.index column_names, **(idx_options)
62
+ end
59
63
  t.timestamps if timestamps
60
64
  end
61
65
  klass
62
66
  end
63
67
 
64
68
  # Initializes instances of a pseudo anonymous class in a particular namespace of your choosing.
65
- def factory(source_data: [], table_name: nil, klass_namespaces: [], klass_basename: nil, columns: [], timestamps: true, connection_params: DEFAULT_CONNECTION_PARAMS, &block)
66
- factory = _factory(source_data: source_data, table_name: table_name, klass_namespaces: klass_namespaces, klass_basename: klass_basename, columns: columns, timestamps: timestamps, connection_params: connection_params, &block)
69
+ def factory(source_data: [], table_name: nil, klass_namespaces: [], klass_basename: nil, columns: [], indexes: [], timestamps: true, connection_params: DEFAULT_CONNECTION_PARAMS, &block)
70
+ factory = _factory(source_data: source_data, table_name: table_name, klass_namespaces: klass_namespaces, klass_basename: klass_basename, columns: columns, indexes: indexes, timestamps: timestamps, connection_params: connection_params, &block)
67
71
  factory.run
68
72
  end
69
73
 
70
74
  # Initializes instances of a pseudo anonymous class in a particular namespace of your choosing.
71
- def factory!(source_data: [], table_name: nil, klass_namespaces: [], klass_basename: nil, columns: [], timestamps: true, connection_params: DEFAULT_CONNECTION_PARAMS, &block)
72
- factory = _factory(source_data: source_data, table_name: table_name, klass_namespaces: klass_namespaces, klass_basename: klass_basename, columns: columns, timestamps: timestamps, connection_params: connection_params, &block)
75
+ def factory!(source_data: [], table_name: nil, klass_namespaces: [], klass_basename: nil, columns: [], indexes: [], timestamps: true, connection_params: DEFAULT_CONNECTION_PARAMS, &block)
76
+ factory = _factory(source_data: source_data, table_name: table_name, klass_namespaces: klass_namespaces, klass_basename: klass_basename, columns: columns, indexes: indexes, timestamps: timestamps, connection_params: connection_params, &block)
73
77
  factory.run!
74
78
  end
75
79
 
76
80
  private
77
81
 
78
- def _factory(source_data: [], table_name: nil, klass_namespaces: [], klass_basename: nil, columns: [], timestamps: true, connection_params: DEFAULT_CONNECTION_PARAMS, &block)
79
- klass = generate(table_name: table_name, klass_namespaces: klass_namespaces, klass_basename: klass_basename, columns: columns, timestamps: timestamps, connection_params: connection_params, &block)
82
+ def _factory(source_data: [], table_name: nil, klass_namespaces: [], klass_basename: nil, columns: [], indexes: [], timestamps: true, connection_params: DEFAULT_CONNECTION_PARAMS, &block)
83
+ klass = generate(table_name: table_name, klass_namespaces: klass_namespaces, klass_basename: klass_basename, columns: columns, timestamps: timestamps, indexes: indexes, connection_params: connection_params, &block)
80
84
  AnonymousActiveRecord::Factory.new(source_data, klass)
81
85
  end
82
86
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anonymous_active_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Boling
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-28 00:00:00.000000000 Z
11
+ date: 2018-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,48 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-block_is_expected
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.60'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.60'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.30'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.30'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: sqlite3
57
99
  requirement: !ruby/object:Gem::Requirement