Skip to content

Commit

Permalink
Merge 82df3e8 into 82ce1b0
Browse files Browse the repository at this point in the history
  • Loading branch information
tmaier committed Mar 26, 2023
2 parents 82ce1b0 + 82df3e8 commit 83449a1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/unleash/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def to_s
",app_name=#{@app_name},environment=#{@environment}>"
end

def to_h
ATTRS.map{ |attr| [attr, self.send(attr)] }.to_h.merge(properties: @properties)
end

def get_by_name(name)
normalized_name = underscore(name).to_sym

Expand Down
16 changes: 16 additions & 0 deletions spec/unleash/context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,20 @@

expect(context.get_by_name(:CurrentTime).to_s).to eq(date.to_s)
end

it "converts context to hash" do
params = {
app_name: 'my_ruby_app',
environment: 'dev',
user_id: '123',
session_id: 'verylongsesssionid',
remote_address: '127.0.0.2',
current_time: '2023-03-22T00:00:00Z',
properties: {
fancy: 'polarbear'
}
}
context = Unleash::Context.new(params)
expect(context.to_h).to eq(params)
end
end

0 comments on commit 83449a1

Please sign in to comment.