Class: ActiveFlags::Handler::FlagBuilder
- Inherits:
-
Object
- Object
- ActiveFlags::Handler::FlagBuilder
- Defined in:
- lib/active_flags/handler/flag_builder.rb
Instance Method Summary collapse
-
#initialize(resource, flag_attributes) ⇒ FlagBuilder
constructor
A new instance of FlagBuilder.
- #save ⇒ Object
Constructor Details
#initialize(resource, flag_attributes) ⇒ FlagBuilder
Returns a new instance of FlagBuilder.
4 5 6 7 |
# File 'lib/active_flags/handler/flag_builder.rb', line 4 def initialize(resource, flag_attributes) @resource = resource @flag_attributes = flag_attributes end |
Instance Method Details
#save ⇒ Object
9 10 11 12 13 14 |
# File 'lib/active_flags/handler/flag_builder.rb', line 9 def save flag = ActiveFlags::Flag.find_or_initialize_by(subject: @resource, key: @flag_attributes[:key]) flag.removing_duplicated_flags! flag.update!(value: @flag_attributes[:value]) @resource.flags_as_collection << flag end |