Module: Cistern::Attributes::ClassMethods
- Defined in:
- lib/cistern/attributes.rb
Instance Method Summary collapse
- #_load(marshalled) ⇒ Object
- #aliases ⇒ Object
- #attribute(_name, options = {}) ⇒ Object
- #attributes ⇒ Object
- #identity(name, options = {}) ⇒ Object
- #ignore_attributes(*args) ⇒ Object
- #ignored_attributes ⇒ Object
Instance Method Details
#_load(marshalled) ⇒ Object
54 55 56 |
# File 'lib/cistern/attributes.rb', line 54 def _load(marshalled) new(Marshal.load(marshalled)) end |
#aliases ⇒ Object
58 59 60 |
# File 'lib/cistern/attributes.rb', line 58 def aliases @aliases ||= Hash.new { |h, k| h[k] = [] } end |
#attribute(_name, options = {}) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/cistern/attributes.rb', line 66 def attribute(_name, = {}) if defined? Cistern::Coverage attribute_call = Cistern::Coverage.find_caller_before('cistern/attributes.rb') # Only use DSL attribute calls from within a model if attribute_call && attribute_call.label.start_with?('<class:') [:coverage_file] = attribute_call.absolute_path [:coverage_line] = attribute_call.lineno [:coverage_hits] = 0 end end name = _name.to_s.to_sym send(:define_method, name) do read_attribute(name) end unless instance_methods.include?(name) send(:alias_method, "#{name}?", name) if [:type] == :boolean send(:define_method, "#{name}=") do |value| write_attribute(name, value) end unless instance_methods.include?("#{name}=".to_sym) if attributes[name] fail(ArgumentError, "#{self.name} attribute[#{_name}] specified more than once") else if [:squash] [:squash] = Array([:squash]).map(&:to_s) end attributes[name] = end [:aliases] = Array([:aliases] || [:alias]).map { |a| a.to_s.to_sym } [:aliases].each do |new_alias| aliases[new_alias] << name.to_s.to_sym end end |
#attributes ⇒ Object
62 63 64 |
# File 'lib/cistern/attributes.rb', line 62 def attributes @attributes ||= {} end |
#identity(name, options = {}) ⇒ Object
106 107 108 109 |
# File 'lib/cistern/attributes.rb', line 106 def identity(name, = {}) @identity = name attribute(name, ) end |
#ignore_attributes(*args) ⇒ Object
111 112 113 |
# File 'lib/cistern/attributes.rb', line 111 def ignore_attributes(*args) @ignored_attributes = args end |
#ignored_attributes ⇒ Object
115 116 117 |
# File 'lib/cistern/attributes.rb', line 115 def ignored_attributes @ignored_attributes ||= [] end |