Sha256: 5e9b6fe7d56b848dc0b0113f782a1220acfaf3b5ef958eff60a24c7bcaa65291

Contents?: true

Size: 694 Bytes

Versions: 3

Compression:

Stored size: 694 Bytes

Contents

module CurrencyCloud
  module Actions
    
    module Find

      def find(params={})
        response = request.get("#{self.resource}/find", params)
        mixin_class.new(self.resource, self, response)
      end
       
      def first(params={})
        entities = find((params || {}).merge(per_page: 1))
        return nil if entities.empty?

        entities.first
      end

      private
      def mixin_class
        unless CurrencyCloud.const_defined?(self.resource.capitalize)
          CurrencyCloud.const_set(self.resource.capitalize, Class.new(CurrencyCloud::ResourcefulCollection))
        end
        CurrencyCloud.const_get(self.resource.capitalize)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
currency_cloud-0.7.1 lib/currency_cloud/actions/find.rb
currency_cloud-0.7 lib/currency_cloud/actions/find.rb
currency_cloud-0.5 lib/currency_cloud/actions/find.rb