Class: Jav::Dsl::FieldParser

Inherits:
Object
  • Object
show all
Defined in:
lib/jav/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.



6
7
8
9
10
11
12
13
# File 'lib/jav/dsl/field_parser.rb', line 6

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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



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

def args
  @args
end

#asObject (readonly)

Returns the value of attribute as.



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

def as
  @as
end

#blockObject (readonly)

Returns the value of attribute block.



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

def block
  @block
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#instanceObject (readonly)

Returns the value of attribute instance.



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

def instance
  @instance
end

#order_indexObject (readonly)

Returns the value of attribute order_index.



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

def order_index
  @order_index
end

Instance Method Details

#invalid?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/jav/dsl/field_parser.rb', line 19

def invalid?
  !valid?
end

#parseObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/jav/dsl/field_parser.rb', line 23

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)


15
16
17
# File 'lib/jav/dsl/field_parser.rb', line 15

def valid?
  instance.present?
end