Sha256: 74b4bb3b0a6185fa8790b56bf312b17c5ce47646efcc0131b90c11b419a77779
Contents?: true
Size: 957 Bytes
Versions: 3
Compression:
Stored size: 957 Bytes
Contents
module RestPack::Serializer::Attributes extend ActiveSupport::Concern module ClassMethods def serializable_attributes @serializable_attributes end def attributes(*attrs) attrs.each { |attr| attribute attr } end def attribute(name, options={}) options[:key] ||= name.to_sym @serializable_attributes ||= {} @serializable_attributes[options[:key]] = name define_attribute_method name define_include_method name end def define_attribute_method(name) unless method_defined?(name) define_method name do value = @model.send(name) value = value.to_s if name == :id value end end end def define_include_method(name) method = "include_#{name}?".to_sym unless method_defined?(method) define_method method do @options[method].nil? || @options[method] end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems