Skip to content

Commit

Permalink
Ensure methods with kwargs are invertible
Browse files Browse the repository at this point in the history
  • Loading branch information
segiddins committed Apr 4, 2023
1 parent 0d2e6e5 commit 14432de
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 52 deletions.
71 changes: 21 additions & 50 deletions lib/timescaledb/rails/extensions/active_record/command_recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,27 @@ module Rails
module ActiveRecord
# :nodoc:
module CommandRecorder
def create_hypertable(*args, &block)
record(:create_hypertable, args, &block)
end

def enable_hypertable_compression(*args, &block)
record(:enable_hypertable_compression, args, &block)
end

def disable_hypertable_compression(*args, &block)
record(:disable_hypertable_compression, args, &block)
end

def add_hypertable_compression_policy(*args, &block)
record(:add_hypertable_compression_policy, args, &block)
end

def remove_hypertable_compression_policy(*args, &block)
record(:remove_hypertable_compression_policy, args, &block)
end

def add_hypertable_reorder_policy(*args, &block)
record(:add_hypertable_reorder_policy, args, &block)
end

def remove_hypertable_reorder_policy(*args, &block)
record(:remove_hypertable_reorder_policy, args, &block)
end

def add_hypertable_retention_policy(*args, &block)
record(:add_hypertable_retention_policy, args, &block)
end

def remove_hypertable_retention_policy(*args, &block)
record(:remove_hypertable_retention_policy, args, &block)
end

def create_continuous_aggregate(*args, &block)
record(:create_continuous_aggregate, args, &block)
end

def drop_continuous_aggregate(*args, &block)
record(:drop_continuous_aggregate, args, &block)
end

def add_continuous_aggregate_policy(*args, &block)
record(:add_continuous_aggregate_policy, args, &block)
end

def remove_continuous_aggregate_policy(*args, &block)
record(:remove_continuous_aggregate_policy, args, &block)
%w[
create_hypertable
enable_hypertable_compression
disable_hypertable_compression
add_hypertable_compression_policy
remove_hypertable_compression_policy
add_hypertable_reorder_policy
remove_hypertable_reorder_policy
add_hypertable_retention_policy
remove_hypertable_retention_policy
create_continuous_aggregate
drop_continuous_aggregate
add_continuous_aggregate_policy
remove_continuous_aggregate_policy
].each do |method|
module_eval <<-METHOD, __FILE__, __LINE__ + 1
def #{method}(*args, &block) # def create_table(*args, &block)
record(:"#{method}", args, &block) # record(:create_table, args, &block)
end # end
METHOD
ruby2_keywords(method)
end

def invert_create_hypertable(args, &block)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def enable_hypertable_compression(table_name, segment_by: nil, order_by: nil)
#
# disable_hypertable_compression('events')
#
def disable_hypertable_compression(table_name, _segment_by: nil, _order_by: nil)
def disable_hypertable_compression(table_name, segment_by: nil, order_by: nil) # rubocop:disable Lint/UnusedMethodArgument
execute "ALTER TABLE #{table_name} SET (timescaledb.compress = false);"
end

Expand Down Expand Up @@ -131,7 +131,7 @@ def create_continuous_aggregate(view_name, view_query, force: false)
#
# drop_continuous_aggregate('temperature_events')
#
def drop_continuous_aggregate(view_name, _view_query = nil)
def drop_continuous_aggregate(view_name, _view_query = nil, force: false) # rubocop:disable Lint/UnusedMethodArgument
execute "DROP MATERIALIZED VIEW #{view_name};"
end

Expand Down

0 comments on commit 14432de

Please sign in to comment.