Class: EnumIsh::Builder
- Inherits:
-
Object
- Object
- EnumIsh::Builder
- Defined in:
- lib/enum_ish/builder.rb,
lib/enum_ish/builder/active_record.rb
Defined Under Namespace
Classes: ActiveRecord
Instance Method Summary collapse
- #build(attr, enum, config = {}) ⇒ Object
-
#initialize(klass) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(klass) ⇒ Builder
Returns a new instance of Builder.
3 4 5 |
# File 'lib/enum_ish/builder.rb', line 3 def initialize(klass) @klass = klass end |
Instance Method Details
#build(attr, enum, config = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/enum_ish/builder.rb', line 7 def build(attr, enum, config = {}) if enum.is_a?(Array) enum = enum.map { |v| k = v.to_s.to_sym v = v.to_s if v.is_a?(Symbol) [k, v] }.to_h end [:text, :options, :predicate, :accessor, :validate, :scope].each do |key| if config[key] send("define_#{key}", attr, enum, config) end end if config.key?(:default) define_default_value(attr, enum, config) end end |