Sha256: 91c4c377439f2d03c16d7a6366eb2a631e6b9a9e496c70ba8659a4fac5767eea
Contents?: true
Size: 1.57 KB
Versions: 36
Compression:
Stored size: 1.57 KB
Contents
class Eco::Data::Locations::NodeDiff module Accessors class << self def included(base) super(base) base.extend Eco::Language::Models::ClassHelpers base.extend ClassMethods base.inheritable_class_vars :exposed_attrs end end module ClassMethods include Eco::Data::Strings::SnakeCase # Creates the defined accessor attributes against `NodeDiff` # It also creates a method with question mark that evaluates true if **any** the attr changed. # @note the defined attributes are expected to be the keys within # the source Hashes that are being compared. # @note accessing `src_1` (prev) attributes, will have it's method as `prev_[attrName]` def attr_expose(*attrs) attrs.each do |attr| meth = attr.to_sym methp = :"#{meth}_prev" methq = :"#{meth}?" # current value define_method meth do attr(meth) end alias_method snake_case(meth), meth # prev value define_method methp do attr_prev(meth) end alias_method snake_case(methp), methp # has it changed? define_method methq do diff_attr?(meth) end alias_method snake_case(methq), methq @exposed_attrs = (@exposed_attrs || []) | [meth] end end # Keeps track on what attributes have been exposed. def exposed_attrs @exposed_attrs ||= [] end end end end
Version data entries
36 entries across 36 versions & 1 rubygems