Class: Purview::Columns::Base
Instance Attribute Summary collapse
Instance Method Summary
collapse
#blank?, #coalesced, #filter_blank_values, #filter_nil_values, #present?, #zero?
Constructor Details
#initialize(name, opts = {}) ⇒ Base
Returns a new instance of Base.
6
7
8
9
|
# File 'lib/purview/columns/base.rb', line 6
def initialize(name, opts={})
@name = name.to_sym
@opts = default_opts.merge(opts)
end
|
Instance Attribute Details
Returns the value of attribute name.
4
5
6
|
# File 'lib/purview/columns/base.rb', line 4
def name
@name
end
|
Instance Method Details
11
12
13
|
# File 'lib/purview/columns/base.rb', line 11
def default
opts[:default]
end
|
15
16
17
|
# File 'lib/purview/columns/base.rb', line 15
def default?
!!default
end
|
19
20
21
|
# File 'lib/purview/columns/base.rb', line 19
def limit
opts[:limit]
end
|
23
24
25
|
# File 'lib/purview/columns/base.rb', line 23
def limit?
!!limit
end
|
27
28
29
|
# File 'lib/purview/columns/base.rb', line 27
def nullable
coalesced(opts[:nullable], true)
end
|
31
32
33
|
# File 'lib/purview/columns/base.rb', line 31
def nullable?
!!nullable
end
|
#parse(value) ⇒ Object
35
36
37
38
39
40
|
# File 'lib/purview/columns/base.rb', line 35
def parse(value)
blank = blank?(value)
return nil if blank && nullable?
raise %{Unexpected blank value for column: "#{name}"} if blank
type.parse(value)
end
|
#primary_key ⇒ Object
42
43
44
|
# File 'lib/purview/columns/base.rb', line 42
def primary_key
opts[:primary_key]
end
|
#primary_key? ⇒ Boolean
46
47
48
|
# File 'lib/purview/columns/base.rb', line 46
def primary_key?
!!primary_key
end
|
50
51
52
|
# File 'lib/purview/columns/base.rb', line 50
def type
coalesced(opts[:type], Purview::Types::String)
end
|