Sha256: a7268667588afecfc8d7e6494727769091625976b84e90f51e4bd7d3c63c2850
Contents?: true
Size: 772 Bytes
Versions: 1
Compression:
Stored size: 772 Bytes
Contents
require 'active_support/concern' module Journey::Resource::Enums extend ActiveSupport::Concern included do def self.enum(attr, collection=[]) collection_const_name = attr.to_s.pluralize.upcase.to_sym const_set collection_const_name, collection.freeze define_method "#{attr}_values" do self.class.const_get(collection_const_name) end instance_eval do attr_accessor :"#{attr}_index" end define_method attr do value = attributes[attr.to_s].presence if value.is_a?(Fixnum) send("#{attr}_values")[value] else value end end define_method "#{attr}=" do |value| attributes[attr.to_s] = value.presence end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
embark-journey-0.0.15 | lib/journey/resource/enums.rb |