class Katapult::ApplicationModel
Constants
- NotFound
Attributes
associations[R]
authentication[R]
models[R]
web_uis[R]
Public Class Methods
new()
click to toggle source
# File lib/katapult/application_model.rb, line 22 def initialize @models = [] @associations = [] @web_uis = [] end
parse(application_model_string, path_to_model = '')
click to toggle source
# File lib/katapult/application_model.rb, line 16 def self.parse(application_model_string, path_to_model = '') new.tap do |model| model.instance_eval application_model_string, path_to_model end end
Public Instance Methods
association(name, options = {})
click to toggle source
# File lib/katapult/application_model.rb, line 57 def association(name, options = {}) options[:application_model] = self associations << Association.new(name, options) end
authenticate(user_model_name, system_email:)
click to toggle source
DSL
# File lib/katapult/application_model.rb, line 45 def authenticate(user_model_name, system_email:) @authentication = Authentication.new(user_model_name, system_email: system_email, application_model: self) end
crud(name, &block)
click to toggle source
DSL
# File lib/katapult/application_model.rb, line 51 def crud(name, &block) model name, &block web_ui name, &:crud end
get_belongs_tos_for(model_name)
click to toggle source
Returns all models that `model_name` belongs_to
# File lib/katapult/application_model.rb, line 72 def get_belongs_tos_for(model_name) associations.select { |a| a.name == model_name }.map(&:belongs_to_model) end
get_has_manys_for(model_name)
click to toggle source
Returns all models that `model_name` has_many of
# File lib/katapult/application_model.rb, line 77 def get_has_manys_for(model_name) associations.select { |a| a.belongs_to == model_name }.map(&:model) end
get_model!(name)
click to toggle source
# File lib/katapult/application_model.rb, line 62 def get_model!(name) models.find { |m| m.name == name } or raise NotFound, "Could not find a model named #{ name }" end
get_web_ui(name)
click to toggle source
# File lib/katapult/application_model.rb, line 67 def get_web_ui(name) web_uis.find { |w| w.name == name } end
model(name, &block)
click to toggle source
DSL
# File lib/katapult/application_model.rb, line 29 def model(name, &block) models << Model.new(name, application_model: self, &block) end
render(options = {})
click to toggle source
# File lib/katapult/application_model.rb, line 81 def render(options = {}) prepare_render models.each { |m| m.render(options) } web_uis.each { |w| w.render(options) } nav.render(options) if nav authentication.render(options) if authentication end
web_ui(name, options = {}, &block)
click to toggle source
DSL
# File lib/katapult/application_model.rb, line 34 def web_ui(name, options = {}, &block) options[:application_model] = self web_uis << WebUI.new(name, options, &block) end
Private Instance Methods
prepare_render()
click to toggle source
# File lib/katapult/application_model.rb, line 92 def prepare_render authentication &.ensure_user_model_attributes_present models.each do |model| belongs_tos = get_belongs_tos_for(model.name) model.add_foreign_key_attrs(belongs_tos) end end