Class: Filch::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/filch.rb

Overview

The Template Object defines a template recieves a model Object, and a String representing the name of the template. returns a new object with the following attributes:

associations_keys

an Array of Strings representing the names of the the Filch::Associations to be queryed.

associations

a Hash of Strings representing the predicates to be queryed.

attribute_keys

same as association_keys, for the the Filch::Attributes

attributes

same as associations, for the Filch::Attributes.

scope_keys

same as association_keys, for the Filch::Scopes

scopes

same as associations, for the Filch::Scopes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, template) ⇒ Template

Returns a new instance of Template.



146
147
148
149
150
151
# File 'lib/filch.rb', line 146

def initialize(model, template)
  @model = model
  @template = template
  @assocs = Associations.new(model)
  @attrs = Attributes.new(model)
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



152
153
154
# File 'lib/filch.rb', line 152

def model
  @model
end

Instance Method Details

#associationsObject



162
163
164
# File 'lib/filch.rb', line 162

def associations
  @assocs.associations[@template]
end

#associations_keysObject



166
167
168
# File 'lib/filch.rb', line 166

def associations_keys
  @assocs.associations_keys[@template]
end

#attributesObject



154
155
156
# File 'lib/filch.rb', line 154

def attributes
  @attrs.attributes[@template]
end

#attributes_keysObject



158
159
160
# File 'lib/filch.rb', line 158

def attributes_keys
  @attrs.attributes_keys[@template]
end

#default_valuesObject



174
175
176
177
178
179
180
# File 'lib/filch.rb', line 174

def default_values
  if @model.methods.include?(:filch_defaults)
    df_vals.merge(@model.filch_defaults[@template])
  else
    df_vals
  end
end

#df_valsObject



170
171
172
# File 'lib/filch.rb', line 170

def df_vals
  {}
end

#optionsObject



182
183
184
185
186
187
188
# File 'lib/filch.rb', line 182

def options
  if @model.methods.include?(:filch_options)
    @model.filch_options[@template] || {}
  else
    {}
  end
end

#scopesObject



190
191
192
# File 'lib/filch.rb', line 190

def scopes
  Scopes.new(@model).scopes[@template]
end