Class: Purview::Columns::Base
Instance Attribute Summary collapse
Instance Method Summary
collapse
#blank?, #coalesced, #filter_blank_values, #filter_nil_values, #present?, #timestamp, #with_timestamp, #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
|
# File 'lib/purview/columns/base.rb', line 35
def parse(value)
blank = blank?(value)
raise %{Unexpected blank value for column: "#{name}"} if blank && !nullable?
blank ? nil : type.parse(value)
end
|
#primary_key ⇒ Object
41
42
43
|
# File 'lib/purview/columns/base.rb', line 41
def primary_key
opts[:primary_key]
end
|
#primary_key? ⇒ Boolean
45
46
47
|
# File 'lib/purview/columns/base.rb', line 45
def primary_key?
!!primary_key
end
|
49
50
51
|
# File 'lib/purview/columns/base.rb', line 49
def type
coalesced(opts[:type], Purview::Types::String)
end
|