module Scopiform::Core::ClassMethods
Attributes
scopiform_ctx[RW]
Public Instance Methods
alias_attribute(new_name, old_name)
click to toggle source
Calls superclass method
# 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)
click to toggle source
# 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)
click to toggle source
# 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_scopes()
click to toggle source
# File lib/scopiform/core.rb, line 13 def auto_scopes @auto_scopes || [] end
auto_scopes_by_attribute(attribute)
click to toggle source
# 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(definitions)
click to toggle source
Calls superclass method
# File lib/scopiform/core.rb, line 44 def enum(definitions) super(definitions) definitions.each_key { |name| update_scope_to_enum(name) } end
Private Instance Methods
auto_scope_add_definition(attribute, **options)
click to toggle source
# File lib/scopiform/core.rb, line 69 def auto_scope_add_definition(attribute, **options) definition = ScopeDefinition.new(attribute, **options) @auto_scopes ||= [] @auto_scopes << definition definition end
auto_scope_for_alias(alias_name, scope_definition)
click to toggle source
# File lib/scopiform/core.rb, line 77 def auto_scope_for_alias(alias_name, scope_definition) alias_scope_definition = scope_definition.dup alias_scope_definition.attribute = alias_name.to_sym @auto_scopes ||= [] @auto_scopes << alias_scope_definition singleton_class.send(:alias_method, alias_scope_definition.name, scope_definition.name) end
update_scope_to_enum(name)
click to toggle source
# File lib/scopiform/core.rb, line 52 def update_scope_to_enum(name) scopes = auto_scopes_by_attribute(name) scopes.each do |scope| if scope.options[:type].blank? argument_type = scope.options[:argument_type] scope.options[:argument_type] = argument_type.is_a?(Array) ? [:string] : :string if argument_type scope.options[:type] = :enum end if scope.options[:remove_for_enum] singleton_class.send(:remove_method, scope.name) @auto_scopes.delete(scope) end end end