activerecord-tablefree 3.1.1 → 3.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +12 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/{activerecord-tablefree → activerecord/tablefree}/cast_type.rb +0 -0
- data/lib/{activerecord-tablefree → activerecord/tablefree}/connection.rb +0 -0
- data/lib/{activerecord-tablefree → activerecord/tablefree}/schema_cache.rb +0 -0
- data/lib/{activerecord-tablefree → activerecord/tablefree}/transaction.rb +0 -0
- data/lib/activerecord/tablefree/version.rb +7 -0
- data/lib/activerecord/tablefree.rb +234 -0
- data/lib/activerecord-tablefree.rb +2 -235
- data/spec/activerecord/tablefree/version_spec.rb +5 -0
- data/spec/{lib/activerecord-tablefree_spec.rb → activerecord/tablefree_spec.rb} +1 -4
- data/spec/spec_helper.rb +5 -0
- metadata +18 -10
- data/lib/activerecord-tablefree/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9050219b074d636ea977dde8d3c3725f7bae889
|
4
|
+
data.tar.gz: 3b7fa7a1cadfd4645d4ece6b90b95f1752782473
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f759624174cecc91229bf7c2d15d04b7075f24f2f01c7aa76d1b7bc6ae60664391da59722ff0dc39cfa611763c016e35e4dec3bd74edddf8853131892d50bff
|
7
|
+
data.tar.gz: 36429a10d2a5aa374b3bc86d12d294c2d670565e8557cad39379c26988e47c859feff79a0e8f932667f3015ecfc754a376384ff911325dc810890233b018a65c
|
data/.gitignore
CHANGED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at peter.boling@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'activerecord/tablefree'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,234 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
require 'activerecord/tablefree/version'
|
5
|
+
require 'activerecord/tablefree/cast_type'
|
6
|
+
require 'activerecord/tablefree/schema_cache'
|
7
|
+
require 'activerecord/tablefree/connection'
|
8
|
+
require 'activerecord/tablefree/transaction'
|
9
|
+
|
10
|
+
module ActiveRecord
|
11
|
+
# = ActiveRecord::Tablefree
|
12
|
+
#
|
13
|
+
# Allow classes to behave like ActiveRecord models, but without an associated
|
14
|
+
# database table. A great way to capitalize on validations. Based on the
|
15
|
+
# original post at http://www.railsweenie.com/forums/2/topics/724 (which seems
|
16
|
+
# to have disappeared from the face of the earth).
|
17
|
+
#
|
18
|
+
# = Example usage
|
19
|
+
#
|
20
|
+
# class ContactMessage < ActiveRecord::Base
|
21
|
+
#
|
22
|
+
# has_no_table
|
23
|
+
#
|
24
|
+
# column :name, :string
|
25
|
+
# column :email, :string
|
26
|
+
# column :message, :string
|
27
|
+
#
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# msg = ContactMessage.new( params[:msg] )
|
31
|
+
# if msg.valid?
|
32
|
+
# ContactMessageSender.deliver_message( msg )
|
33
|
+
# redirect_to :action => :sent
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
module Tablefree
|
37
|
+
class NoDatabase < StandardError; end
|
38
|
+
class Unsupported < StandardError; end
|
39
|
+
|
40
|
+
def self.included(base) #:nodoc:
|
41
|
+
base.send :extend, ActsMethods
|
42
|
+
end
|
43
|
+
|
44
|
+
module ActsMethods #:nodoc:
|
45
|
+
# A model that needs to be tablefree will call this method to indicate
|
46
|
+
# it.
|
47
|
+
def has_no_table(options = { database: :fail_fast })
|
48
|
+
raise ArgumentError, "Invalid database option '#{options[:database]}'" unless %i[fail_fast pretend_success].member? options[:database]
|
49
|
+
# keep our options handy
|
50
|
+
class_attribute :tablefree_options
|
51
|
+
self.tablefree_options = {
|
52
|
+
database: options[:database],
|
53
|
+
columns_hash: {}
|
54
|
+
}
|
55
|
+
|
56
|
+
# extend
|
57
|
+
extend ActiveRecord::Tablefree::SingletonMethods
|
58
|
+
extend ActiveRecord::Tablefree::ClassMethods
|
59
|
+
|
60
|
+
# include
|
61
|
+
include ActiveRecord::Tablefree::InstanceMethods
|
62
|
+
|
63
|
+
# setup columns
|
64
|
+
include ActiveModel::AttributeAssignment
|
65
|
+
include ActiveRecord::ModelSchema
|
66
|
+
end
|
67
|
+
|
68
|
+
def tablefree?
|
69
|
+
false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
module SingletonMethods
|
74
|
+
# Used internally by ActiveRecord 5. This is the special hook that makes everything else work.
|
75
|
+
def load_schema!
|
76
|
+
@columns_hash = tablefree_options[:columns_hash].except(*ignored_columns)
|
77
|
+
@columns_hash.each do |name, column|
|
78
|
+
define_attribute(
|
79
|
+
name,
|
80
|
+
connection.lookup_cast_type_from_column(column),
|
81
|
+
default: column.default,
|
82
|
+
user_provided_default: false
|
83
|
+
)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Register a new column.
|
88
|
+
def column(name, sql_type = nil, default = nil, null = true)
|
89
|
+
cast_type = "ActiveRecord::Type::#{sql_type.to_s.camelize}".constantize.new
|
90
|
+
tablefree_options[:columns_hash][name.to_s] = ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, cast_type, sql_type.to_s, null)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Register a set of columns with the same SQL type
|
94
|
+
def add_columns(sql_type, *args)
|
95
|
+
args.each do |col|
|
96
|
+
column col, sql_type
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def destroy(*_args)
|
101
|
+
case tablefree_options[:database]
|
102
|
+
when :pretend_success
|
103
|
+
new
|
104
|
+
when :fail_fast
|
105
|
+
raise NoDatabase, "Can't #destroy on Tablefree class"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def destroy_all(*_args)
|
110
|
+
case tablefree_options[:database]
|
111
|
+
when :pretend_success
|
112
|
+
[]
|
113
|
+
when :fail_fast
|
114
|
+
raise NoDatabase, "Can't #destroy_all on Tablefree class"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
case ActiveRecord::VERSION::MAJOR
|
119
|
+
when 5
|
120
|
+
def find_by_sql(*_args)
|
121
|
+
case tablefree_options[:database]
|
122
|
+
when :pretend_success
|
123
|
+
[]
|
124
|
+
when :fail_fast
|
125
|
+
raise NoDatabase, "Can't #find_by_sql on Tablefree class"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
else
|
129
|
+
raise Unsupported, 'Unsupported ActiveRecord version'
|
130
|
+
end
|
131
|
+
|
132
|
+
def transaction
|
133
|
+
# case tablefree_options[:database]
|
134
|
+
# when :pretend_success
|
135
|
+
@_current_transaction_records ||= []
|
136
|
+
yield
|
137
|
+
# when :fail_fast
|
138
|
+
# raise NoDatabase.new("Can't #transaction on Tablefree class")
|
139
|
+
# end
|
140
|
+
end
|
141
|
+
|
142
|
+
def tablefree?
|
143
|
+
true
|
144
|
+
end
|
145
|
+
|
146
|
+
def table_exists?
|
147
|
+
false
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
module ClassMethods
|
152
|
+
def from_query_string(query_string)
|
153
|
+
if query_string.blank?
|
154
|
+
new
|
155
|
+
else
|
156
|
+
params = query_string.split('&').collect do |chunk|
|
157
|
+
next if chunk.empty?
|
158
|
+
key, value = chunk.split('=', 2)
|
159
|
+
next if key.empty?
|
160
|
+
value = value.nil? ? nil : CGI.unescape(value)
|
161
|
+
[CGI.unescape(key), value]
|
162
|
+
end.compact.to_h
|
163
|
+
|
164
|
+
new(params)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def connection
|
169
|
+
@_connection ||= ActiveRecord::Tablefree::Connection.new
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
module InstanceMethods
|
174
|
+
def to_query_string(prefix = nil)
|
175
|
+
attributes.to_a.collect { |(name, value)| escaped_var_name(name, prefix) + '=' + escape_for_url(value) if value }.compact.join('&')
|
176
|
+
end
|
177
|
+
|
178
|
+
def quote_value(_value, _column = nil)
|
179
|
+
''
|
180
|
+
end
|
181
|
+
|
182
|
+
%w[create create_record _create_record update update_record _update_record].each do |method_name|
|
183
|
+
define_method(method_name) do |*_args|
|
184
|
+
case self.class.tablefree_options[:database]
|
185
|
+
when :pretend_success
|
186
|
+
true
|
187
|
+
when :fail_fast
|
188
|
+
raise NoDatabase, "Can't ##{method_name} a Tablefree object"
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def destroy
|
194
|
+
case self.class.tablefree_options[:database]
|
195
|
+
when :pretend_success
|
196
|
+
@destroyed = true
|
197
|
+
freeze
|
198
|
+
when :fail_fast
|
199
|
+
raise NoDatabase, "Can't #destroy a Tablefree object"
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def reload(*_args)
|
204
|
+
case self.class.tablefree_options[:database]
|
205
|
+
when :pretend_success
|
206
|
+
self
|
207
|
+
when :fail_fast
|
208
|
+
raise NoDatabase, "Can't #reload a Tablefree object"
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
def add_to_transaction; end
|
213
|
+
|
214
|
+
private
|
215
|
+
|
216
|
+
def escaped_var_name(name, prefix = nil)
|
217
|
+
prefix ? "#{CGI.escape(prefix)}[#{CGI.escape(name)}]" : CGI.escape(name)
|
218
|
+
end
|
219
|
+
|
220
|
+
def escape_for_url(value)
|
221
|
+
case value
|
222
|
+
when true then '1'
|
223
|
+
when false then '0'
|
224
|
+
when nil then ''
|
225
|
+
else CGI.escape(value.to_s)
|
226
|
+
end
|
227
|
+
rescue
|
228
|
+
''
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
ActiveRecord::Base.send(:include, ActiveRecord::Tablefree)
|
@@ -1,235 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require '
|
3
|
-
|
4
|
-
require 'activerecord-tablefree/version'
|
5
|
-
require 'activerecord-tablefree/cast_type'
|
6
|
-
require 'activerecord-tablefree/schema_cache'
|
7
|
-
require 'activerecord-tablefree/connection'
|
8
|
-
require 'activerecord-tablefree/transaction'
|
9
|
-
|
10
|
-
module ActiveRecord
|
11
|
-
# = ActiveRecord::Tablefree
|
12
|
-
#
|
13
|
-
# Allow classes to behave like ActiveRecord models, but without an associated
|
14
|
-
# database table. A great way to capitalize on validations. Based on the
|
15
|
-
# original post at http://www.railsweenie.com/forums/2/topics/724 (which seems
|
16
|
-
# to have disappeared from the face of the earth).
|
17
|
-
#
|
18
|
-
# = Example usage
|
19
|
-
#
|
20
|
-
# class ContactMessage < ActiveRecord::Base
|
21
|
-
#
|
22
|
-
# has_no_table
|
23
|
-
#
|
24
|
-
# column :name, :string
|
25
|
-
# column :email, :string
|
26
|
-
# column :message, :string
|
27
|
-
#
|
28
|
-
# end
|
29
|
-
#
|
30
|
-
# msg = ContactMessage.new( params[:msg] )
|
31
|
-
# if msg.valid?
|
32
|
-
# ContactMessageSender.deliver_message( msg )
|
33
|
-
# redirect_to :action => :sent
|
34
|
-
# end
|
35
|
-
#
|
36
|
-
module Tablefree
|
37
|
-
|
38
|
-
class NoDatabase < StandardError; end
|
39
|
-
class Unsupported < StandardError; end
|
40
|
-
|
41
|
-
def self.included(base) #:nodoc:
|
42
|
-
base.send :extend, ActsMethods
|
43
|
-
end
|
44
|
-
|
45
|
-
module ActsMethods #:nodoc:
|
46
|
-
# A model that needs to be tablefree will call this method to indicate
|
47
|
-
# it.
|
48
|
-
def has_no_table(options = { database: :fail_fast })
|
49
|
-
raise ArgumentError, "Invalid database option '#{options[:database]}'" unless %i[fail_fast pretend_success].member? options[:database]
|
50
|
-
# keep our options handy
|
51
|
-
class_attribute :tablefree_options
|
52
|
-
self.tablefree_options = {
|
53
|
-
database: options[:database],
|
54
|
-
columns_hash: {}
|
55
|
-
}
|
56
|
-
|
57
|
-
# extend
|
58
|
-
extend ActiveRecord::Tablefree::SingletonMethods
|
59
|
-
extend ActiveRecord::Tablefree::ClassMethods
|
60
|
-
|
61
|
-
# include
|
62
|
-
include ActiveRecord::Tablefree::InstanceMethods
|
63
|
-
|
64
|
-
# setup columns
|
65
|
-
include ActiveModel::AttributeAssignment
|
66
|
-
include ActiveRecord::ModelSchema
|
67
|
-
end
|
68
|
-
|
69
|
-
def tablefree?
|
70
|
-
false
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
module SingletonMethods
|
75
|
-
# Used internally by ActiveRecord 5. This is the special hook that makes everything else work.
|
76
|
-
def load_schema!
|
77
|
-
@columns_hash = tablefree_options[:columns_hash].except(*ignored_columns)
|
78
|
-
@columns_hash.each do |name, column|
|
79
|
-
define_attribute(
|
80
|
-
name,
|
81
|
-
connection.lookup_cast_type_from_column(column),
|
82
|
-
default: column.default,
|
83
|
-
user_provided_default: false
|
84
|
-
)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
# Register a new column.
|
89
|
-
def column(name, sql_type = nil, default = nil, null = true)
|
90
|
-
cast_type = "ActiveRecord::Type::#{sql_type.to_s.camelize}".constantize.new
|
91
|
-
tablefree_options[:columns_hash][name.to_s] = ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, cast_type, sql_type.to_s, null)
|
92
|
-
end
|
93
|
-
|
94
|
-
# Register a set of columns with the same SQL type
|
95
|
-
def add_columns(sql_type, *args)
|
96
|
-
args.each do |col|
|
97
|
-
column col, sql_type
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def destroy(*_args)
|
102
|
-
case tablefree_options[:database]
|
103
|
-
when :pretend_success
|
104
|
-
new
|
105
|
-
when :fail_fast
|
106
|
-
raise NoDatabase, "Can't #destroy on Tablefree class"
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def destroy_all(*_args)
|
111
|
-
case tablefree_options[:database]
|
112
|
-
when :pretend_success
|
113
|
-
[]
|
114
|
-
when :fail_fast
|
115
|
-
raise NoDatabase, "Can't #destroy_all on Tablefree class"
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
case ActiveRecord::VERSION::MAJOR
|
120
|
-
when 5
|
121
|
-
def find_by_sql(*_args)
|
122
|
-
case tablefree_options[:database]
|
123
|
-
when :pretend_success
|
124
|
-
[]
|
125
|
-
when :fail_fast
|
126
|
-
raise NoDatabase, "Can't #find_by_sql on Tablefree class"
|
127
|
-
end
|
128
|
-
end
|
129
|
-
else
|
130
|
-
raise Unsupported, 'Unsupported ActiveRecord version'
|
131
|
-
end
|
132
|
-
|
133
|
-
def transaction
|
134
|
-
# case tablefree_options[:database]
|
135
|
-
# when :pretend_success
|
136
|
-
@_current_transaction_records ||= []
|
137
|
-
yield
|
138
|
-
# when :fail_fast
|
139
|
-
# raise NoDatabase.new("Can't #transaction on Tablefree class")
|
140
|
-
# end
|
141
|
-
end
|
142
|
-
|
143
|
-
def tablefree?
|
144
|
-
true
|
145
|
-
end
|
146
|
-
|
147
|
-
def table_exists?
|
148
|
-
false
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
module ClassMethods
|
153
|
-
def from_query_string(query_string)
|
154
|
-
if query_string.blank?
|
155
|
-
new
|
156
|
-
else
|
157
|
-
params = query_string.split('&').collect do |chunk|
|
158
|
-
next if chunk.empty?
|
159
|
-
key, value = chunk.split('=', 2)
|
160
|
-
next if key.empty?
|
161
|
-
value = value.nil? ? nil : CGI.unescape(value)
|
162
|
-
[CGI.unescape(key), value]
|
163
|
-
end.compact.to_h
|
164
|
-
|
165
|
-
new(params)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def connection
|
170
|
-
@_connection ||= ActiveRecord::Tablefree::Connection.new
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
module InstanceMethods
|
175
|
-
def to_query_string(prefix = nil)
|
176
|
-
attributes.to_a.collect { |(name, value)| escaped_var_name(name, prefix) + '=' + escape_for_url(value) if value }.compact.join('&')
|
177
|
-
end
|
178
|
-
|
179
|
-
def quote_value(_value, _column = nil)
|
180
|
-
''
|
181
|
-
end
|
182
|
-
|
183
|
-
%w[create create_record _create_record update update_record _update_record].each do |method_name|
|
184
|
-
define_method(method_name) do |*_args|
|
185
|
-
case self.class.tablefree_options[:database]
|
186
|
-
when :pretend_success
|
187
|
-
true
|
188
|
-
when :fail_fast
|
189
|
-
raise NoDatabase, "Can't ##{method_name} a Tablefree object"
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
def destroy
|
195
|
-
case self.class.tablefree_options[:database]
|
196
|
-
when :pretend_success
|
197
|
-
@destroyed = true
|
198
|
-
freeze
|
199
|
-
when :fail_fast
|
200
|
-
raise NoDatabase, "Can't #destroy a Tablefree object"
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
def reload(*_args)
|
205
|
-
case self.class.tablefree_options[:database]
|
206
|
-
when :pretend_success
|
207
|
-
self
|
208
|
-
when :fail_fast
|
209
|
-
raise NoDatabase, "Can't #reload a Tablefree object"
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
def add_to_transaction; end
|
214
|
-
|
215
|
-
private
|
216
|
-
|
217
|
-
def escaped_var_name(name, prefix = nil)
|
218
|
-
prefix ? "#{CGI.escape(prefix)}[#{CGI.escape(name)}]" : CGI.escape(name)
|
219
|
-
end
|
220
|
-
|
221
|
-
def escape_for_url(value)
|
222
|
-
case value
|
223
|
-
when true then '1'
|
224
|
-
when false then '0'
|
225
|
-
when nil then ''
|
226
|
-
else CGI.escape(value.to_s)
|
227
|
-
end
|
228
|
-
rescue
|
229
|
-
''
|
230
|
-
end
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
ActiveRecord::Base.send(:include, ActiveRecord::Tablefree)
|
1
|
+
# legacy automatic require support
|
2
|
+
require 'activerecord/tablefree'
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-tablefree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jarl Friis
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2017-12-
|
14
|
+
date: 2017-12-20 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activerecord
|
@@ -250,7 +250,9 @@ description: ActiveRecord Tablefree Models provides a simple mixin for creating
|
|
250
250
|
email:
|
251
251
|
- jarl@softace.dk
|
252
252
|
- peter.boling@gmail.com
|
253
|
-
executables:
|
253
|
+
executables:
|
254
|
+
- console
|
255
|
+
- setup
|
254
256
|
extensions: []
|
255
257
|
extra_rdoc_files: []
|
256
258
|
files:
|
@@ -258,11 +260,14 @@ files:
|
|
258
260
|
- ".rspec"
|
259
261
|
- ".travis.yml"
|
260
262
|
- Appraisals
|
263
|
+
- CODE_OF_CONDUCT.md
|
261
264
|
- Gemfile
|
262
265
|
- LICENSE.txt
|
263
266
|
- README.md
|
264
267
|
- Rakefile
|
265
268
|
- activerecord-tablefree.gemspec
|
269
|
+
- bin/console
|
270
|
+
- bin/setup
|
266
271
|
- features/basic_integration.feature
|
267
272
|
- features/step_definitions/rails_steps.rb
|
268
273
|
- features/step_definitions/tablefree.rb
|
@@ -275,12 +280,14 @@ files:
|
|
275
280
|
- gemfiles/rails51.gemfile
|
276
281
|
- init.rb
|
277
282
|
- lib/activerecord-tablefree.rb
|
278
|
-
- lib/activerecord
|
279
|
-
- lib/activerecord
|
280
|
-
- lib/activerecord
|
281
|
-
- lib/activerecord
|
282
|
-
- lib/activerecord
|
283
|
-
-
|
283
|
+
- lib/activerecord/tablefree.rb
|
284
|
+
- lib/activerecord/tablefree/cast_type.rb
|
285
|
+
- lib/activerecord/tablefree/connection.rb
|
286
|
+
- lib/activerecord/tablefree/schema_cache.rb
|
287
|
+
- lib/activerecord/tablefree/transaction.rb
|
288
|
+
- lib/activerecord/tablefree/version.rb
|
289
|
+
- spec/activerecord/tablefree/version_spec.rb
|
290
|
+
- spec/activerecord/tablefree_spec.rb
|
284
291
|
- spec/spec_helper.rb
|
285
292
|
homepage: https://github.com/boltthreads/activerecord-tablefree
|
286
293
|
licenses:
|
@@ -315,5 +322,6 @@ test_files:
|
|
315
322
|
- features/support/paths.rb
|
316
323
|
- features/support/rails.rb
|
317
324
|
- features/support/selectors.rb
|
318
|
-
- spec/
|
325
|
+
- spec/activerecord/tablefree/version_spec.rb
|
326
|
+
- spec/activerecord/tablefree_spec.rb
|
319
327
|
- spec/spec_helper.rb
|