class LHS::Record
Constants
- DEFAULT_LIMIT
Public Class Methods
build(data = nil)
click to toggle source
# File lib/lhs/record.rb, line 93 def self.build(data = nil) new(data) end
new(data = nil, apply_customer_setters = true)
click to toggle source
# File lib/lhs/record.rb, line 82 def initialize(data = nil, apply_customer_setters = true) data ||= LHS::Data.new({}, nil, self.class) data = LHS::Data.new(data, nil, self.class) unless data.is_a?(LHS::Data) define_singleton_method(:_data) { data } apply_custom_setters! if apply_customer_setters end
stub_all(url, items, options = {})
click to toggle source
# File lib/lhs/test/stubbable_records.rb, line 9 def self.stub_all(url, items, options = {}) extend WebMock::API items.each_slice(DEFAULT_LIMIT).with_index do |(*batch), index| uri = LocalUri::URI.new(url) uri.query.merge!( limit_key(:parameter) => DEFAULT_LIMIT ) offset = pagination_class.page_to_offset(index + 1, DEFAULT_LIMIT) unless index.zero? uri.query.merge!( pagination_key(:parameter) => offset ) end request_stub = stub_request(:get, uri.to_s) request_stub.with(options) if options.present? request_stub.to_return( body: { items: batch, offset: index.zero? ? 0 : offset, total: items.length }.to_json ) end end
Public Instance Methods
as_json(options = nil)
click to toggle source
# File lib/lhs/record.rb, line 89 def as_json(options = nil) _data.as_json(options) end
dup()
click to toggle source
Override Object#dup because it doesn't support copying any singleton methods, which leads to missing `_data` method when you execute `dup`.
# File lib/lhs/record.rb, line 99 def dup clone end
Protected Instance Methods
method_missing(name, *args, &block)
click to toggle source
# File lib/lhs/record.rb, line 105 def method_missing(name, *args, &block) _data.send(name, *args, &block) end
respond_to_missing?(name, include_all = false)
click to toggle source
# File lib/lhs/record.rb, line 109 def respond_to_missing?(name, include_all = false) _data.respond_to_missing?(name, include_all) end