Class: Crudboy::Model
Instance Attribute Summary collapse
-
#active_record_model ⇒ Object
Returns the value of attribute active_record_model.
-
#columns(**options) ⇒ Object
Returns the value of attribute columns.
-
#name ⇒ Object
Returns the value of attribute name.
-
#table_comment ⇒ Object
Returns the value of attribute table_comment.
-
#table_name ⇒ Object
Returns the value of attribute table_name.
Instance Method Summary collapse
-
#initialize(active_record_model, table_name, table_comment) ⇒ Model
constructor
A new instance of Model.
- #method_missing(method, *args, **options, &block) ⇒ Object
- #primary_column ⇒ Object
- #regular_columns ⇒ Object
Constructor Details
#initialize(active_record_model, table_name, table_comment) ⇒ Model
Returns a new instance of Model.
5 6 7 8 9 10 11 |
# File 'lib/crudboy/model.rb', line 5 def initialize(active_record_model, table_name, table_comment) @active_record_model = active_record_model @name = @active_record_model.name @table_name = table_name @table_comment = table_comment @columns = active_record_model.columns.map { |c| Column.new(c, c.name == active_record_model.primary_key) } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **options, &block) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/crudboy/model.rb', line 47 def method_missing(method, *args, **, &block) if active_record_model.respond_to?(method) active_record_model.send(method, *args, **, &block) else super end end |
Instance Attribute Details
#active_record_model ⇒ Object
Returns the value of attribute active_record_model.
3 4 5 |
# File 'lib/crudboy/model.rb', line 3 def active_record_model @active_record_model end |
#columns(**options) ⇒ Object
Returns the value of attribute columns.
3 4 5 |
# File 'lib/crudboy/model.rb', line 3 def columns @columns end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/crudboy/model.rb', line 3 def name @name end |
#table_comment ⇒ Object
Returns the value of attribute table_comment.
3 4 5 |
# File 'lib/crudboy/model.rb', line 3 def table_comment @table_comment end |
#table_name ⇒ Object
Returns the value of attribute table_name.
3 4 5 |
# File 'lib/crudboy/model.rb', line 3 def table_name @table_name end |
Instance Method Details
#primary_column ⇒ Object
13 14 15 |
# File 'lib/crudboy/model.rb', line 13 def primary_column columns.find { |c| c.name == active_record_model.primary_key } end |
#regular_columns ⇒ Object
17 18 19 |
# File 'lib/crudboy/model.rb', line 17 def regular_columns columns.reject { |c| c.name == active_record_model.primary_key } end |