Module: Anaconda::Model::InstanceMethods

Defined in:
lib/anaconda/anaconda_for.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/anaconda/anaconda_for.rb', line 70

def method_missing(method, *args, &block)
  checking_column = checking_method = nil
  if self.class.anaconda_columns.present? && self.class.anaconda_columns.any? do |column|
      checking_column = column
      Anaconda::MagicMethods.any? do |magic_method|
        checking_method = magic_method
        "#{column.to_s}_#{magic_method.to_s}" == method.to_s
      end
    end
    case checking_method
    when :url
      anaconda_url(checking_column, *args)
    when :download_url
      anaconda_download_url(checking_column, *args)
    when :anaconda_default_base_key
      anaconda_default_base_key_for(checking_column)
    else
      super
    end
  else
    super
  end
end

Instance Method Details

#anaconda_form_data_for(anaconda_column) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/anaconda/anaconda_for.rb', line 102

def anaconda_form_data_for( anaconda_column )
  if self.anaconda_columns.include? anaconda_column.to_sym
    
    options = self.class.anaconda_options[anaconda_column.to_sym].dup
    
    options[:base_key] = self.send(options[:base_key].to_s) if options[:base_key].kind_of? Symbol
    uploader  = Anaconda::S3Uploader.new(options)
    fields = uploader.fields
    fields[:post_url] = uploader.url
    fields
  else
    raise "#{anaconda_column} not configured for anaconda. Misspelling or did you forget to add the anaconda_for call for this field?"
  end
end

#anaconda_form_data_for_all_columnsObject



94
95
96
97
98
99
100
# File 'lib/anaconda/anaconda_for.rb', line 94

def anaconda_form_data_for_all_columns
  form_data = {}
  self.anaconda_columns.each do |column|
    form_data[column.to_sym] = anaconda_form_data_for column
  end
  form_data
end

#anaconda_options_for(anaconda_column) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/anaconda/anaconda_for.rb', line 117

def anaconda_options_for( anaconda_column )
  if self.class.anaconda_columns.include? anaconda_column.to_sym
    self.anaconda_options[anaconda_column].inject({}) do |hash, (k, v)|
      if v.kind_of? Proc
        hash[k] = self.instance_exec(&v)
      else
        hash[k] = v
      end
      hash
    end
  else
    raise "#{anaconda_column} not configured for anaconda. Misspelling or did you forget to add the anaconda_for call for this field?"
  end
end