Module: ActiveData::Model::Primary::ClassMethods

Defined in:
lib/active_data/model/primary.rb

Instance Method Summary collapse

Instance Method Details

#has_primary_attribute?Boolean

Returns:



30
31
32
# File 'lib/active_data/model/primary.rb', line 30

def has_primary_attribute?
  has_attribute? _primary_name
end

#primary(*args) ⇒ Object Also known as: primary_attribute



19
20
21
22
23
24
25
26
27
# File 'lib/active_data/model/primary.rb', line 19

def primary *args
  options = args.extract_options!
  self._primary_name = (args.first.presence || ActiveData.primary_attribute).to_s
  unless has_attribute?(_primary_name)
    options.merge!(type: args.second) if args.second
    attribute _primary_name, options.presence || DEFAULT_PRIMARY_ATTRIBUTE_OPTIONS.call
  end
  alias_attribute :primary_attribute, _primary_name
end

#primary_nameObject



34
35
36
# File 'lib/active_data/model/primary.rb', line 34

def primary_name
  _primary_name
end