Module: Scopiform::Core::ClassMethods

Defined in:
lib/scopiform/core.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#scopiform_ctxObject

Returns the value of attribute scopiform_ctx.



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

def scopiform_ctx
  @scopiform_ctx
end

Instance Method Details

#alias_attribute(new_name, old_name) ⇒ Object



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

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)


22
23
24
# File 'lib/scopiform/core.rb', line 22

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

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



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

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



13
14
15
# File 'lib/scopiform/core.rb', line 13

def auto_scopes
  @auto_scopes || []
end

#auto_scopes_by_attribute(attribute) ⇒ Object



17
18
19
20
# File 'lib/scopiform/core.rb', line 17

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

#enum(name, values, **args) ⇒ Object



44
45
46
47
48
# File 'lib/scopiform/core.rb', line 44

def enum(name, values, **args)
  super(name, values, **args)

  update_scope_to_enum(name)
end