config_scripts 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.rspec +2 -0
  4. data/.yardopts +1 -0
  5. data/CHANGELOG.md +17 -0
  6. data/Gemfile +4 -0
  7. data/Gemfile.lock +124 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +55 -0
  10. data/Rakefile +1 -0
  11. data/TODO.md +8 -0
  12. data/config_scripts.gemspec +31 -0
  13. data/lib/config_scripts/generators/config_script.rb +24 -0
  14. data/lib/config_scripts/generators/migrations.rb +36 -0
  15. data/lib/config_scripts/generators.rb +2 -0
  16. data/lib/config_scripts/scripts/script.rb +135 -0
  17. data/lib/config_scripts/scripts/script_history.rb +39 -0
  18. data/lib/config_scripts/scripts.rb +9 -0
  19. data/lib/config_scripts/seeds/seed_set.rb +321 -0
  20. data/lib/config_scripts/seeds/seed_type.rb +361 -0
  21. data/lib/config_scripts/seeds.rb +8 -0
  22. data/lib/config_scripts/tasks/pending_migrations.rake +11 -0
  23. data/lib/config_scripts/tasks/seeds.rake +18 -0
  24. data/lib/config_scripts/tasks.rb +12 -0
  25. data/lib/config_scripts/version.rb +4 -0
  26. data/lib/config_scripts.rb +9 -0
  27. data/spec/dummy/README.rdoc +28 -0
  28. data/spec/dummy/Rakefile +6 -0
  29. data/spec/dummy/app/assets/images/.keep +0 -0
  30. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  31. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  32. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  33. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  34. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  35. data/spec/dummy/app/mailers/.keep +0 -0
  36. data/spec/dummy/app/models/.keep +0 -0
  37. data/spec/dummy/app/models/concerns/.keep +0 -0
  38. data/spec/dummy/app/models/hair_color.rb +2 -0
  39. data/spec/dummy/app/models/person.rb +4 -0
  40. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  41. data/spec/dummy/bin/bundle +3 -0
  42. data/spec/dummy/bin/rails +4 -0
  43. data/spec/dummy/bin/rake +4 -0
  44. data/spec/dummy/config/application.rb +23 -0
  45. data/spec/dummy/config/boot.rb +5 -0
  46. data/spec/dummy/config/database.yml +25 -0
  47. data/spec/dummy/config/environment.rb +5 -0
  48. data/spec/dummy/config/environments/development.rb +29 -0
  49. data/spec/dummy/config/environments/production.rb +80 -0
  50. data/spec/dummy/config/environments/test.rb +36 -0
  51. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  52. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  53. data/spec/dummy/config/initializers/inflections.rb +16 -0
  54. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  55. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  56. data/spec/dummy/config/initializers/session_store.rb +3 -0
  57. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  58. data/spec/dummy/config/locales/en.yml +23 -0
  59. data/spec/dummy/config/routes.rb +56 -0
  60. data/spec/dummy/config.ru +4 -0
  61. data/spec/dummy/db/migrate/20140208014550_create_config_scripts.rb +7 -0
  62. data/spec/dummy/db/migrate/20140208161829_create_people.rb +9 -0
  63. data/spec/dummy/db/migrate/20140208182050_create_hair_colors.rb +9 -0
  64. data/spec/dummy/db/migrate/20140208182101_add_hair_color_to_person.rb +6 -0
  65. data/spec/dummy/db/migrate/20140208225801_add_scope_to_people.rb +6 -0
  66. data/spec/dummy/db/migrate/20140209132911_add_hex_value_to_hair_color.rb +5 -0
  67. data/spec/dummy/db/schema.rb +38 -0
  68. data/spec/dummy/lib/assets/.keep +0 -0
  69. data/spec/dummy/log/.keep +0 -0
  70. data/spec/dummy/public/404.html +58 -0
  71. data/spec/dummy/public/422.html +58 -0
  72. data/spec/dummy/public/500.html +57 -0
  73. data/spec/dummy/public/favicon.ico +0 -0
  74. data/spec/generators/config_script_spec.rb +23 -0
  75. data/spec/generators/migrations_spec.rb +23 -0
  76. data/spec/scripts/script_history_spec.rb +53 -0
  77. data/spec/scripts/script_spec.rb +282 -0
  78. data/spec/seeds/seed_set_spec.rb +371 -0
  79. data/spec/seeds/seed_type_spec.rb +439 -0
  80. data/spec/spec_helper.rb +38 -0
  81. data/templates/config_script.rb +9 -0
  82. data/templates/create_config_scripts_migration.rb +7 -0
  83. metadata +321 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3f9ab8bf09440a9182b9450651756d9cdde28109
4
+ data.tar.gz: ab9ff7ebde2313fee3071c9dcff710219cc1d3bf
5
+ SHA512:
6
+ metadata.gz: c51d874865f2080a14ee8a13576b828fbdf8dd5935e32b1311384b276a16816b3d18283da8fb97c0dda8b0bf81f9dd5dc9ae136fa67dd97aaa4341dc2f4516e9
7
+ data.tar.gz: 13a589c68a9ce1d9a9b44aa00bf8593aade3c1d10e3bc72051226a65ad69e1d08015901c33f47efffc522548210c4973650b149b2b9a5624709e97cba6aa103f
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ # YARD Documentation
2
+ .yardoc
3
+ doc/code
4
+
5
+ # Simplecov Code Coverage
6
+ doc/coverage
7
+
8
+ # Files from Dummy App for Specs
9
+ spec/dummy/db/*.sqlite3
10
+ spec/dummy/log/*.log
11
+
12
+ # tmp files creating from specs
13
+ tmp/
14
+
15
+ # Package gem files
16
+ pkg/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --color
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ -o doc/code
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # Version 0.4.0 - 9 February 2014
2
+
3
+ * Adds support for polymorphic foreign keys
4
+ * Adds support for custom readers and writers for attribute values.
5
+ * Adds the ability to read and write individual seed sets.
6
+
7
+ # Version 0.3.0 - 8 February 2014
8
+
9
+ * Adds the last of the specs.
10
+
11
+ # Version 0.2.0 - 3 February 2014
12
+
13
+ * Adds documentation
14
+
15
+ # Version 0.1.0 - 2 February 2014
16
+
17
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in config_scripts.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,124 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ config_scripts (0.4.1)
5
+ rails (> 3.0.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionmailer (4.0.2)
11
+ actionpack (= 4.0.2)
12
+ mail (~> 2.5.4)
13
+ actionpack (4.0.2)
14
+ activesupport (= 4.0.2)
15
+ builder (~> 3.1.0)
16
+ erubis (~> 2.7.0)
17
+ rack (~> 1.5.2)
18
+ rack-test (~> 0.6.2)
19
+ activemodel (4.0.2)
20
+ activesupport (= 4.0.2)
21
+ builder (~> 3.1.0)
22
+ activerecord (4.0.2)
23
+ activemodel (= 4.0.2)
24
+ activerecord-deprecated_finders (~> 1.0.2)
25
+ activesupport (= 4.0.2)
26
+ arel (~> 4.0.0)
27
+ activerecord-deprecated_finders (1.0.3)
28
+ activesupport (4.0.2)
29
+ i18n (~> 0.6, >= 0.6.4)
30
+ minitest (~> 4.2)
31
+ multi_json (~> 1.3)
32
+ thread_safe (~> 0.1)
33
+ tzinfo (~> 0.3.37)
34
+ arel (4.0.2)
35
+ atomic (1.1.14)
36
+ builder (3.1.4)
37
+ diff-lcs (1.2.5)
38
+ docile (1.1.3)
39
+ erubis (2.7.0)
40
+ generator_spec (0.9.2)
41
+ activesupport (>= 3.0.0)
42
+ railties (>= 3.0.0)
43
+ hike (1.2.3)
44
+ i18n (0.6.9)
45
+ mail (2.5.4)
46
+ mime-types (~> 1.16)
47
+ treetop (~> 1.4.8)
48
+ mime-types (1.25.1)
49
+ minitest (4.7.5)
50
+ multi_json (1.8.4)
51
+ polyglot (0.3.3)
52
+ rack (1.5.2)
53
+ rack-test (0.6.2)
54
+ rack (>= 1.0)
55
+ rails (4.0.2)
56
+ actionmailer (= 4.0.2)
57
+ actionpack (= 4.0.2)
58
+ activerecord (= 4.0.2)
59
+ activesupport (= 4.0.2)
60
+ bundler (>= 1.3.0, < 2.0)
61
+ railties (= 4.0.2)
62
+ sprockets-rails (~> 2.0.0)
63
+ railties (4.0.2)
64
+ actionpack (= 4.0.2)
65
+ activesupport (= 4.0.2)
66
+ rake (>= 0.8.7)
67
+ thor (>= 0.18.1, < 2.0)
68
+ rake (10.1.1)
69
+ rspec (2.14.1)
70
+ rspec-core (~> 2.14.0)
71
+ rspec-expectations (~> 2.14.0)
72
+ rspec-mocks (~> 2.14.0)
73
+ rspec-core (2.14.7)
74
+ rspec-expectations (2.14.5)
75
+ diff-lcs (>= 1.1.3, < 2.0)
76
+ rspec-mocks (2.14.5)
77
+ rspec-rails (2.14.1)
78
+ actionpack (>= 3.0)
79
+ activemodel (>= 3.0)
80
+ activesupport (>= 3.0)
81
+ railties (>= 3.0)
82
+ rspec-core (~> 2.14.0)
83
+ rspec-expectations (~> 2.14.0)
84
+ rspec-mocks (~> 2.14.0)
85
+ simplecov (0.8.2)
86
+ docile (~> 1.1.0)
87
+ multi_json
88
+ simplecov-html (~> 0.8.0)
89
+ simplecov-html (0.8.0)
90
+ sprockets (2.10.1)
91
+ hike (~> 1.2)
92
+ multi_json (~> 1.0)
93
+ rack (~> 1.0)
94
+ tilt (~> 1.1, != 1.3.0)
95
+ sprockets-rails (2.0.1)
96
+ actionpack (>= 3.0)
97
+ activesupport (>= 3.0)
98
+ sprockets (~> 2.8)
99
+ sqlite3 (1.3.8)
100
+ thor (0.18.1)
101
+ thread_safe (0.1.3)
102
+ atomic
103
+ tilt (1.4.1)
104
+ timecop (0.7.1)
105
+ treetop (1.4.15)
106
+ polyglot
107
+ polyglot (>= 0.3.1)
108
+ tzinfo (0.3.38)
109
+ yard (0.8.7.3)
110
+
111
+ PLATFORMS
112
+ ruby
113
+
114
+ DEPENDENCIES
115
+ bundler (~> 1.3)
116
+ config_scripts!
117
+ generator_spec
118
+ rake
119
+ rspec
120
+ rspec-rails
121
+ simplecov
122
+ sqlite3
123
+ timecop
124
+ yard
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 John Brownlee
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # ConfigScripts
2
+
3
+ This gem provides libraries for generating configuration scripts, and reading
4
+ and writing seed data to spreadsheets.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'config_scripts'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install config_scripts
19
+
20
+ Generate the new migrations for the config_scripts table:
21
+
22
+ $ rails g config_scripts:migrations
23
+
24
+ And run them:
25
+
26
+ $ rake db:migrate
27
+
28
+ ## Usage
29
+
30
+ ### Config Scripts
31
+
32
+ #### Generate a new config script:
33
+
34
+ $ rails g config_scripts:config_script MyConfigScript
35
+
36
+ This will add a file to the `db/config_scripts` directory.
37
+
38
+ #### Run all the pending config scripts:
39
+
40
+ $ rake config_scripts:run_pending
41
+
42
+ ### Seed Data
43
+
44
+ #### Defining Seed Data:
45
+
46
+ Create a file in the directory `db/seeds/definitions`. Examples of defining seed
47
+ data will be coming in the future.
48
+
49
+ #### Dumping seed data to the disk:
50
+
51
+ $ rake config_scripts:seeds:dump
52
+
53
+ #### Loading the seed data from the disk:
54
+
55
+ $ rake config_scripts::seeds::load
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/TODO.md ADDED
@@ -0,0 +1,8 @@
1
+ ### Features
2
+
3
+ * Rolling back scripts
4
+ * Generators for seed directories
5
+
6
+ ### Gem Preparation
7
+
8
+ * Add examples to the Readme
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'config_scripts/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "config_scripts"
8
+ spec.version = ConfigScripts::VERSION
9
+ spec.authors = ["John Brownlee"]
10
+ spec.email = ["apps@johnbrownlee.com"]
11
+ spec.description = "Library for creating trackable config scripts, and reading and writing seed data into spreadsheets"
12
+ spec.summary = "Config scripts and seed files for Rails"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "rails", "> 3.0.0"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "yard"
26
+ spec.add_development_dependency "simplecov"
27
+ spec.add_development_dependency 'sqlite3'
28
+ spec.add_development_dependency 'timecop'
29
+ spec.add_development_dependency 'generator_spec'
30
+ spec.add_development_dependency 'rspec-rails'
31
+ end
@@ -0,0 +1,24 @@
1
+ require 'rails/generators'
2
+ module ConfigScripts
3
+ # This class provides a generator for creating a config new script.
4
+ class ConfigScriptGenerator < Rails::Generators::NamedBase
5
+ source_root File.expand_path('../../../../templates', __FILE__)
6
+
7
+ # This method creates a new config script.
8
+ #
9
+ # It will take a template file from +templates/config_scripts+, and the
10
+ # name passed in when runing the generator, and create a file under
11
+ # +db/config_scripts+ in the app.
12
+ #
13
+ # The config script filename will be prefixed with a timestamp, like a
14
+ # database migration. The class defined in the config script will have
15
+ # the name passed in to the generator.
16
+ #
17
+ # @return [Nil]
18
+ def config_script
19
+ path = "db/config_scripts/#{Time.now.to_s(:number)}_#{self.file_name}.rb"
20
+ template "config_script.rb", path, {name: name}
21
+ nil
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,36 @@
1
+ require 'rails/generators'
2
+ module ConfigScripts
3
+ # This class provides a generator for creating the migrations that we need to
4
+ # use this gem.
5
+ class MigrationsGenerator < Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+ source_root File.expand_path('../../../../templates', __FILE__)
8
+
9
+ # This generator creates the migrations that we need for the gem.
10
+ def create_migrations
11
+ copy_migration 'create_config_scripts'
12
+ end
13
+
14
+ # This method gets the number for the next migration created by this
15
+ # generator.
16
+ #
17
+ # @param [String] dirname
18
+ # The name of the directory in which we are creating the migrations.
19
+ #
20
+ # We use the current timestamp.
21
+ def self.next_migration_number(dirname)
22
+ Time.now.to_s(:number)
23
+ end
24
+
25
+ protected
26
+
27
+ # This method copies a migration from our template directory to the app's
28
+ # migrations directory.
29
+ #
30
+ # @param [String] filename
31
+ # The name of the file in the templates directory.
32
+ def copy_migration(filename)
33
+ migration_template "#{filename}_migration.rb", "db/migrate/#{filename}.rb"
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,2 @@
1
+ require 'config_scripts/generators/migrations'
2
+ require 'config_scripts/generators/config_script'
@@ -0,0 +1,135 @@
1
+ module ConfigScripts
2
+ module Scripts
3
+ # This class is the base class for all of the config scripts that the
4
+ # app will define.
5
+ class Script
6
+ # @!group Config
7
+
8
+ # This method gets the directory in which the scripts will be stored.
9
+ #
10
+ # The scripts are stored in the +db/config_scripts+ directory under the app.
11
+ #
12
+ # @return [String]
13
+ def self.script_directory
14
+ Rails.root.join('db', 'config_scripts')
15
+ end
16
+
17
+ # @!group Pending Scripts
18
+
19
+ # This method gets the scripts that we have not yet run.
20
+ #
21
+ # We will return the filenames, without the extensions.
22
+ #
23
+ # @return [Array<String>]
24
+ def self.pending_scripts
25
+ paths = Dir.glob(File.join(self.script_directory, '*.rb'))
26
+ paths.collect do |path|
27
+ filename = File.basename(path, ".rb")
28
+ timestamp = filename[0, 14]
29
+ ScriptHistory.script_was_run?(timestamp) ? nil : filename
30
+ end.compact
31
+ end
32
+
33
+ # This method runs all the scripts that have not yet been run.
34
+ #
35
+ # @return [True]
36
+ def self.run_pending_scripts
37
+ self.pending_scripts.each do |filename|
38
+ path = Rails.root.join('db', 'config_scripts', "#{filename}.rb")
39
+ require path
40
+ timestamp = filename[0,14]
41
+ class_name = filename[15..-1].camelize + 'Config'
42
+ klass = nil
43
+ begin
44
+ klass = class_name.constantize
45
+ rescue NameError
46
+ puts "Aborting: could not find class #{class_name}"
47
+ return
48
+ end
49
+ puts "Running #{filename}"
50
+ success = klass.new(timestamp).run(:up)
51
+ end
52
+ true
53
+ end
54
+
55
+ # This method prints out the names of all of the scripts that have not
56
+ # been run.
57
+ def self.list_pending_scripts
58
+ self.pending_scripts.each do |filename|
59
+ puts filename
60
+ end
61
+ end
62
+
63
+ # @!group Creating
64
+
65
+ # This method creates a new script.
66
+ #
67
+ # @param [String] timestamp
68
+ # The timestamp that is used to uniquely indentify the script.
69
+ #
70
+ # @return [Script]
71
+ def initialize(timestamp)
72
+ @timestamp = timestamp
73
+ end
74
+
75
+ # @!group Running
76
+
77
+ # @return [String]
78
+ # The timestamp for this instance of the script.
79
+ attr_accessor :timestamp
80
+
81
+ # This method performs the changes for this config script.
82
+ #
83
+ # This implementation raises an exception. Subclasses must define this
84
+ # method.
85
+ #
86
+ # If there are any issues running the script, this method should raise an
87
+ # exception.
88
+ def up
89
+ raise "Not supported"
90
+ end
91
+
92
+ # This method rolls back the changes for this config script.
93
+ #
94
+ # This implementation raises an exception. Subclasses must define this
95
+ # method if their scripts can be rolled back.
96
+ #
97
+ # If there are any issues rolling back the script, this method should
98
+ # raise an exception.
99
+ def down
100
+ raise "Not supported"
101
+ end
102
+
103
+ # This method runs the script in a given direction.
104
+ #
105
+ # This will use either the +up+ or +down+ method. That method call will be
106
+ # wrapped in a transaction, so if the script raises an exception, all of
107
+ # its changes will be rolled back.
108
+ #
109
+ # If the method runs successfully, this will either record a timestamp
110
+ # or remove a timestamp in the +config_scripts+ table.
111
+ #
112
+ # @param [Symbol] direction
113
+ # Whether we should run +up+ or +down+.
114
+ def run(direction)
115
+ ActiveRecord::Base.transaction do
116
+ begin
117
+ self.send(direction)
118
+ rescue => e
119
+ puts "Error running script for #{self.class.name}: #{e.message}"
120
+ puts e.backtrace.first
121
+ raise e
122
+ end
123
+
124
+ case(direction)
125
+ when :up
126
+ ScriptHistory.record_timestamp(@timestamp)
127
+ when :down
128
+ ScriptHistory.remove_timestamp(@timestamp)
129
+ end
130
+ Rails.cache.clear
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,39 @@
1
+ module ConfigScripts
2
+ module Scripts
3
+ # This class models a record of a script being run.
4
+ #
5
+ # This uses the +config_scripts+ table to record its histories.
6
+ class ScriptHistory < ActiveRecord::Base
7
+ self.table_name = 'config_scripts'
8
+
9
+ # @!attribute name
10
+ # The name of the script, which will be its timestamp.
11
+ # @return [String]
12
+
13
+ # This method gets all of the entries that have a timestamp as their name.
14
+ # @return [Relation<ScriptHistory>]
15
+ def self.entries_for_timestamp(timestamp)
16
+ self.where(:name => timestamp)
17
+ end
18
+
19
+ # This method determines if we have run a script with a timestamp.
20
+ # @return [Boolean]
21
+ def self.script_was_run?(timestamp)
22
+ self.entries_for_timestamp(timestamp).any?
23
+ end
24
+
25
+ # This method records that we have run a script with a timestamp.
26
+ # @return [ScriptHistory]
27
+ def self.record_timestamp(timestamp)
28
+ self.entries_for_timestamp(timestamp).first_or_create
29
+ end
30
+
31
+ # This method removes all records that we have run a script with a
32
+ # timestamp.
33
+ # @return [Array<ScriptHistory>]
34
+ def self.remove_timestamp(timestamp)
35
+ self.entries_for_timestamp(timestamp).destroy_all
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,9 @@
1
+ module ConfigScripts
2
+ # This module encapsulates code for generating and running configuration
3
+ # scripts.
4
+ module Scripts
5
+ end
6
+ end
7
+
8
+ require 'config_scripts/scripts/script'
9
+ require 'config_scripts/scripts/script_history'