Class: Katapult::ApplicationModel
- Inherits:
-
Object
- Object
- Katapult::ApplicationModel
- Defined in:
- lib/katapult/application_model.rb
Constant Summary collapse
- NotFound =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#associations ⇒ Object
readonly
Returns the value of attribute associations.
-
#authentication ⇒ Object
readonly
Returns the value of attribute authentication.
-
#models ⇒ Object
readonly
Returns the value of attribute models.
-
#nav ⇒ Object
readonly
Returns the value of attribute nav.
-
#web_uis ⇒ Object
readonly
Returns the value of attribute web_uis.
Class Method Summary collapse
Instance Method Summary collapse
- #association(name, options = {}) ⇒ Object
-
#authenticate(user_model_name, system_email:) ⇒ Object
DSL.
-
#crud(name, &block) ⇒ Object
DSL.
-
#get_belongs_tos_for(model_name) ⇒ Object
Returns all models that ‘model_name` belongs_to.
-
#get_has_manys_for(model_name) ⇒ Object
Returns all models that ‘model_name` has_many of.
- #get_model!(name) ⇒ Object
- #get_web_ui(name) ⇒ Object
-
#initialize ⇒ ApplicationModel
constructor
A new instance of ApplicationModel.
-
#model(name, &block) ⇒ Object
DSL.
-
#navigation(name = :main) ⇒ Object
DSL.
- #render(options = {}) ⇒ Object
-
#web_ui(name, options = {}, &block) ⇒ Object
DSL.
Constructor Details
#initialize ⇒ ApplicationModel
Returns a new instance of ApplicationModel.
22 23 24 25 26 |
# File 'lib/katapult/application_model.rb', line 22 def initialize @models = [] @associations = [] @web_uis = [] end |
Instance Attribute Details
#associations ⇒ Object (readonly)
Returns the value of attribute associations.
14 15 16 |
# File 'lib/katapult/application_model.rb', line 14 def associations @associations end |
#authentication ⇒ Object (readonly)
Returns the value of attribute authentication.
14 15 16 |
# File 'lib/katapult/application_model.rb', line 14 def authentication @authentication end |
#models ⇒ Object (readonly)
Returns the value of attribute models.
14 15 16 |
# File 'lib/katapult/application_model.rb', line 14 def models @models end |
#nav ⇒ Object (readonly)
Returns the value of attribute nav.
14 15 16 |
# File 'lib/katapult/application_model.rb', line 14 def nav @nav end |
#web_uis ⇒ Object (readonly)
Returns the value of attribute web_uis.
14 15 16 |
# File 'lib/katapult/application_model.rb', line 14 def web_uis @web_uis end |
Class Method Details
.parse(application_model_string, path_to_model = '') ⇒ Object
16 17 18 19 20 |
# 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 |
Instance Method Details
#association(name, options = {}) ⇒ Object
57 58 59 60 |
# File 'lib/katapult/application_model.rb', line 57 def association(name, = {}) [:application_model] = self associations << Association.new(name, ) end |
#authenticate(user_model_name, system_email:) ⇒ Object
DSL
45 46 47 48 |
# 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) ⇒ Object
DSL
51 52 53 54 |
# 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) ⇒ Object
Returns all models that ‘model_name` belongs_to
72 73 74 |
# 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) ⇒ Object
Returns all models that ‘model_name` has_many of
77 78 79 |
# 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) ⇒ Object
62 63 64 65 |
# 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) ⇒ Object
67 68 69 |
# File 'lib/katapult/application_model.rb', line 67 def get_web_ui(name) web_uis.find { |w| w.name == name } end |
#model(name, &block) ⇒ Object
DSL
29 30 31 |
# File 'lib/katapult/application_model.rb', line 29 def model(name, &block) models << Model.new(name, application_model: self, &block) end |
#navigation(name = :main) ⇒ Object
DSL
40 41 42 |
# File 'lib/katapult/application_model.rb', line 40 def (name = :main) @nav = .new(name, application_model: self) end |
#render(options = {}) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/katapult/application_model.rb', line 81 def render( = {}) prepare_render models.each { |m| m.render() } web_uis.each { |w| w.render() } nav.render() if nav authentication.render() if authentication end |
#web_ui(name, options = {}, &block) ⇒ Object
DSL
34 35 36 37 |
# File 'lib/katapult/application_model.rb', line 34 def web_ui(name, = {}, &block) [:application_model] = self web_uis << WebUI.new(name, , &block) end |