Class: TypeScopes
- Inherits:
-
Object
show all
- Defined in:
- lib/type_scopes.rb,
lib/type_scopes/version.rb
Defined Under Namespace
Classes: Boolean, Numeric, String, Time
Constant Summary
collapse
- VERSION =
"0.6.0".freeze
Class Method Summary
collapse
Class Method Details
.append_scope(model, name, block) ⇒ Object
13
14
15
|
# File 'lib/type_scopes.rb', line 13
def self.append_scope(model, name, block)
model.scope(name, block) if !model.respond_to?(name, true)
end
|
.inject(model, column_names = model.columns.map(&:name)) ⇒ Object
2
3
4
5
6
7
8
9
10
11
|
# File 'lib/type_scopes.rb', line 2
def self.inject(model, column_names = model.columns.map(&:name))
for name in column_names
if column = model.columns_hash[name]
Time.support?(column.sql_type) && Time.inject_for_column(model, name)
String.support?(column.sql_type) && String.inject_for_column(model, name)
Numeric.support?(column.sql_type) && Numeric.inject_for_column(model, name)
Boolean.support?(column.sql_type) && Boolean.inject_for_column(model, name)
end
end
end
|
.inject_for_column(model, name) ⇒ Object
25
26
27
|
# File 'lib/type_scopes.rb', line 25
def self.inject_for_column(model, name)
raise NotImplementedError
end
|
.support?(column_type) ⇒ Boolean
17
18
19
|
# File 'lib/type_scopes.rb', line 17
def self.support?(column_type)
types.any? { |type| column_type.include?(type) }
end
|
.types ⇒ Object
21
22
23
|
# File 'lib/type_scopes.rb', line 21
def self.types
raise NotImplementedError
end
|