Module: Vexile::DSL::ClassMethods
- Defined in:
- lib/vexile.rb
Instance Method Summary collapse
- #has_many(*attribute_names) ⇒ Object
- #has_one(*attribute_names) ⇒ Object
- #vexile_const_lookup(const) ⇒ Object
Instance Method Details
#has_many(*attribute_names) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/vexile.rb', line 56 def has_many *attribute_names if attribute_names.last.kind_of? Hash = attribute_names.pop else = {} end attribute_names.each do |name| klass_name = ([:class_name] || name.to_s.underscore).singularize.classify proxy_accessor name.to_s.underscore, :proxy => [ArrayProxy, VexileProxy], :class_name => klass_name, :owner_class => self end end |
#has_one(*attribute_names) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/vexile.rb', line 68 def has_one *attribute_names if attribute_names.last.kind_of? Hash = attribute_names.pop else = {} end attribute_names.each do |name| class_name = ([:class_name] || name.to_s.underscore).singularize.classify proxy_accessor name.to_s.underscore, :proxy => VexileProxy, :class_name => class_name, :owner_class => self end end |
#vexile_const_lookup(const) ⇒ Object
50 51 52 53 54 |
# File 'lib/vexile.rb', line 50 def vexile_const_lookup const namespaced = [self, self.parents].flatten.map{|i| [i, const.to_s].join "::"}.push(const.to_s).sort{|a,b| b.length <=> a.length} vexile_class = namespaced.detect{|i| Vexile.klasses.map(&:name).include?(i)} vexile_class && vexile_class.constantize end |