Class: Faalis::Dashboard::DSL::Create

Inherits:
Base
  • Object
show all
Defined in:
lib/faalis/dashboard/dsl/create.rb

Instance Attribute Summary

Attributes inherited from Base

#action_buttons, #default_scope, #fields, #model

Instance Method Summary collapse

Methods inherited from Base

#action_button, #attributes, #scope

Constructor Details

#initialize(model) ⇒ Create

Returns a new instance of Create



6
7
8
9
# File 'lib/faalis/dashboard/dsl/create.rb', line 6

def initialize(model)
  super
  @field_details = {}
end

Instance Method Details

#_field_detailsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/faalis/dashboard/dsl/create.rb', line 29

def _field_details
  details = @field_details.dup

  fields_for_form.each do |field|
    if !details.include? field.to_sym

      type = guess_field_type(field)
      details[field.to_sym] = initialize_field(field.to_sym, type)
    end
  end

  details
end

#attributes_properties(**options) ⇒ Object

Specify attributes details, for example if you want to change a datetime field type to string you need to do like this:

in_form do
  attributes_properties date: { as: :string }
end


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/faalis/dashboard/dsl/create.rb', line 17

def attributes_properties(**options)
  options_set = Set.new options.keys.map(&:to_s)

  unless options_set.subset? Set.new(@fields)
    fail "You have to provide correct attribute names in" +
         "'attributes_properties' for '#{@model}'."
  end

  # TODO: Check for valid value for each key
  @field_details = options || {}
end

#fields_for_formObject



43
44
45
46
47
48
49
50
51
# File 'lib/faalis/dashboard/dsl/create.rb', line 43

def fields_for_form
  fields_name = @fields.dup

  fields_name.delete('id')
  fields_name.delete('created_at')
  fields_name.delete('updated_at')

  fields_name
end