Module: WCC::Media::ActiveRecordShim::ClassMethods
- Defined in:
- lib/wcc/media/active_record_shim.rb
Instance Method Summary collapse
- #active_record_shim(&block) ⇒ Object
- #find(id) ⇒ Object
- #find_all(**filters) ⇒ Object
- #find_by(**filters) ⇒ Object
- #find_in_batches(options, &block) ⇒ Object
- #model_name ⇒ Object
- #table_name ⇒ Object
- #unscoped ⇒ Object
- #where(**conditions) ⇒ Object
Instance Method Details
#active_record_shim(&block) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/wcc/media/active_record_shim.rb', line 23 def active_record_shim(&block) builder = ShimBuilder.new builder.instance_eval(&block) builder.apply(self) self end |
#find(id) ⇒ Object
30 31 32 |
# File 'lib/wcc/media/active_record_shim.rb', line 30 def find(id) WCC::Media::Client.default.public_send(endpoint).find(id) end |
#find_all(**filters) ⇒ Object
34 35 36 |
# File 'lib/wcc/media/active_record_shim.rb', line 34 def find_all(**filters) WCC::Media::Client.default.public_send(endpoint).list(filters) end |
#find_by(**filters) ⇒ Object
38 39 40 41 42 |
# File 'lib/wcc/media/active_record_shim.rb', line 38 def find_by(**filters) raise ArgumentError, "You must provide at least one filter" if filters.empty? find_all(filters).first end |
#find_in_batches(options, &block) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/wcc/media/active_record_shim.rb', line 56 def find_in_batches(, &block) = ? .dup : {} batch_size = .delete(:batch_size) || 1000 filter = { limit: batch_size, offset: .delete(:start) || 0 } find_all(filter).each_slice(batch_size, &block) end |
#model_name ⇒ Object
44 45 46 |
# File 'lib/wcc/media/active_record_shim.rb', line 44 def model_name name end |
#table_name ⇒ Object
48 49 50 |
# File 'lib/wcc/media/active_record_shim.rb', line 48 def table_name endpoint end |
#unscoped ⇒ Object
52 53 54 |
# File 'lib/wcc/media/active_record_shim.rb', line 52 def unscoped yield end |
#where(**conditions) ⇒ Object
67 68 69 70 71 |
# File 'lib/wcc/media/active_record_shim.rb', line 67 def where(**conditions) # TODO: return a Query object that implements more of the ActiveRecord query interface # https://guides.rubyonrails.org/active_record_querying.html#conditions find_all(conditions) end |