lib/pupper/model.rb in pupper-0.1.3 vs lib/pupper/model.rb in pupper-0.1.4
- old
+ new
@@ -38,21 +38,36 @@
end
class_methods do
attr_writer :primary_key, :backend, :static
+ # @overload primary_key=(identifier)
+ # Set the identifier the including model will use by default
+ # when finding or updating (defaults to `:uid`)
+ #
+ # == Parameters:
+ # identifier::
+ # A symbol refering to the identifying field in the model. e.g.
+ # `:id`.
def primary_key
@primary_key ||= :uid
end
+ # @overload static=(true_or_false)
+ # Declare whether or not the model has a corresponding API client or not.
+ # (default: `false`)
+ #
+ # == Parameters:
+ # true_or_false::
+ # `true` if the model has no API, `false` otherwise.
def static?
@static ||= false
end
def backend
+ return if static?
@backend ||= "#{model_name.name.pluralize}Client".constantize.new
rescue NameError
- return unless static?
raise NoSuchBackend, <<-ERR
Model #{model_name.name} is looking for an API client that doesn't exist!
Either a) implement the new client: