Module: AWS::Record::AbstractBase::ClassMethods

Defined in:
lib/aws/record/abstract_base.rb

Instance Method Summary collapse

Instance Method Details

#attributesHash<String,Attribute>

Returns a hash of all of the configured attributes for this class.

Returns:

  • (Hash<String,Attribute>)

    Returns a hash of all of the configured attributes for this class.



579
580
581
# File 'lib/aws/record/abstract_base.rb', line 579

def attributes
  @attributes ||= {}
end

#optimistic_locking(attribute_name = :version_id) ⇒ Object



561
562
563
564
# File 'lib/aws/record/abstract_base.rb', line 561

def optimistic_locking attribute_name = :version_id
  attribute = integer_attr(attribute_name)
  @optimistic_locking_attr = attribute
end

#optimistic_locking?Boolean

Returns true if this class is configured to perform optimistic locking.

Returns:

  • (Boolean)

    Returns true if this class is configured to perform optimistic locking.



568
569
570
# File 'lib/aws/record/abstract_base.rb', line 568

def optimistic_locking?
  !!@optimistic_locking_attr
end

#optimistic_locking_attrObject



573
574
575
# File 'lib/aws/record/abstract_base.rb', line 573

def optimistic_locking_attr
  @optimistic_locking_attr
end

#scope(name, scope = nil, &block) ⇒ Object

Adds a scoped finder to this class.

class Book < AWS::Record::Model
  scope :top_10, order(:popularity, :desc).limit(10) 
end

Book.top_10.to_a
#=> [#<Book...>, #<Book...>]

Book.top_10.first
#=> #<Book...>

You can also provide a block that accepts params for the scoped finder. This block should return a scope.

class Book < AWS::Record::Model
  scope :by_author, lambda {|name| where(:author => name) }
end

# top 10 books by the author 'John Doe'
Book.by_author('John Doe').top_10

Parameters:

  • name (Symbol)

    The name of the scope. Scope names should be method-safe and should not conflict with any other class methods.

  • scope (Scope) (defaults to: nil)


548
549
550
551
552
553
554
# File 'lib/aws/record/abstract_base.rb', line 548

def scope name, scope = nil, &block

  method_definition = scope ? lambda { scope } : block

  extend(Module.new { define_method(name, &method_definition) })

end

#set_shard_name(name) ⇒ Object Also known as: set_domain_name, shard_name=

Allows you to override the default shard name for this class. The shard name defaults to the class name.

Parameters:

  • name (String)


502
503
504
# File 'lib/aws/record/abstract_base.rb', line 502

def set_shard_name name
  @_shard_name = name
end

#shard_name(name = nil) ⇒ String Also known as: domain_name

Returns the name of the shard this class will persist records into by default.

Parameters:

  • name (String) (defaults to: nil)

    Defaults to the name of this class.

Returns:

  • (String)

    Returns the full prefixed domain name for this class.



513
514
515
516
517
518
# File 'lib/aws/record/abstract_base.rb', line 513

def shard_name name = nil
  name = @_shard_name if name.nil?
  name = self.name if name.nil?
  name = name.name if name.is_a?(Core::Model) # sdb domain or ddb table
  name
end