Class: Property::Role

Inherits:
Object
  • Object
show all
Includes:
RoleModule
Defined in:
lib/property/role.rb

Overview

The Role holds information on a group of property columns. The “Role” is used in the same way as the ruby Module: as a mixin. The Schema class “includes” roles.

Direct Known Subclasses

Schema

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RoleModule

#column_names, #columns, #defined_columns, #defined_indices, #has_column?, #index, #inspect, #name, #property, #serialize, #used_in, #used_keys_in

Constructor Details

#initialize(name, opts = nil) ⇒ Role

Initialize a new role with the given name



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

def initialize(name, opts = nil)
  @name = name
end

Class Method Details

.new(name, opts = nil, &block) ⇒ Object

Create a new role. If a block is provided, this block can be used to define properties:

Example:

@role = Role.new('Poet') do |p|
  p.string :muse
end


17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/property/role.rb', line 17

def self.new(name, opts = nil, &block)
  if name.kind_of?(Hash)
    obj = super(name[:name] || name['name'], opts)
  else
    obj = super(name, opts)
  end

  if block_given?
    obj.property(&block)
  end
  obj
end