Class: Class
Overview
:nodoc:
Instance Method Summary collapse
- #attr_array(plural_array_name_sym, options = {}) ⇒ Object
- #class_attr_accessor(*syms) ⇒ Object
- #class_attr_reader(*syms) ⇒ Object
- #class_attr_writer(*syms) ⇒ Object
- #class_to_sym ⇒ Object
- #create_child(class_name, mod = Object, register = true, &block) ⇒ Object
- #instance_attr_accessor(*syms) ⇒ Object
- #underscore_class_name ⇒ Object
Instance Method Details
#attr_array(plural_array_name_sym, options = {}) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/trellis/utils.rb', line 79 def attr_array(plural_array_name_sym, ={}) create_accessor = [:create_accessor].nil? ? true : [:create_accessor] plural_array_name_sym = plural_array_name_sym.to_s #convert to string if it is a symbol instance_variable_set("@#{plural_array_name_sym}".to_sym, Array.new) (plural_array_name_sym) { instance_variable_get("@#{plural_array_name_sym}".to_sym) } if create_accessor end |
#class_attr_accessor(*syms) ⇒ Object
55 56 57 58 59 |
# File 'lib/trellis/utils.rb', line 55 def class_attr_accessor(*syms) syms.flatten.each do |sym| .instance_eval { attr_accessor(sym) } end end |
#class_attr_reader(*syms) ⇒ Object
67 68 69 70 71 |
# File 'lib/trellis/utils.rb', line 67 def class_attr_reader(*syms) syms.flatten.each do |sym| .instance_eval { attr_reader(sym) } end end |
#class_attr_writer(*syms) ⇒ Object
73 74 75 76 77 |
# File 'lib/trellis/utils.rb', line 73 def class_attr_writer(*syms) syms.flatten.each do |sym| .instance_eval { attr_writer(sym) } end end |
#class_to_sym ⇒ Object
42 43 44 |
# File 'lib/trellis/utils.rb', line 42 def class_to_sym underscore_class_name.to_sym end |
#create_child(class_name, mod = Object, register = true, &block) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/trellis/utils.rb', line 86 def create_child(class_name, mod = Object, register = true, &block) klass = Class.new self klass.class_eval &block if block_given? mod.const_set class_name, klass if register klass end |
#instance_attr_accessor(*syms) ⇒ Object
61 62 63 64 65 |
# File 'lib/trellis/utils.rb', line 61 def instance_attr_accessor(*syms) syms.flatten.each do |sym| instance_eval { attr_accessor(sym) } end end |
#underscore_class_name ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/trellis/utils.rb', line 46 def underscore_class_name value = (name.empty? || name =~ /<class:(.*)/) ? self : name value.to_s.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase.split('/').last end |