Class: BooleanField
- Inherits:
-
Field
- Object
- Field
- BooleanField
show all
- Defined in:
- lib/generators/hot_glue/fields/boolean_field.rb
Instance Attribute Summary
Attributes inherited from Field
#alt_lookup, #assoc_class, #assoc_label, #assoc_model, #assoc_name, #associations, #attachment_data, #auth, #class_name, #default_boolean_display, #display_as, #form_labels_position, #form_placeholder_labels, #god, #hawk_keys, #hidden_create, #hidden_update, #layout_strategy, #limit, #modify_as, #name, #namespace, #object, #ownership_field, #plural, #polymorphic_parents, #pundit, #sample_file_path, #self_auth, #singular, #singular_class, #sql_type, #stimmify, #update_show_only
Instance Method Summary
collapse
Methods inherited from Field
#code_to_reset_match_if_search_is_blank, #display_boolean_as, #field_error_name, #field_output, #field_view_output, #form_show_only_output, #getName, #hidden_output, #initialize, #modified_display_output, #modify_binary?, #newline_after_field?, #prelookup_syntax, #spec_list_view_natural_assertion, #spec_random_data, #spec_related_column_lets, #testing_name, #text_area_output, #viewable_output
Constructor Details
This class inherits a constructor from Field
Instance Method Details
#checkbox_display ⇒ Object
31
32
33
|
# File 'lib/generators/hot_glue/fields/boolean_field.rb', line 31
def checkbox_display
"<%= f.check_box(:#{name}, class: '#{@layout_strategy.form_checkbox_input_class}', id: '#{singular}_#{name}', checked: #{singular}.#{name}) %>\n"
end
|
#falsy_value ⇒ Object
81
82
83
|
# File 'lib/generators/hot_glue/fields/boolean_field.rb', line 81
def falsy_value
modify_as[:binary][:falsy] || 'No'
end
|
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/generators/hot_glue/fields/boolean_field.rb', line 39
def form_field_display
if display_boolean_as.nil?
end
"<span class='#{@layout_strategy.form_checkbox_wrapper_class} #{'form-switch' if display_boolean_as == 'switch'}'>\n" +
(if display_boolean_as == 'radio'
radio_button_display
elsif display_boolean_as == 'checkbox'
checkbox_display
elsif display_boolean_as == 'switch'
switch_display
end) + "</span> \n"
end
|
53
54
55
|
# File 'lib/generators/hot_glue/fields/boolean_field.rb', line 53
def form_field_output
form_field_display
end
|
#label_class ⇒ Object
85
86
87
|
# File 'lib/generators/hot_glue/fields/boolean_field.rb', line 85
def label_class
super + " form-check-label"
end
|
#label_for ⇒ Object
20
21
22
|
# File 'lib/generators/hot_glue/fields/boolean_field.rb', line 20
def label_for
"#{singular}_#{name}"
end
|
#line_field_output ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/generators/hot_glue/fields/boolean_field.rb', line 57
def line_field_output
if modify_binary?
"<% if #{singular}.#{name}.nil? %>
<span class=''>MISSING</span>
<% elsif #{singular}.#{name} %>
#{modify_as[:binary][:truthy]}
<% else %>
#{modify_as[:binary][:falsy]}
<% end %>"
else
"<% if #{singular}.#{name}.nil? %>
<span class=''>MISSING</span>
<% elsif #{singular}.#{name} %>
YES
<% else %>
NO
<% end %>"
end
end
|
#load_all_query_statement ⇒ Object
105
106
107
|
# File 'lib/generators/hot_glue/fields/boolean_field.rb', line 105
def load_all_query_statement
"#{name}_query = boolean_query_constructor(:#{name}, @q['0'][:#{name}_match])"
end
|
24
25
26
27
28
29
|
# File 'lib/generators/hot_glue/fields/boolean_field.rb', line 24
def radio_button_display
" <%= f.radio_button(:#{name}, '0', checked: #{singular}.#{name} ? '' : 'checked', class: '#{@layout_strategy.form_checkbox_input_class}') %>\n" +
" <%= f.label(:#{name}, value: '#{modify_binary? && modify_as[:binary][:falsy] || 'No'}', for: '#{singular}_#{name}_0') %>\n" +
" <br /> <%= f.radio_button(:#{name}, '1', checked: #{singular}.#{name} ? 'checked' : '' , class: '#{@layout_strategy.form_checkbox_input_class}') %>\n" +
" <%= f.label(:#{name}, value: '#{modify_binary? && modify_as[:binary][:truthy] || 'Yes'}', for: '#{singular}_#{name}_1') %>\n"
end
|
#search_field_output ⇒ Object
91
92
93
94
95
96
97
98
|
# File 'lib/generators/hot_glue/fields/boolean_field.rb', line 91
def search_field_output
" <%= f.radio_button('q[0][#{name}_match]', '-1', checked: @q[\'0\'][:#{name}_match]=='-1' ? 'checked' : '', class: '#{@layout_strategy.form_checkbox_input_class}') %>\n" +
" <%= f.label('All', value: '-1', for: 'q[0][#{name}_match]_-1' ) %>\n" +
" <%= f.radio_button('q[0][#{name}_match]', '0', checked: @q[\'0\'][:#{name}_match]=='0' ? 'checked' : '', class: '#{@layout_strategy.form_checkbox_input_class}') %>\n" +
" <%= f.label('#{falsy_value}', value: '0', for: 'q[0][#{name}_match]_0') %>\n" +
" <br /> <%= f.radio_button('q[0][#{name}_match]', '1', checked: @q[\'0\'][:#{name}_match]=='1' ? 'checked' : '' , class: '#{@layout_strategy.form_checkbox_input_class}') %>\n" +
" <%= f.label('#{truthy_value}', value: '1', for: 'q[0][#{name}_match]_1') %>\n"
end
|
#spec_list_view_assertion ⇒ Object
16
17
18
|
# File 'lib/generators/hot_glue/fields/boolean_field.rb', line 16
def spec_list_view_assertion
["expect(page).to have_content(#{singular}#{1}.#{name} ? 'YES' : 'NO')"].join("\n ")
end
|
#spec_make_assertion ⇒ Object
8
9
10
|
# File 'lib/generators/hot_glue/fields/boolean_field.rb', line 8
def spec_make_assertion
["expect(page).to have_content(#{singular}#{1}.#{name} ? 'YES' : 'NO')"].join("\n ")
end
|
#spec_setup_and_change_act(which_partial = nil) ⇒ Object
3
4
5
6
|
# File 'lib/generators/hot_glue/fields/boolean_field.rb', line 3
def spec_setup_and_change_act(which_partial = nil)
" new_#{name} = 1 \n" +
" find(\"[name='#{testing_name}[#{name}]'][value='\#{new_" + name.to_s + "}']\").choose"
end
|
#spec_setup_let_arg ⇒ Object
12
13
14
|
# File 'lib/generators/hot_glue/fields/boolean_field.rb', line 12
def spec_setup_let_arg
"#{name}: !!rand(2).floor"
end
|
#switch_display ⇒ Object
35
36
37
|
# File 'lib/generators/hot_glue/fields/boolean_field.rb', line 35
def switch_display
"<%= f.check_box(:#{name}, class: '#{@layout_strategy.form_checkbox_input_class}', role: 'switch', id: '#{singular}_#{name}', checked: #{singular}.#{name}) %>\n"
end
|
#truthy_value ⇒ Object
77
78
79
|
# File 'lib/generators/hot_glue/fields/boolean_field.rb', line 77
def truthy_value
modify_as[:binary][:truthy] || 'Yes'
end
|
#where_query_statement ⇒ Object
101
102
103
|
# File 'lib/generators/hot_glue/fields/boolean_field.rb', line 101
def where_query_statement
".where(#{name}_query)"
end
|