Module: Conexa

Defined in:
lib/conexa.rb,
lib/conexa/util.rb,
lib/conexa/model.rb,
lib/conexa/errors.rb,
lib/conexa/object.rb,
lib/conexa/request.rb,
lib/conexa/version.rb,
lib/conexa/deprecation.rb,
lib/conexa/configuration.rb,
lib/conexa/resources/auth.rb,
lib/conexa/resources/bill.rb,
lib/conexa/resources/plan.rb,
lib/conexa/resources/sale.rb,
lib/conexa/resources/charge.rb,
lib/conexa/resources/person.rb,
lib/conexa/resources/result.rb,
lib/conexa/resources/account.rb,
lib/conexa/resources/address.rb,
lib/conexa/resources/company.rb,
lib/conexa/resources/product.rb,
lib/conexa/resources/contract.rb,
lib/conexa/resources/customer.rb,
lib/conexa/resources/supplier.rb,
lib/conexa/resources/pagination.rb,
lib/conexa/resources/cost_center.rb,
lib/conexa/resources/credit_card.rb,
lib/conexa/resources/legal_person.rb,
lib/conexa/resources/room_booking.rb,
lib/conexa/resources/bill_category.rb,
lib/conexa/resources/payment_method.rb,
lib/conexa/resources/recurring_sale.rb,
lib/conexa/resources/bill_subcategory.rb,
lib/conexa/resources/invoicing_method.rb,
lib/conexa/resources/receiving_method.rb,
lib/conexa/resources/service_category.rb

Defined Under Namespace

Modules: Deprecatable, Deprecation Classes: Account, Address, Auth, Bill, BillCategory, BillSubcategory, Charge, Company, ConexaError, ConexaObject, Configuration, ConnectionError, Contract, CostCenter, CreditCard, Customer, Error, InvoicingMethod, LegalPerson, MissingCredentialsError, Model, NotFound, Pagination, ParamError, PaymentMethod, Person, Plan, Product, ReadOnlyError, ReceivingMethod, RecurringSale, Request, RequestError, ResponseError, Result, RoomBooking, Sale, ServiceCategory, Supplier, Util, ValidationError

Constant Summary collapse

READ_ONLY_KEY =

Key for the block-scoped read-only override. Thread-local so a guarded block in one thread cannot relax or tighten another.

:conexa_read_only
VERSION =
"0.2.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



23
24
25
# File 'lib/conexa.rb', line 23

def configuration
  @configuration
end

Class Method Details

.api_endpointObject



31
32
33
# File 'lib/conexa.rb', line 31

def self.api_endpoint
  configuration.api_host + "/index.php/api/v2"
end

.configure {|configuration| ... } ⇒ Object

Yields:



26
27
28
29
# File 'lib/conexa.rb', line 26

def self.configure
  self.configuration ||= Configuration.new
  yield(configuration)
end

.read_only(enabled = true) ⇒ Object

Run a block with writes forbidden, then restore the previous state.

Useful for auditing or reporting code that should never mutate a tenant, without having to reconfigure the client globally.

Examples:

Conexa.read_only do
  Conexa::Charge.all(status: "pending")   # fine
  Conexa::Charge.settle(555)              # raises Conexa::ReadOnlyError
end

Parameters:

  • enabled (Boolean) (defaults to: true)

    pass false to explicitly allow writes in the block

Returns:

  • (Object)

    the block's return value



65
66
67
68
69
70
71
# File 'lib/conexa.rb', line 65

def self.read_only(enabled = true)
  previous = Thread.current[READ_ONLY_KEY]
  Thread.current[READ_ONLY_KEY] = enabled
  yield
ensure
  Thread.current[READ_ONLY_KEY] = previous
end

.read_only?Boolean

Is writing currently forbidden?

True inside a read_only block, or whenever configuration.read_only is set (which itself defaults from CONEXA_READ_ONLY).

Returns:

  • (Boolean)


45
46
47
48
49
50
# File 'lib/conexa.rb', line 45

def self.read_only?
  scoped = Thread.current[READ_ONLY_KEY]
  return scoped unless scoped.nil?

  !!configuration&.read_only
end