Module: UtopiaData::Resource::Models
- Included in:
- UtopiaData::Resource
- Defined in:
- lib/utopia_data/resource/models.rb
Instance Method Summary collapse
- #attributes(&block) ⇒ Object
- #columns ⇒ Object
-
#create_resource_model ⇒ Object
Create the resource model.
- #model ⇒ Object
- #model_name ⇒ Object
- #set(attribute, options = {}) ⇒ Object
Instance Method Details
#attributes(&block) ⇒ Object
33 34 35 36 |
# File 'lib/utopia_data/resource/models.rb', line 33 def attributes(&block) @columns = [] instance_eval &block if block_given? end |
#columns ⇒ Object
42 43 44 |
# File 'lib/utopia_data/resource/models.rb', line 42 def columns @columns ||= [] end |
#create_resource_model ⇒ Object
Create the resource model
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/utopia_data/resource/models.rb', line 47 def create_resource_model table_name = @config[:table_name] ? "self.table_name = '#{@config[:table_name]}'" : nil model_class = <<-MODEL class ::#{model_name} < ActiveRecord::Base #{table_name} attr_accessor #{columns.join(", ")} end MODEL eval model_class end |
#model ⇒ Object
29 30 31 |
# File 'lib/utopia_data/resource/models.rb', line 29 def model @model ||= resource_class end |
#model_name ⇒ Object
25 26 27 |
# File 'lib/utopia_data/resource/models.rb', line 25 def model_name resource_class_name end |
#set(attribute, options = {}) ⇒ Object
38 39 40 |
# File 'lib/utopia_data/resource/models.rb', line 38 def set(attribute, = {}) @columns << attribute end |