Class: Avo::Dsl::FieldParser

Inherits:
Object
  • Object
show all
Defined in:
lib/avo/dsl/field_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, order_index: 0, **args, &block) ⇒ FieldParser

Returns a new instance of FieldParser.



11
12
13
14
15
16
17
18
# File 'lib/avo/dsl/field_parser.rb', line 11

def initialize(id:, order_index: 0, **args, &block)
  @id = id
  @as = args.fetch(:as, :text)
  @order_index = order_index
  @args = args
  @block = block
  @instance = nil
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



5
6
7
# File 'lib/avo/dsl/field_parser.rb', line 5

def args
  @args
end

#asObject (readonly)

Returns the value of attribute as.



4
5
6
# File 'lib/avo/dsl/field_parser.rb', line 4

def as
  @as
end

#blockObject (readonly)

Returns the value of attribute block.



7
8
9
# File 'lib/avo/dsl/field_parser.rb', line 7

def block
  @block
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/avo/dsl/field_parser.rb', line 6

def id
  @id
end

#instanceObject (readonly)

Returns the value of attribute instance.



8
9
10
# File 'lib/avo/dsl/field_parser.rb', line 8

def instance
  @instance
end

#order_indexObject (readonly)

Returns the value of attribute order_index.



9
10
11
# File 'lib/avo/dsl/field_parser.rb', line 9

def order_index
  @order_index
end

Instance Method Details

#invalid?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/avo/dsl/field_parser.rb', line 24

def invalid?
  !valid?
end

#parseObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/avo/dsl/field_parser.rb', line 28

def parse
  # The field is passed as a symbol eg: :text, :color_picker, :trix
  @instance = if as.is_a? Symbol
    parse_from_symbol
  elsif as.is_a? Class
    parse_from_class
  end

  self
end

#valid?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/avo/dsl/field_parser.rb', line 20

def valid?
  instance.present?
end