gotime-cassandra_object 2.9.1 → 2.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'gotime-cassandra_object'
5
- s.version = '2.9.1'
5
+ s.version = '2.9.2'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
@@ -96,11 +96,9 @@ module CassandraObject
96
96
  end
97
97
 
98
98
  private
99
-
100
- def self.column_family_tasks
101
- Tasks::ColumnFamily.new(CassandraObject::Base.connection.keyspace)
102
- end
103
-
99
+ def self.column_family_tasks
100
+ Tasks::ColumnFamily.new(CassandraObject::Base.connection.keyspace)
101
+ end
104
102
  end
105
103
  end
106
104
  end
@@ -1,7 +1,5 @@
1
1
  module CassandraObject
2
-
3
2
  module Tasks
4
-
5
3
  class ColumnFamily
6
4
 
7
5
  COMPARATOR_TYPES = { :time => 'TimeUUIDType',
@@ -21,14 +19,14 @@ module CassandraObject
21
19
  connection.schema.cf_defs.find { |cf_def| cf_def.name == name.to_s }
22
20
  end
23
21
 
24
- def create(name, &block)
22
+ def create(name)
25
23
  cf = Cassandra::ColumnFamily.new
26
24
  cf.name = name.to_s
27
25
  cf.keyspace = @keyspace.to_s
28
26
  cf.comparator_type = 'BytesType'
29
27
  cf.column_type = 'Standard'
30
28
 
31
- block.call cf if block
29
+ yield(cf) if block_given?
32
30
 
33
31
  post_process_column_family(cf)
34
32
  connection.add_column_family(cf)
@@ -62,14 +62,13 @@ module CassandraObject
62
62
  end
63
63
 
64
64
  private
65
-
66
- def connection
67
- unless @connection
68
- c = CassandraObject::Base.connection
69
- @connection = Cassandra.new('system', c.servers, c.thrift_client_options)
65
+ def connection
66
+ unless @connection
67
+ c = CassandraObject::Base.connection
68
+ @connection = Cassandra.new('system', c.servers, c.thrift_client_options)
69
+ end
70
+ @connection
70
71
  end
71
- @connection
72
- end
73
72
 
74
73
  end
75
74
 
@@ -1,65 +1,36 @@
1
1
  namespace :ks do
2
- task :configure => :environment do
3
- @configs = YAML.load_file(Rails.root.join("config", "cassandra.yml"))
4
- @config = @configs[Rails.env || 'development']
5
- end
6
-
7
- #task :set_keyspace => :configure do
8
- #set_keyspace
9
- #end
10
-
11
2
  desc 'Create the keyspace in config/cassandra.yml for the current environment'
12
- task :create => :configure do
13
- CassandraObject::Tasks::Keyspace.new.create @config['keyspace'], @config
14
- puts "Created keyspace: #{@config['keyspace']}"
15
- end
16
-
17
- namespace :create do
18
- desc 'Create keyspaces in config/cassandra.yml for all environments'
19
- task :all => :configure do
20
- created = []
21
- @configs.values.each do |config|
22
- CassandraObject::Tasks::Keyspace.new.create config['keyspace'], config
23
- created << config['keyspace']
24
- end
25
- puts "Created keyspaces: #{created.join(', ')}"
26
- end
3
+ task :create => :environment do
4
+ CassandraObject::Tasks::Keyspace.new.create config['keyspace'], config
5
+ puts "Created keyspace: #{config['keyspace']}"
27
6
  end
28
7
 
29
8
  desc 'Drop keyspace in config/cassandra.yml for the current environment'
30
- task :drop => :configure do
31
- CassandraObject::Tasks::Keyspace.new.drop @config['keyspace']
32
- puts "Dropped keyspace: #{@config['keyspace']}"
33
- end
34
-
35
- namespace :drop do
36
- desc 'Drop keyspaces in config/cassandra.yml for all environments'
37
- task :all => :configure do
38
- dropped = []
39
- @configs.values.each do |config|
40
- CassandraObject::Tasks::Keyspace.new.drop config['keyspace']
41
- dropped << config['keyspace']
42
- end
43
- puts "Dropped keyspaces: #{dropped.join(', ')}"
44
- end
9
+ task :drop => :environment do
10
+ CassandraObject::Tasks::Keyspace.new.drop config['keyspace']
11
+ puts "Dropped keyspace: #{config['keyspace']}"
45
12
  end
46
13
 
47
14
  desc 'Migrate the keyspace (options: VERSION=x)'
48
- task :migrate => :configure do
15
+ task :migrate => :environment do
49
16
  version = ( ENV['VERSION'] ? ENV['VERSION'].to_i : nil )
50
17
  CassandraObject::Schema::Migrator.migrate CassandraObject::Schema::Migrator.migrations_path, version
51
18
  schema_dump
52
19
  end
53
20
 
21
+ namespace :migrate do
22
+ task :reset => ["ks:drop", "ks:create", "ks:migrate"]]
23
+ end
24
+
54
25
  desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n)'
55
- task :rollback => :set_keyspace do
26
+ task :rollback => :environment do
56
27
  step = ENV['STEP'] ? ENV['STEP'].to_i : 1
57
28
  CassandraObject::Schema::Migrator.rollback CassandraObject::Schema::Migrator.migrations_path, step
58
29
  schema_dump
59
30
  end
60
31
 
61
32
  desc 'Pushes the schema to the next version (specify steps w/ STEP=n)'
62
- task :forward => :set_keyspace do
33
+ task :forward => :environment do
63
34
  step = ENV['STEP'] ? ENV['STEP'].to_i : 1
64
35
  CassandraObject::Schema::Migrator.forward CassandraObject::Schema::Migrator.migrations_path, step
65
36
  schema_dump
@@ -67,55 +38,48 @@ namespace :ks do
67
38
 
68
39
  namespace :schema do
69
40
  desc 'Create ks/schema.json file that can be portably used against any Cassandra instance supported by CassandraObject'
70
- task :dump => :configure do
41
+ task :dump => :environment do
71
42
  schema_dump
72
43
  end
73
44
 
74
45
  desc 'Load ks/schema.json file into Cassandra'
75
- task :load => :configure do
46
+ task :load => :environment do
76
47
  schema_load
77
48
  end
78
49
  end
79
50
 
80
51
  namespace :test do
81
52
  desc 'Load the development schema in to the test keyspace'
82
- task :prepare => :configure do
53
+ task :prepare => :environment do
83
54
  schema_dump :development
84
55
  schema_load :test
85
56
  end
86
57
  end
87
58
 
88
- desc 'Retrieves the current schema version number'
89
- task :version => :set_keyspace do
90
- version = CassandraObject::Schema::Migrator.current_version
91
- puts "Current version: #{version}"
92
- end
93
-
94
59
  private
95
-
96
- def schema_dump(env = Rails.env)
97
- ks = set_keyspace env
98
- File.open "#{Rails.root}/ks/schema.json", 'w' do |file|
99
- schema = ActiveSupport::JSON.decode(ks.schema_dump.to_json)
100
- JSON.pretty_generate(schema).split(/\n/).each do |line|
101
- file.puts line
60
+ def schema_dump(env = Rails.env)
61
+ ks = set_keyspace env
62
+ File.open "#{Rails.root}/ks/schema.json", 'w' do |file|
63
+ schema = ActiveSupport::JSON.decode(ks.schema_dump.to_json)
64
+ JSON.pretty_generate(schema).split(/\n/).each do |line|
65
+ file.puts line
66
+ end
102
67
  end
103
68
  end
104
- end
105
69
 
106
- def schema_load(env = Rails.env)
107
- ks = set_keyspace env
108
- File.open "#{Rails.root}/ks/schema.json", 'r' do |file|
109
- hash = JSON.parse(file.read(nil))
110
- ks.schema_load CassandraObject::Tasks::Keyspace.parse(hash)
70
+ def schema_load(env = Rails.env)
71
+ ks = set_keyspace env
72
+ File.open "#{Rails.root}/ks/schema.json", 'r' do |file|
73
+ hash = JSON.parse(file.read(nil))
74
+ ks.schema_load CassandraObject::Tasks::Keyspace.parse(hash)
75
+ end
111
76
  end
112
- end
113
77
 
114
- def set_keyspace(env = Rails.env)
115
- config = @configs[env.to_s || 'development']
116
- ks = CassandraObject::Tasks::Keyspace.new
117
- ks.set config['keyspace']
118
- ks
119
- end
78
+ def config
79
+ @config ||= begin
80
+ configs = YAML.load_file(Rails.root.join("config", "cassandra.yml"))
81
+ configs[Rails.env || 'development']
82
+ end
83
+ end
120
84
  end
121
85
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gotime-cassandra_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.1
4
+ version: 2.9.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-11-30 00:00:00.000000000 Z
13
+ date: 2012-01-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
17
- requirement: &70268900134300 !ruby/object:Gem::Requirement
17
+ requirement: &70334356748580 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '3.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70268900134300
25
+ version_requirements: *70334356748580
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: cassandra
28
- requirement: &70268900133840 !ruby/object:Gem::Requirement
28
+ requirement: &70334356747580 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 0.12.0
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70268900133840
36
+ version_requirements: *70334356747580
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bundler
39
- requirement: &70268900133280 !ruby/object:Gem::Requirement
39
+ requirement: &70334356745380 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 1.0.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70268900133280
47
+ version_requirements: *70334356745380
48
48
  description: Cassandra ActiveModel
49
49
  email: gems@gotime.com
50
50
  executables: []