Module: Scopiform::Core::ClassMethods

Defined in:
lib/scopiform/core.rb

Instance Method Summary collapse

Instance Method Details

#alias_attribute(new_name, old_name) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/scopiform/core.rb', line 34

def alias_attribute(new_name, old_name)
  super(new_name, old_name)

  auto_scopes_by_attribute(old_name).each do |scope_definition|
    auto_scope_for_alias(new_name, scope_definition)
  end
end

#auto_scope?(name) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/scopiform/core.rb', line 20

def auto_scope?(name)
  auto_scopes.find { |scope| scope.name == name }.present?
end

#auto_scope_add(attribute, block, prefix: nil, suffix: nil, **options) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/scopiform/core.rb', line 24

def auto_scope_add(attribute, block, prefix: nil, suffix: nil, **options)
  scope_definition = auto_scope_add_definition(attribute, prefix: prefix, suffix: suffix, **options)

  scope scope_definition.name, block

  aliases_for(attribute).each do |alias_name|
    auto_scope_for_alias(alias_name, scope_definition)
  end
end

#auto_scopesObject



11
12
13
# File 'lib/scopiform/core.rb', line 11

def auto_scopes
  @auto_scopes || []
end

#auto_scopes_by_attribute(attribute) ⇒ Object



15
16
17
18
# File 'lib/scopiform/core.rb', line 15

def auto_scopes_by_attribute(attribute)
  attribute = attribute.to_sym
  auto_scopes.select { |scope| scope.attribute == attribute }
end

#enum(definitions) ⇒ Object



42
43
44
45
46
# File 'lib/scopiform/core.rb', line 42

def enum(definitions)
  super(definitions)

  definitions.each_key { |name| update_scope_to_enum(name) }
end