Module: RandomAttributes
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveSupport::Callbacks
- Defined in:
- lib/random_attributes.rb,
lib/random_attributes/version.rb
Overview
RandomAttributes
Getters, setters and object building for a someone elses data structure.
Example:
class Runner
include RandomAttributes
attribute 'runnerName', alias: :name
end
runner = Runner.new "runnerName" => "Phar Lap"
runner.name #=> "Phar Lap"
Defined Under Namespace
Modules: ClassMethods Classes: Register
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
- #attributes ⇒ Object
- #cache_key ⇒ Object
- #initialize(attrs = nil) ⇒ Object
- #parse(attrs = nil) ⇒ Object (also: #merge_attributes)
Instance Method Details
#attributes ⇒ Object
149 150 151 |
# File 'lib/random_attributes.rb', line 149 def attributes @raw_attributes ||= {}.freeze end |
#cache_key ⇒ Object
133 134 135 |
# File 'lib/random_attributes.rb', line 133 def cache_key @raw_attributes_hash end |
#initialize(attrs = nil) ⇒ Object
129 130 131 |
# File 'lib/random_attributes.rb', line 129 def initialize(attrs = nil) parse attrs end |
#parse(attrs = nil) ⇒ Object Also known as: merge_attributes
137 138 139 140 141 142 143 144 145 |
# File 'lib/random_attributes.rb', line 137 def parse(attrs = nil) @parsed_attributes = {} attrs && attrs.stringify_keys! run_callbacks :parse do @raw_attributes = attributes.merge(attrs.nil? ? {} : attrs).freeze @raw_attributes_hash = Digest::MD5.hexdigest(attributes.to_s) end self end |