make 0.2.8 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/make/form.rb +20 -21
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13d4a9d819e59a3736ad889e48f6b64093215cd5
4
- data.tar.gz: 859571be189a93332bafd94f477eb6efe811bc2d
3
+ metadata.gz: 7bcc508e38182d88b21adc2c6e071d361fd41591
4
+ data.tar.gz: a157388fabe661e035b6bd0801a46456979bc094
5
5
  SHA512:
6
- metadata.gz: e5bd0d1e3ef3389855bff0dbb53113c48033d26df40bda17674cb2c4009b28686363624fe2ea4ddbe0e627eab1565bb370b18c321e8a2f961a6ba54a86687bff
7
- data.tar.gz: 6d5db6e0b775102a84935cd1743748d0f781e0595272e5b63adaa81cb38ef5aad2eb7031ef99bc1888a4345eb3c8da14f5db51cfcc4fa1a44c5191f2861830c3
6
+ metadata.gz: 96901320b5bdd5a306039d8a7a8a01725405c4890d679ec4f73ba9da13182710395b58bcf943e825604564f0f89dfec1e002673dca75aa7c550778842e739058
7
+ data.tar.gz: 8a67532d917365db39a2ed53a5722f899e7b8e8657c911e992d58232ff7a1adc512b78340d43bec9d5a2242c94666391b270001a04cb86346010d271573659d3
@@ -66,36 +66,32 @@ class Form
66
66
  def select column, array, assoc = false
67
67
  columnName = column.titleize
68
68
  input = "\n\t<label>" + columnName + "\n\t</label>\n\t<select name=\"" + @modelName + "[" + column + "]\">"
69
- if assoc #if association is checked true
70
- array.each do |id|
71
- val = column[0...-3].capitalize.constantize.find(id).attributes.values[1]
72
- input += "\n\t\t\t<option value=\"" + id.to_s + "\">" + val.to_s + "</option>"
73
- end
74
- else #if no associations exist for array
75
- array.each do |item|
76
- input += "\n\t\t\t<option value=\"" + item.to_s + "\">" + item.to_s + "</option>"
77
- end
78
- end
69
+ input += "\n\t\t\t<option value=\"" + item.to_s + "\">" + item.to_s + "</option>"
79
70
  @potential_keys_to_ignore.push(column)
80
71
  input += "\n\t</select>"
81
72
  @formMiddle.push(input)
82
73
  return self
83
74
  end
84
75
  # Similar to select, but association assumed and specific associated column name can be selected
85
- def assoc column, assocColumn, array='all'
76
+ def assoc column, assoc_column, assoc_model=nil
77
+ # titleize column
86
78
  columnName = column.titleize
79
+ # Create for input
87
80
  input = "\n\t<label>" + columnName + "\n\t</label>\n\t<select name=\"" + @modelName + "[" + column + "]\">"
88
- assocModel = column[0...-3].capitalize.constantize
89
- array = assocModel.distinct.count('id')
90
- assocModel.attributes.each_with_index do |attribute, index|
91
- if attribute.key == assocColumn
92
- assocIndex = index
93
- end
81
+ # Remove _id and take the assocModel unless assocModel exists
82
+ if assoc_model
83
+ assoc_model = assoc_model.capitalize.constantize
84
+ else
85
+ assoc_model = column[0...-3].capitalize.constantize
94
86
  end
95
- while array > 0
96
- val = assocModel.find(id).attributes.values[assocIndex]
97
- input += "\n\t\t\t<option value=\"" + id.to_s + "\">" + val.to_s + "</option>"
98
- array --
87
+ # Keep track of how many records exist in assocModel
88
+ total = assoc_model.distinct.count('id')
89
+ # run a while loop for as many records there are
90
+ counter = 1
91
+ while counter <= total do
92
+ val = assoc_model.find(counter).attributes[assoc_column]
93
+ input += "\n\t\t\t<option value=\"" + counter.to_s + "\">" + val.to_s + "</option>"
94
+ counter+= 1
99
95
  end
100
96
  input += "\n\t</select>"
101
97
  @potential_keys_to_ignore.push(column)
@@ -129,6 +125,9 @@ class Form
129
125
  input = "\n\t<label>Confirm Password</label>\n\t<input type=\"password\" name=\"" + @modelName + "[password_confirmation]\">"
130
126
  @formMiddle.push(input)
131
127
  end
128
+ elsif column.include? 'date'
129
+ input = "\n\t<label>"+column.titleize+"</label>\n\t<input type=\"date\" name=\"" + @modelName + "[" + column + "]\">"
130
+ @formMiddle.push(input)
132
131
  else
133
132
  input = "\n\t<label>" + column.titleize + "\n\t</label>\n\t<input type=\"text\" name=\"" + @modelName + "[" + column + "]\">"
134
133
  @formMiddle.push(input)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: make
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sara Wong