class Fabrication::Schematic::Attribute
Attributes
Public Class Methods
Source
# File lib/fabrication/schematic/attribute.rb, line 7 def initialize(klass, name, value, params = {}, &block) self.klass = klass self.name = name self.params = params self.value = value.nil? ? block : value end
Public Instance Methods
Source
# File lib/fabrication/schematic/attribute.rb, line 14 def params @params ||= {} end
Source
# File lib/fabrication/schematic/attribute.rb, line 26 def processed_value(processed_attributes) if process_count (1..process_count).map { |i| execute(processed_attributes, i, &value) } elsif value_proc? execute(processed_attributes, &value) else value end end
Source
# File lib/fabrication/schematic/attribute.rb, line 18 def transient! params[:transient] = true end
Source
# File lib/fabrication/schematic/attribute.rb, line 22 def transient? params[:transient] end
Source
# File lib/fabrication/schematic/attribute.rb, line 40 def value_proc? value.is_a?(Proc) end
Source
# File lib/fabrication/schematic/attribute.rb, line 36 def value_static? !value_proc? end
Private Instance Methods
Source
# File lib/fabrication/schematic/attribute.rb, line 46 def execute(...) Fabrication::Schematic::Runner.new(klass).instance_exec(...) end
Source
# File lib/fabrication/schematic/attribute.rb, line 50 def process_count count || rand || rand_range end
Source
# File lib/fabrication/schematic/attribute.rb, line 58 def rand return unless params[:rand] range = params[:rand] range = 1..range unless range.is_a? Range Kernel.rand(range) end
Source
# File lib/fabrication/schematic/attribute.rb, line 67 def rand_range Kernel.rand(params[:start_range]..params[:end_range]) if params[:start_range] && params[:end_range] end