Skip to content

Commit

Permalink
Add core.literal lens.
Browse files Browse the repository at this point in the history
  • Loading branch information
blambeau committed Jun 9, 2022
1 parent 7d0f2ee commit e60cd10
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.3

* Add core.literal lens.

## 0.5.2 - 2022-05-20

* Add check.notEmpty lens that throw an error if the input is
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ result = lens.call(input)
core.dig - Extract from the input value (object or array) using a path.
core.chain - Applies a chain of lenses to an input value
core.mapping - Converts the input value via a key:value mapping
core.literal - Returns a constant value takens as lens definition
str.strip - Remove leading and trailing spaces of an input string
str.split - Splits the input string as an array
Expand Down
6 changes: 6 additions & 0 deletions lib/monolens/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ def dig(options)
end
module_function :dig

def literal(options)
Literal.new(options)
end
module_function :literal

def mapping(options)
Mapping.new(options)
end
Expand All @@ -21,3 +26,4 @@ def mapping(options)
require_relative 'core/chain'
require_relative 'core/dig'
require_relative 'core/mapping'
require_relative 'core/literal'
11 changes: 11 additions & 0 deletions lib/monolens/core/literal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Monolens
module Core
class Literal
include Lens

def call(arg, world = {})
option(:defn)
end
end
end
end
13 changes: 13 additions & 0 deletions spec/monolens/core/test_literal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'spec_helper'

describe Monolens, "core.literal" do
let(:lens) do
Monolens.lens('core.literal' => { defn: 'hello' })
end

it 'works' do
input = {}
expected = 'hello'
expect(lens.call(input)).to eql(expected)
end
end

0 comments on commit e60cd10

Please sign in to comment.