Class: SampleModels::Sampler::ConfigureRecipient

Inherits:
Object
  • Object
show all
Defined in:
lib/sample_models/sampler.rb

Defined Under Namespace

Classes: Attribute

Instance Method Summary collapse

Constructor Details

#initialize(sampler) ⇒ ConfigureRecipient

Returns a new instance of ConfigureRecipient.



59
60
61
# File 'lib/sample_models/sampler.rb', line 59

def initialize(sampler)
  @sampler = sampler
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/sample_models/sampler.rb', line 63

def method_missing(meth, *args, &block)
  if @sampler.model.column_names.include?(meth.to_s)
    Attribute.new(@sampler, meth)
  elsif @sampler.model.belongs_to_association(meth)
    Attribute.new(@sampler, meth)
  elsif @sampler.model.instance_methods.map(&:to_sym).include?(meth) && 
        @sampler.model.instance_methods.map(&:to_sym).include?("#{meth.to_s}=".to_sym)
    Attribute.new(@sampler, meth)
  elsif meth.to_s =~ /(.*)_sample$/
    @sampler.named_samples[$1] = args.first
  else
    super
  end
end

Instance Method Details

#before_save(&proc) ⇒ Object



78
79
80
# File 'lib/sample_models/sampler.rb', line 78

def before_save(&proc)
  @sampler.before_save = proc
end