composite_primary_keys 8.1.6 → 9.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/History.rdoc +59 -7
- data/README.rdoc +62 -1
- data/Rakefile +4 -1
- data/lib/composite_primary_keys/arel/in.rb +6 -0
- data/lib/composite_primary_keys/arel/sqlserver.rb +36 -0
- data/lib/composite_primary_keys/arel/to_sql.rb +26 -0
- data/lib/composite_primary_keys/associations/association.rb +14 -12
- data/lib/composite_primary_keys/associations/association_scope.rb +22 -27
- data/lib/composite_primary_keys/associations/collection_association.rb +39 -8
- data/lib/composite_primary_keys/associations/has_many_association.rb +17 -40
- data/lib/composite_primary_keys/associations/has_many_through_association.rb +58 -58
- data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +13 -11
- data/lib/composite_primary_keys/associations/join_dependency.rb +73 -56
- data/lib/composite_primary_keys/associations/preloader/association.rb +75 -73
- data/lib/composite_primary_keys/attribute_methods/primary_key.rb +13 -11
- data/lib/composite_primary_keys/attribute_methods/read.rb +18 -15
- data/lib/composite_primary_keys/attribute_methods/write.rb +21 -19
- data/lib/composite_primary_keys/attribute_methods.rb +6 -4
- data/lib/composite_primary_keys/autosave_association.rb +19 -54
- data/lib/composite_primary_keys/base.rb +18 -82
- data/lib/composite_primary_keys/composite_arrays.rb +9 -1
- data/lib/composite_primary_keys/composite_predicates.rb +1 -0
- data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +10 -10
- data/lib/composite_primary_keys/connection_adapters/abstract_mysql_adapter.rb +5 -6
- data/lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb +23 -0
- data/lib/composite_primary_keys/core.rb +46 -45
- data/lib/composite_primary_keys/fixtures.rb +19 -17
- data/lib/composite_primary_keys/locking/optimistic.rb +53 -49
- data/lib/composite_primary_keys/nested_attributes.rb +60 -53
- data/lib/composite_primary_keys/persistence.rb +49 -41
- data/lib/composite_primary_keys/relation/batches.rb +35 -32
- data/lib/composite_primary_keys/relation/calculations.rb +3 -7
- data/lib/composite_primary_keys/relation/finder_methods.rb +122 -55
- data/lib/composite_primary_keys/relation/predicate_builder.rb +18 -29
- data/lib/composite_primary_keys/relation/query_methods.rb +25 -36
- data/lib/composite_primary_keys/relation/where_clause.rb +33 -0
- data/lib/composite_primary_keys/relation.rb +96 -43
- data/lib/composite_primary_keys/sanitization.rb +6 -15
- data/lib/composite_primary_keys/version.rb +3 -3
- data/lib/composite_primary_keys.rb +10 -19
- data/scripts/console.rb +48 -48
- data/scripts/txt2html +76 -76
- data/scripts/txt2js +65 -65
- data/tasks/databases/mysql.rake +17 -19
- data/tasks/databases/oracle.rake +29 -15
- data/tasks/databases/postgresql.rake +20 -29
- data/tasks/databases/sqlite.rake +25 -0
- data/tasks/databases/sqlserver.rake +32 -16
- data/tasks/website.rake +18 -18
- data/test/README_tests.rdoc +56 -56
- data/test/abstract_unit.rb +24 -18
- data/test/connections/connection_spec.rb +11 -2
- data/test/connections/databases.ci.yml +5 -4
- data/test/connections/databases.example.yml +19 -4
- data/test/connections/databases.yml +40 -30
- data/test/db_test.rb +52 -52
- data/test/fixtures/article.rb +1 -0
- data/test/fixtures/articles.yml +6 -6
- data/test/fixtures/capitol.rb +3 -3
- data/test/fixtures/capitols.yml +16 -16
- data/test/fixtures/comments.yml +15 -15
- data/test/fixtures/db_definitions/mysql.sql +16 -17
- data/test/fixtures/db_definitions/oracle.drop.sql +2 -0
- data/test/fixtures/db_definitions/oracle.sql +26 -17
- data/test/fixtures/db_definitions/postgresql.sql +2 -3
- data/test/fixtures/db_definitions/sqlite.sql +0 -1
- data/test/fixtures/db_definitions/sqlserver.sql +20 -35
- data/test/fixtures/department.rb +5 -5
- data/test/fixtures/departments.yml +15 -15
- data/test/fixtures/dorms.yml +4 -4
- data/test/fixtures/employee.rb +5 -7
- data/test/fixtures/employees.yml +1 -5
- data/test/fixtures/group.rb +2 -2
- data/test/fixtures/groups.yml +6 -6
- data/test/fixtures/hack.rb +4 -4
- data/test/fixtures/hacks.yml +2 -2
- data/test/fixtures/membership_status.rb +2 -2
- data/test/fixtures/product.rb +9 -9
- data/test/fixtures/product_tariff.rb +5 -5
- data/test/fixtures/products.yml +11 -11
- data/test/fixtures/reading.rb +4 -4
- data/test/fixtures/readings.yml +10 -10
- data/test/fixtures/reference_code_using_composite_key_alias.rb +8 -8
- data/test/fixtures/reference_code_using_simple_key_alias.rb +8 -8
- data/test/fixtures/reference_codes.yml +28 -28
- data/test/fixtures/reference_type.rb +1 -1
- data/test/fixtures/reference_types.yml +9 -9
- data/test/fixtures/restaurant.rb +9 -9
- data/test/fixtures/restaurants.yml +14 -14
- data/test/fixtures/restaurants_suburbs.yml +10 -10
- data/test/fixtures/room.rb +11 -11
- data/test/fixtures/room_assignment.rb +13 -13
- data/test/fixtures/room_assignments.yml +24 -24
- data/test/fixtures/room_attribute.rb +2 -2
- data/test/fixtures/room_attribute_assignment.rb +4 -4
- data/test/fixtures/room_attribute_assignments.yml +4 -4
- data/test/fixtures/room_attributes.yml +2 -2
- data/test/fixtures/rooms.yml +12 -12
- data/test/fixtures/seat.rb +5 -5
- data/test/fixtures/seats.yml +8 -8
- data/test/fixtures/street.rb +2 -2
- data/test/fixtures/streets.yml +16 -16
- data/test/fixtures/student.rb +3 -3
- data/test/fixtures/students.yml +15 -15
- data/test/fixtures/suburbs.yml +14 -14
- data/test/fixtures/tariff.rb +1 -1
- data/test/fixtures/tariffs.yml +14 -14
- data/test/fixtures/user.rb +0 -1
- data/test/plugins/pagination.rb +405 -405
- data/test/plugins/pagination_helper.rb +135 -135
- data/test/setup.rb +50 -50
- data/test/test_aliases.rb +18 -18
- data/test/test_associations.rb +18 -17
- data/test/test_composite_arrays.rb +24 -24
- data/test/test_counter_cache.rb +30 -30
- data/test/test_create.rb +14 -6
- data/test/test_delete.rb +36 -34
- data/test/test_dup.rb +37 -37
- data/test/test_exists.rb +39 -39
- data/test/test_find.rb +16 -4
- data/test/test_habtm.rb +27 -3
- data/test/test_miscellaneous.rb +32 -32
- data/test/test_nested_attributes.rb +6 -6
- data/test/test_pagination.rb +35 -35
- data/test/test_polymorphic.rb +0 -7
- data/test/test_predicates.rb +20 -20
- data/test/test_preload.rb +94 -0
- data/test/test_suite.rb +1 -1
- data/test/test_update.rb +10 -7
- data/test/test_validations.rb +13 -13
- metadata +30 -39
- data/README_DB2.rdoc +0 -33
- data/lib/composite_primary_keys/arel/visitors/to_sql.rb +0 -36
- data/lib/composite_primary_keys/associations/singular_association.rb +0 -18
- data/lib/composite_primary_keys/attribute_methods/dirty.rb +0 -29
- data/lib/composite_primary_keys/attribute_set/builder.rb +0 -20
- data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb +0 -70
- data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +0 -19
- data/lib/composite_primary_keys/dirty.rb +0 -19
- data/lib/composite_primary_keys/validations/uniqueness.rb +0 -41
- data/tasks/databases/oracle_enhanced.rake +0 -27
- data/tasks/databases/sqlite3.rake +0 -27
- data/test/connections/native_ibm_db/connection.rb +0 -19
- data/test/connections/native_mysql/connection.rb +0 -17
- data/test/connections/native_oracle/connection.rb +0 -11
- data/test/connections/native_oracle_enhanced/connection.rb +0 -16
- data/test/connections/native_postgresql/connection.rb +0 -13
- data/test/connections/native_sqlite3/connection.rb +0 -9
- data/test/connections/native_sqlserver/connection.rb +0 -11
- data/test/fixtures/db_definitions/sqlserver.drop.sql +0 -92
- data/test/test_delete_all.rb +0 -35
- data/test/test_find_in_batches.rb +0 -30
@@ -1,8 +1,8 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
class Relation
|
3
3
|
alias :initialize_without_cpk :initialize
|
4
|
-
def initialize(klass, table, values = {})
|
5
|
-
initialize_without_cpk(klass, table, values)
|
4
|
+
def initialize(klass, table, predicate_builder, values = {})
|
5
|
+
initialize_without_cpk(klass, table, predicate_builder, values)
|
6
6
|
add_cpk_support if klass && klass.composite?
|
7
7
|
end
|
8
8
|
|
@@ -16,60 +16,113 @@ module ActiveRecord
|
|
16
16
|
extend CompositePrimaryKeys::CompositeRelation
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
}.flatten
|
25
|
-
|
26
|
-
# CPK
|
27
|
-
# equalities = where_values.grep(Arel::Nodes::Equality).find_all { |node|
|
28
|
-
# node.left.relation.name == relation_table_name
|
29
|
-
# }
|
30
|
-
equalities = (nodes_from_and + where_values.grep(Arel::Nodes::Equality)).find_all { |node|
|
31
|
-
node.left.relation.name == relation_table_name
|
32
|
-
}
|
19
|
+
silence_warnings do
|
20
|
+
def _update_record(values, id, id_was) # :nodoc:
|
21
|
+
substitutes, binds = substitute_values values
|
22
|
+
|
23
|
+
scope = @klass.unscoped
|
33
24
|
|
34
|
-
|
25
|
+
if @klass.finder_needs_type_condition?
|
26
|
+
scope.unscope!(where: @klass.inheritance_column)
|
27
|
+
end
|
35
28
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
else
|
42
|
-
where.right.val
|
29
|
+
# CPK
|
30
|
+
if self.composite?
|
31
|
+
# Not sure if this is a good idea, but replace nil id_was with the new id
|
32
|
+
id_update = id_was.each_with_index.map do |value, i|
|
33
|
+
value || id[i]
|
43
34
|
end
|
44
|
-
|
45
|
-
|
35
|
+
|
36
|
+
relation = @klass.unscoped.where(cpk_id_predicate(@klass.arel_table, @klass.primary_key, id_update))
|
37
|
+
else
|
38
|
+
relation = scope.where(@klass.primary_key => (id_was || id))
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
bvs = binds + relation.bound_attributes
|
43
|
+
um = relation
|
44
|
+
.arel
|
45
|
+
.compile_update(substitutes, @klass.primary_key)
|
46
|
+
|
47
|
+
@klass.connection.update(
|
48
|
+
um,
|
49
|
+
'SQL',
|
50
|
+
bvs,
|
51
|
+
)
|
52
|
+
end
|
46
53
|
end
|
47
54
|
|
48
|
-
def
|
49
|
-
|
55
|
+
def update_all(updates)
|
56
|
+
raise ArgumentError, "Empty list of attributes to change" if updates.blank?
|
50
57
|
|
51
|
-
|
52
|
-
um = if self.composite?
|
53
|
-
relation = @klass.unscoped.where(cpk_id_predicate(@klass.arel_table, @klass.primary_key, id_was || id))
|
58
|
+
stmt = Arel::UpdateManager.new
|
54
59
|
|
55
|
-
|
56
|
-
|
57
|
-
scope = @klass.unscoped
|
60
|
+
stmt.set Arel.sql(@klass.send(:sanitize_sql_for_assignment, updates))
|
61
|
+
stmt.table(table)
|
58
62
|
|
59
|
-
|
60
|
-
|
63
|
+
if joins_values.any?
|
64
|
+
# CPK
|
65
|
+
#@klass.connection.join_to_update(stmt, arel, arel_attribute(primary_key))
|
66
|
+
if primary_key.kind_of?(Array)
|
67
|
+
attributes = primary_key.map do |key|
|
68
|
+
arel_attribute(key)
|
69
|
+
end
|
70
|
+
@klass.connection.join_to_update(stmt, arel, attributes.to_composite_keys)
|
71
|
+
else
|
72
|
+
@klass.connection.join_to_update(stmt, arel, arel_attribute(primary_key))
|
61
73
|
end
|
74
|
+
else
|
75
|
+
stmt.key = arel_attribute(primary_key)
|
76
|
+
stmt.take(arel.limit)
|
77
|
+
stmt.order(*arel.orders)
|
78
|
+
stmt.wheres = arel.constraints
|
79
|
+
end
|
80
|
+
|
81
|
+
@klass.connection.update stmt, 'SQL', bound_attributes
|
82
|
+
end
|
62
83
|
|
63
|
-
relation = scope.where(@klass.primary_key => (id_was || id))
|
64
|
-
binds += relation.bind_values
|
65
84
|
|
66
|
-
|
85
|
+
def delete_all(conditions = nil)
|
86
|
+
invalid_methods = INVALID_METHODS_FOR_DELETE_ALL.select { |method|
|
87
|
+
if MULTI_VALUE_METHODS.include?(method)
|
88
|
+
send("#{method}_values").any?
|
89
|
+
elsif SINGLE_VALUE_METHODS.include?(method)
|
90
|
+
send("#{method}_value")
|
91
|
+
elsif CLAUSE_METHODS.include?(method)
|
92
|
+
send("#{method}_clause").any?
|
93
|
+
end
|
94
|
+
}
|
95
|
+
if invalid_methods.any?
|
96
|
+
raise ActiveRecordError.new("delete_all doesn't support #{invalid_methods.join(', ')}")
|
67
97
|
end
|
68
98
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
99
|
+
if conditions
|
100
|
+
ActiveSupport::Deprecation.warn(<<-MESSAGE.squish)
|
101
|
+
Passing conditions to delete_all is deprecated and will be removed in Rails 5.1.
|
102
|
+
To achieve the same use where(conditions).delete_all.
|
103
|
+
MESSAGE
|
104
|
+
where(conditions).delete_all
|
105
|
+
else
|
106
|
+
stmt = Arel::DeleteManager.new
|
107
|
+
stmt.from(table)
|
108
|
+
|
109
|
+
# CPK
|
110
|
+
if joins_values.any? && @klass.composite?
|
111
|
+
arel_attributes = Array(primary_key).map do |key|
|
112
|
+
arel_attribute(key)
|
113
|
+
end.to_composite_keys
|
114
|
+
@klass.connection.join_to_delete(stmt, arel, arel_attributes)
|
115
|
+
elsif joins_values.any?
|
116
|
+
@klass.connection.join_to_delete(stmt, arel, arel_attribute(primary_key))
|
117
|
+
else
|
118
|
+
stmt.wheres = arel.constraints
|
119
|
+
end
|
120
|
+
|
121
|
+
affected = @klass.connection.delete(stmt, 'SQL', bound_attributes)
|
122
|
+
|
123
|
+
reset
|
124
|
+
affected
|
125
|
+
end
|
73
126
|
end
|
74
127
|
end
|
75
128
|
end
|
@@ -2,23 +2,14 @@ module ActiveRecord
|
|
2
2
|
module Sanitization
|
3
3
|
module ClassMethods
|
4
4
|
protected
|
5
|
-
|
6
|
-
# that correspond to a +composed_of+ relationship with their expanded
|
7
|
-
# aggregate attribute values.
|
8
|
-
# Given:
|
9
|
-
# class Person < ActiveRecord::Base
|
10
|
-
# composed_of :address, class_name: "Address",
|
11
|
-
# mapping: [%w(address_street street), %w(address_city city)]
|
12
|
-
# end
|
13
|
-
# Then:
|
14
|
-
# { address: Address.new("813 abc st.", "chicago") }
|
15
|
-
# # => { address_street: "813 abc st.", address_city: "chicago" }
|
5
|
+
|
16
6
|
def expand_hash_conditions_for_aggregates(attrs)
|
17
7
|
expanded_attrs = {}
|
18
8
|
attrs.each do |attr, value|
|
19
9
|
# CPK
|
20
10
|
# if aggregation = reflect_on_aggregation(attr.to_sym)
|
21
11
|
if attr.is_a?(CompositePrimaryKeys::CompositeKeys)
|
12
|
+
value = value.split('/') if value.is_a?(String)
|
22
13
|
attr.each_with_index do |key,i|
|
23
14
|
expanded_attrs[key] = value.respond_to?(:flatten) ? value.flatten[i] : value
|
24
15
|
end
|
@@ -40,15 +31,15 @@ module ActiveRecord
|
|
40
31
|
|
41
32
|
def quoted_id
|
42
33
|
# CPK
|
43
|
-
# self.class.quote_value(
|
34
|
+
# self.class.quote_value(@attributes[self.class.primary_key].value_for_database)
|
44
35
|
if self.composite?
|
45
36
|
[self.class.primary_keys, ids].transpose.map { |attr_name,id|
|
46
|
-
self.class.quote_value(
|
37
|
+
self.class.quote_value(@attributes[attr_name].value_for_database)
|
47
38
|
}
|
48
39
|
else
|
49
|
-
self.class.quote_value(
|
40
|
+
self.class.quote_value(@attributes[self.class.primary_key].value_for_database)
|
50
41
|
end
|
51
42
|
end
|
52
43
|
end
|
53
44
|
end
|
54
|
-
end
|
45
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2006-
|
2
|
+
# Copyright (c) 2006-2016 Nic Williams and Charlie Savage
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -26,13 +26,10 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
26
26
|
|
27
27
|
unless defined?(ActiveRecord)
|
28
28
|
require 'rubygems'
|
29
|
-
gem 'activerecord', '~>
|
29
|
+
gem 'activerecord', '~>5.0.0.beta3'
|
30
30
|
require 'active_record'
|
31
31
|
end
|
32
32
|
|
33
|
-
# Arel files we override
|
34
|
-
require 'arel/visitors/to_sql'
|
35
|
-
|
36
33
|
# AR files we override
|
37
34
|
require 'active_record/counter_cache'
|
38
35
|
require 'active_record/fixtures'
|
@@ -41,6 +38,7 @@ require 'active_record/persistence'
|
|
41
38
|
require 'active_record/relation'
|
42
39
|
require 'active_record/sanitization'
|
43
40
|
require 'active_record/attribute_methods'
|
41
|
+
require 'active_record/autosave_association'
|
44
42
|
|
45
43
|
require 'active_record/associations/association'
|
46
44
|
require 'active_record/associations/association_scope'
|
@@ -53,7 +51,6 @@ require 'active_record/associations/preloader/belongs_to'
|
|
53
51
|
require 'active_record/associations/singular_association'
|
54
52
|
require 'active_record/associations/collection_association'
|
55
53
|
|
56
|
-
require 'active_record/attribute_set/builder'
|
57
54
|
require 'active_record/attribute_methods/primary_key'
|
58
55
|
require 'active_record/attribute_methods/read'
|
59
56
|
require 'active_record/attribute_methods/write'
|
@@ -64,16 +61,13 @@ require 'active_record/connection_adapters/abstract_adapter'
|
|
64
61
|
require 'active_record/connection_adapters/abstract_mysql_adapter'
|
65
62
|
|
66
63
|
require 'active_record/relation/batches'
|
64
|
+
require 'active_record/relation/where_clause'
|
67
65
|
require 'active_record/relation/calculations'
|
68
66
|
require 'active_record/relation/finder_methods'
|
69
67
|
require 'active_record/relation/predicate_builder'
|
70
68
|
require 'active_record/relation/query_methods'
|
71
69
|
|
72
|
-
require 'active_record/validations/uniqueness'
|
73
|
-
|
74
70
|
# CPK files
|
75
|
-
require 'composite_primary_keys/arel/visitors/to_sql'
|
76
|
-
|
77
71
|
require 'composite_primary_keys/persistence'
|
78
72
|
require 'composite_primary_keys/base'
|
79
73
|
require 'composite_primary_keys/core'
|
@@ -82,8 +76,8 @@ require 'composite_primary_keys/composite_predicates'
|
|
82
76
|
require 'composite_primary_keys/fixtures'
|
83
77
|
require 'composite_primary_keys/relation'
|
84
78
|
require 'composite_primary_keys/sanitization'
|
85
|
-
require 'composite_primary_keys/attribute_set/builder'
|
86
79
|
require 'composite_primary_keys/attribute_methods'
|
80
|
+
require 'composite_primary_keys/autosave_association'
|
87
81
|
require 'composite_primary_keys/version'
|
88
82
|
|
89
83
|
require 'composite_primary_keys/associations/association'
|
@@ -94,14 +88,9 @@ require 'composite_primary_keys/associations/join_dependency'
|
|
94
88
|
require 'composite_primary_keys/associations/join_dependency/join_association'
|
95
89
|
require 'composite_primary_keys/associations/preloader/association'
|
96
90
|
require 'composite_primary_keys/associations/preloader/belongs_to'
|
97
|
-
require 'composite_primary_keys/associations/singular_association'
|
98
91
|
require 'composite_primary_keys/associations/collection_association'
|
99
92
|
|
100
|
-
require 'composite_primary_keys/dirty'
|
101
|
-
require 'composite_primary_keys/autosave_association'
|
102
|
-
|
103
93
|
require 'composite_primary_keys/attribute_methods/primary_key'
|
104
|
-
require 'composite_primary_keys/attribute_methods/dirty'
|
105
94
|
require 'composite_primary_keys/attribute_methods/read'
|
106
95
|
require 'composite_primary_keys/attribute_methods/write'
|
107
96
|
require 'composite_primary_keys/locking/optimistic'
|
@@ -109,14 +98,16 @@ require 'composite_primary_keys/nested_attributes'
|
|
109
98
|
|
110
99
|
require 'composite_primary_keys/connection_adapters/abstract_adapter'
|
111
100
|
require 'composite_primary_keys/connection_adapters/abstract_mysql_adapter'
|
112
|
-
require 'composite_primary_keys/connection_adapters/abstract/connection_specification_changes'
|
113
101
|
|
114
102
|
require 'composite_primary_keys/relation/batches'
|
103
|
+
require 'composite_primary_keys/relation/where_clause'
|
115
104
|
require 'composite_primary_keys/relation/calculations'
|
116
105
|
require 'composite_primary_keys/relation/finder_methods'
|
117
106
|
require 'composite_primary_keys/relation/predicate_builder'
|
118
107
|
require 'composite_primary_keys/relation/query_methods'
|
119
108
|
|
120
|
-
require 'composite_primary_keys/validations/uniqueness'
|
121
|
-
|
122
109
|
require 'composite_primary_keys/composite_relation'
|
110
|
+
|
111
|
+
require 'composite_primary_keys/arel/in'
|
112
|
+
require 'composite_primary_keys/arel/to_sql'
|
113
|
+
require 'composite_primary_keys/arel/sqlserver'
|
data/scripts/console.rb
CHANGED
@@ -1,48 +1,48 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
#
|
4
|
-
# if run as script, load the file as library while starting irb
|
5
|
-
#
|
6
|
-
if __FILE__ == $0
|
7
|
-
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
8
|
-
ENV['ADAPTER'] = ARGV[0]
|
9
|
-
exec "#{irb} -f -r #{$0} --simple-prompt"
|
10
|
-
end
|
11
|
-
|
12
|
-
#
|
13
|
-
# check if the given adapter is supported (default: mysql)
|
14
|
-
#
|
15
|
-
adapters = %w[mysql sqlite oracle oracle_enhanced postgresql ibm_db]
|
16
|
-
adapter = ENV['ADAPTER'] || 'mysql'
|
17
|
-
unless adapters.include? adapter
|
18
|
-
puts "Usage: #{__FILE__} <adapter>"
|
19
|
-
puts ''
|
20
|
-
puts 'Adapters: '
|
21
|
-
puts adapters.map{ |adapter| " #{adapter}" }.join("\n")
|
22
|
-
exit 1
|
23
|
-
end
|
24
|
-
|
25
|
-
#
|
26
|
-
# load all necessary libraries
|
27
|
-
#
|
28
|
-
require 'rubygems'
|
29
|
-
require 'local/database_connections'
|
30
|
-
|
31
|
-
$LOAD_PATH.unshift 'lib'
|
32
|
-
|
33
|
-
begin
|
34
|
-
require 'local/paths'
|
35
|
-
$LOAD_PATH.unshift "#{ENV['EDGE_RAILS_DIR']}/active_record/lib" if ENV['EDGE_RAILS_DIR']
|
36
|
-
$LOAD_PATH.unshift "#{ENV['EDGE_RAILS_DIR']}/activesupport/lib" if ENV['EDGE_RAILS_DIR']
|
37
|
-
rescue
|
38
|
-
end
|
39
|
-
|
40
|
-
require 'active_support'
|
41
|
-
require 'active_record'
|
42
|
-
|
43
|
-
require "test/connections/native_#{adapter}/connection"
|
44
|
-
require 'composite_primary_keys'
|
45
|
-
|
46
|
-
PROJECT_ROOT = File.join(File.dirname(__FILE__), '..')
|
47
|
-
Dir[File.join(PROJECT_ROOT,'test/fixtures/*.rb')].each { |model| require model }
|
48
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#
|
4
|
+
# if run as script, load the file as library while starting irb
|
5
|
+
#
|
6
|
+
if __FILE__ == $0
|
7
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
8
|
+
ENV['ADAPTER'] = ARGV[0]
|
9
|
+
exec "#{irb} -f -r #{$0} --simple-prompt"
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# check if the given adapter is supported (default: mysql)
|
14
|
+
#
|
15
|
+
adapters = %w[mysql sqlite oracle oracle_enhanced postgresql ibm_db]
|
16
|
+
adapter = ENV['ADAPTER'] || 'mysql'
|
17
|
+
unless adapters.include? adapter
|
18
|
+
puts "Usage: #{__FILE__} <adapter>"
|
19
|
+
puts ''
|
20
|
+
puts 'Adapters: '
|
21
|
+
puts adapters.map{ |adapter| " #{adapter}" }.join("\n")
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# load all necessary libraries
|
27
|
+
#
|
28
|
+
require 'rubygems'
|
29
|
+
require 'local/database_connections'
|
30
|
+
|
31
|
+
$LOAD_PATH.unshift 'lib'
|
32
|
+
|
33
|
+
begin
|
34
|
+
require 'local/paths'
|
35
|
+
$LOAD_PATH.unshift "#{ENV['EDGE_RAILS_DIR']}/active_record/lib" if ENV['EDGE_RAILS_DIR']
|
36
|
+
$LOAD_PATH.unshift "#{ENV['EDGE_RAILS_DIR']}/activesupport/lib" if ENV['EDGE_RAILS_DIR']
|
37
|
+
rescue
|
38
|
+
end
|
39
|
+
|
40
|
+
require 'active_support'
|
41
|
+
require 'active_record'
|
42
|
+
|
43
|
+
require "test/connections/native_#{adapter}/connection"
|
44
|
+
require 'composite_primary_keys'
|
45
|
+
|
46
|
+
PROJECT_ROOT = File.join(File.dirname(__FILE__), '..')
|
47
|
+
Dir[File.join(PROJECT_ROOT,'test/fixtures/*.rb')].each { |model| require model }
|
48
|
+
|
data/scripts/txt2html
CHANGED
@@ -1,76 +1,76 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
gem 'RedCloth'
|
5
|
-
gem 'syntax'
|
6
|
-
|
7
|
-
require 'redcloth'
|
8
|
-
require 'syntax/convertors/html'
|
9
|
-
require 'erb'
|
10
|
-
|
11
|
-
version_path = File.join(File.dirname(__FILE__), '..', 'lib', 'composite_primary_keys', 'version.rb')
|
12
|
-
require File.expand_path(version_path)
|
13
|
-
|
14
|
-
version = CompositePrimaryKeys::VERSION::STRING
|
15
|
-
download = 'http://rubygems.org/gems/composite_primary_keys'
|
16
|
-
|
17
|
-
class Fixnum
|
18
|
-
def ordinal
|
19
|
-
# teens
|
20
|
-
return 'th' if (10..19).include?(self % 100)
|
21
|
-
# others
|
22
|
-
case self % 10
|
23
|
-
when 1
|
24
|
-
return 'st'
|
25
|
-
when 2
|
26
|
-
return 'nd'
|
27
|
-
when 3
|
28
|
-
return 'rd'
|
29
|
-
else
|
30
|
-
return 'th'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class Time
|
36
|
-
def pretty
|
37
|
-
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def convert_syntax(syntax, source)
|
42
|
-
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
|
43
|
-
end
|
44
|
-
|
45
|
-
if ARGV.length >= 1
|
46
|
-
src, template = ARGV
|
47
|
-
template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
|
48
|
-
|
49
|
-
else
|
50
|
-
puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
|
51
|
-
exit!
|
52
|
-
end
|
53
|
-
|
54
|
-
template = ERB.new(File.open(template).read)
|
55
|
-
|
56
|
-
title = nil
|
57
|
-
body = nil
|
58
|
-
File.open(src) do |fsrc|
|
59
|
-
title_text = fsrc.readline
|
60
|
-
body_text = fsrc.read
|
61
|
-
syntax_items = []
|
62
|
-
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
|
63
|
-
ident = syntax_items.length
|
64
|
-
element, syntax, source = $1, $2, $3
|
65
|
-
syntax_items << "<#{element} class=\"syntax\">#{convert_syntax(syntax, source)}</#{element}>"
|
66
|
-
"syntax-temp-#{ident}"
|
67
|
-
}
|
68
|
-
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
69
|
-
body = RedCloth.new(body_text).to_html
|
70
|
-
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
|
71
|
-
end
|
72
|
-
stat = File.stat(src)
|
73
|
-
created = stat.ctime
|
74
|
-
modified = stat.mtime
|
75
|
-
|
76
|
-
$stdout << template.result(binding)
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
gem 'RedCloth'
|
5
|
+
gem 'syntax'
|
6
|
+
|
7
|
+
require 'redcloth'
|
8
|
+
require 'syntax/convertors/html'
|
9
|
+
require 'erb'
|
10
|
+
|
11
|
+
version_path = File.join(File.dirname(__FILE__), '..', 'lib', 'composite_primary_keys', 'version.rb')
|
12
|
+
require File.expand_path(version_path)
|
13
|
+
|
14
|
+
version = CompositePrimaryKeys::VERSION::STRING
|
15
|
+
download = 'http://rubygems.org/gems/composite_primary_keys'
|
16
|
+
|
17
|
+
class Fixnum
|
18
|
+
def ordinal
|
19
|
+
# teens
|
20
|
+
return 'th' if (10..19).include?(self % 100)
|
21
|
+
# others
|
22
|
+
case self % 10
|
23
|
+
when 1
|
24
|
+
return 'st'
|
25
|
+
when 2
|
26
|
+
return 'nd'
|
27
|
+
when 3
|
28
|
+
return 'rd'
|
29
|
+
else
|
30
|
+
return 'th'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Time
|
36
|
+
def pretty
|
37
|
+
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def convert_syntax(syntax, source)
|
42
|
+
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
|
43
|
+
end
|
44
|
+
|
45
|
+
if ARGV.length >= 1
|
46
|
+
src, template = ARGV
|
47
|
+
template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
|
48
|
+
|
49
|
+
else
|
50
|
+
puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
|
51
|
+
exit!
|
52
|
+
end
|
53
|
+
|
54
|
+
template = ERB.new(File.open(template).read)
|
55
|
+
|
56
|
+
title = nil
|
57
|
+
body = nil
|
58
|
+
File.open(src) do |fsrc|
|
59
|
+
title_text = fsrc.readline
|
60
|
+
body_text = fsrc.read
|
61
|
+
syntax_items = []
|
62
|
+
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
|
63
|
+
ident = syntax_items.length
|
64
|
+
element, syntax, source = $1, $2, $3
|
65
|
+
syntax_items << "<#{element} class=\"syntax\">#{convert_syntax(syntax, source)}</#{element}>"
|
66
|
+
"syntax-temp-#{ident}"
|
67
|
+
}
|
68
|
+
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
69
|
+
body = RedCloth.new(body_text).to_html
|
70
|
+
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
|
71
|
+
end
|
72
|
+
stat = File.stat(src)
|
73
|
+
created = stat.ctime
|
74
|
+
modified = stat.mtime
|
75
|
+
|
76
|
+
$stdout << template.result(binding)
|