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

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

Instance Method Summary collapse

Instance Method Details

#has_primary_attribute?Boolean

rubocop:disable Naming/PredicateName

Returns:



32
33
34
# File 'lib/active_data/model/primary.rb', line 32

def has_primary_attribute? # rubocop:disable Naming/PredicateName
  has_attribute? _primary_name
end

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



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

def primary(*args)
  options = args.extract_options!
  self._primary_name = (args.first.presence || ActiveData.primary_attribute).to_s
  unless has_attribute?(_primary_name)
    options[: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



36
37
38
# File 'lib/active_data/model/primary.rb', line 36

def primary_name
  _primary_name
end