Module: Granite::Form::Model::Primary::ClassMethods

Defined in:
lib/granite/form/model/primary.rb

Instance Method Summary collapse

Instance Method Details

#has_primary_attribute?Boolean

rubocop:disable Naming/PredicateName

Returns:



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

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

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



22
23
24
25
26
27
28
29
30
# File 'lib/granite/form/model/primary.rb', line 22

def primary(*args)
  options = args.extract_options!
  self._primary_name = (args.first.presence || Granite::Form.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



38
39
40
# File 'lib/granite/form/model/primary.rb', line 38

def primary_name
  _primary_name
end