Module: Lego

Defined in:
lib/lego.rb,
lib/lego/model.rb,
lib/lego/value.rb,
lib/lego/either.rb

Defined Under Namespace

Modules: Either, Value Classes: Model

Constant Summary collapse

CoerceError =
Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.fail(error) ⇒ Object



11
12
13
# File 'lib/lego/either.rb', line 11

def self.fail(error)
  Either::Fail.new(error)
end

.just(value) ⇒ Object



7
8
9
# File 'lib/lego/either.rb', line 7

def self.just(value)
  Either::Just.new(value)
end

.noneObject



3
4
5
# File 'lib/lego/either.rb', line 3

def self.none
  Either::None.new
end

.value_parser(item, *args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/lego.rb', line 10

def self.value_parser(item, *args)
  if (Lego::Value.const_defined?(item.to_s, false) rescue false)
    Lego::Value.const_get(item.to_s, false).new(*args)
  elsif item.respond_to?(:coerce)
    item
  else
    raise NameError
  end
rescue NameError
  raise NameError, "Unknown Lego::Value parser: #{item.to_s}"
end