Class: ParamsReady::AbstractBuilder

Inherits:
Object
  • Object
show all
Extended by:
Extensions::Registry
Defined in:
lib/params_ready/builder.rb

Direct Known Subclasses

Builder, Query::AbstractPredicateBuilder

Defined Under Namespace

Modules: HavingArelTable, HavingModel, HavingValue

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Extensions::Registry

human_string, registry

Constructor Details

#initialize(definition) ⇒ AbstractBuilder

Returns a new instance of AbstractBuilder.



57
58
59
# File 'lib/params_ready/builder.rb', line 57

def initialize(definition)
  @definition = definition
end

Class Method Details

.define_parameter(type, *args, **opts, &block) ⇒ Object



31
32
33
34
35
36
# File 'lib/params_ready/builder.rb', line 31

def self.define_parameter(type, *args, **opts, &block)
  builder_class = builder(type)
  builder = builder_class.instance(*args, **opts)
  builder.include(&block) unless block.nil?
  builder.build
end

.define_registered_parameter(name, *args, **opts, &block) ⇒ Object



38
39
40
41
# File 'lib/params_ready/builder.rb', line 38

def self.define_registered_parameter(name, *args, **opts, &block)
  full_name = "define_#{name}"
  send(full_name, *args, **opts, &block)
end

.instance(*args, **opts) ⇒ Object



51
52
53
# File 'lib/params_ready/builder.rb', line 51

def self.instance(*args, **opts)
  new *args, **opts
end

.register(name) ⇒ Object



27
28
29
# File 'lib/params_ready/builder.rb', line 27

def self.register(name)
  register_builder(name, self)
end

.resolve(input, *args, **opts, &block) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/params_ready/builder.rb', line 43

def self.resolve(input, *args, **opts, &block)
  if input.is_a? Parameter::AbstractDefinition
    input
  else
    define_registered_parameter(input, *args, **opts, &block)
  end
end

Instance Method Details

#buildObject



72
73
74
75
# File 'lib/params_ready/builder.rb', line 72

def build
  @definition.finish
  @definition
end

#fetchObject



66
67
68
69
70
# File 'lib/params_ready/builder.rb', line 66

def fetch
  d = @definition
  @definition = nil
  d
end

#include(&block) ⇒ Object



61
62
63
64
# File 'lib/params_ready/builder.rb', line 61

def include(&block)
  instance_eval(&block)
  self
end

#open?Boolean

Returns:

  • (Boolean)


77
78
79
80
81
82
# File 'lib/params_ready/builder.rb', line 77

def open?
  return false if @definition.nil?
  return false if @definition.frozen?

  true
end