Class: Carload::Dashboard
- Inherits:
-
Object
- Object
- Carload::Dashboard
- Defined in:
- lib/carload/dashboard.rb
Direct Known Subclasses
Class Method Summary collapse
- .associate(options) ⇒ Object
- .default_model ⇒ Object
- .model(name, &block) ⇒ Object
- .models ⇒ Object
- .write(file_path) ⇒ Object
Class Method Details
.associate(options) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/carload/dashboard.rb', line 17 def associate model_a = .keys.first model_b = .values.first .shift @@models[model_a].associations[model_b] = end |
.default_model ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/carload/dashboard.rb', line 28 def default_model return @@default_model if defined? @@default_model @@models.each do |name, spec| return @@default_model = name if spec.default end @@default_model = @@models.keys.first end |
.model(name, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/carload/dashboard.rb', line 4 def model name, &block name = name.to_sym if block_given? @@models ||= {} spec = @@models[name] || ModelSpec.new spec.name = name yield spec @@models[name] = spec else @@models[name] end end |
.models ⇒ Object
24 25 26 |
# File 'lib/carload/dashboard.rb', line 24 def models @@models ||= {} end |
.write(file_path) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/carload/dashboard.rb', line 36 def write file_path content = File.read("#{Carload::Engine.root}/lib/generators/carload/templates/dashboard.rb") content.gsub!(/^end$/, '') default = true models.each do |name, spec| content << " model :\#{name} do |spec|\n spec.default = \#{default}\n spec.attributes.permitted = \#{spec.attributes.permitted}\n spec.index_page.shows.attributes = \#{spec.index_page.shows.attributes}\n spec.index_page.searches.attributes = \#{spec.index_page.searches.attributes}\n end\n RUBY\n default = false\n next if spec.associations.empty?\n spec.associations.each_value do |association|\n next unless association[:choose_by]\n reflection = association[:reflection]\n content << <<-RUBY\n associate(\#{{ name.to_sym => reflection.name, choose_by: association[:choose_by] }})\n RUBY\n end\n end\n content << \"end\\n\"\n File.open('app/carload/dashboard.rb', 'w') do |file|\n file.write content\n file.close\n end\nend\n" |