Skip to content

Instantly share code, notes, and snippets.

@jryans
Created August 22, 2012 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jryans/3427250 to your computer and use it in GitHub Desktop.
Save jryans/3427250 to your computer and use it in GitHub Desktop.
Add fields to all specs
def insert_at(parent, pos, new_field)
parent.viz_fields.all(:conditions => ['position >= ?', pos]).each do |child|
child.position += 1
child.save
end
new_field[:position] = pos
parent.viz_fields.create(new_field)
end
def add_fields(s, v)
root = s.viz_field
section = insert_at(root, root.viz_fields.length + 1, {:viz => v, :kind => VizField::TYPES::SECTION, :attr => 'section_analytics', :label => 'Analytics'})
insert_at(section, section.viz_fields.length + 1, {:viz => v, :kind => VizField::TYPES::STRING, :attr => 'ga_client_account', :label => 'Google Analytics', :description => 'Enter your Google Analytics account ID to receive events from this product.'})
end
Viz.all(:conditions => { :published => true, :in_progress => false }).each do |v|
pub_ver = v.versions.find_by_published(true)
add_fields(pub_ver.viz_spec, v)
working_ver = v.versions.find_by_number(pub_ver.number + 1)
add_fields(working_ver.viz_spec, v)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment