footing 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,7 +20,6 @@ Footing.patch! Numeric, Footing::Numeric
20
20
  String.ancestors
21
21
  [
22
22
  String,
23
- Footing::String::InstanceMethods,
24
23
  Footing::String,
25
24
  Comparable,
26
25
  Object,
@@ -31,7 +30,6 @@ String.ancestors
31
30
  Numeric.ancestors
32
31
  [
33
32
  Numeric,
34
- Footing::Numeric::InstanceMethods,
35
33
  Footing::Numeric,
36
34
  Comparable,
37
35
  Object,
@@ -4,7 +4,7 @@ module Footing
4
4
  # Rekeys the Hash by invoking a method on the existing keys
5
5
  # and uses the return value as the new key.
6
6
  #
7
- # NOTE: Creates and return a new Hash.
7
+ # NOTE: Creates and returns a new Hash.
8
8
  #
9
9
  # Example:
10
10
  # h = { [1] => "short", [1,2] => "medium", [1,2,3] => "long" }
@@ -19,5 +19,23 @@ module Footing
19
19
  end
20
20
  end
21
21
 
22
+ # Recursively forces all String values to the specified encoding.
23
+ # @param [] encoding The encoding to use.
24
+ # @yield [value] Yields the value after the encoding has been applied.
25
+ def force_encoding!(encoding, &block)
26
+ each do |key, value|
27
+ case value
28
+ when String
29
+ # force encoding then strip all non ascii chars
30
+ if block_given?
31
+ self[key] = yield(value.force_encoding(encoding))
32
+ else
33
+ self[key] = value.force_encoding(encoding)
34
+ end
35
+ when Hash then value.force_encoding!(encoding, &block)
36
+ end
37
+ end
38
+ end
39
+
22
40
  end
23
41
  end
@@ -0,0 +1,20 @@
1
+ # Extend Rails with this module to add a uuid method in your migrations.
2
+ #
3
+ # Example:
4
+ # # rails_root/config/application.rb
5
+ # config.after_initialize do
6
+ # Footing.patch! ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::TableDefinition, Footing::PGTableDefinition
7
+ # end
8
+ #
9
+ module Footing
10
+ module PGTableDefinition
11
+
12
+ # Provides a uuid method when inside a migration's create_table block.
13
+ def uuid(*args)
14
+ options = args.extract_options!
15
+ #column(args[0], 'uuid default uuid_generate_v1()', options)
16
+ column(args[0], 'uuid', options)
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ # Extend Rails to support adding timestamp indexes for created_at & updated_at using day granularity.
2
+ #
3
+ # Example:
4
+ # # rails_root/config/application.rb
5
+ # config.after_initialize do
6
+ # Footing.patch! ActiveRecord::ConnectionAdapters::AbstractAdapter, Footing::PGSchemaStatements
7
+ # end
8
+ #
9
+ module Footing
10
+ module PGSchemaStatements
11
+
12
+ # Adds indexes to the created_at and updated_at timestamp columns with 'day' granularity.
13
+ # This method is available to ActiveRecord::Migration change, up, down methods.
14
+ def add_timestamp_indexes(table_name)
15
+ %w(created_at updated_at).each do |column_name|
16
+ name = "index_#{table_name}_on_#{column_name}"
17
+ execute "create index #{name} on #{quote_table_name(table_name)} (date_trunc('day', #{quote_column_name(column_name)}))"
18
+ end
19
+ end
20
+
21
+ # Removes indexes to the created_at and updated_at timestamp columns with 'day' granularity.
22
+ # This method is available to ActiveRecord::Migration change, up, down methods.
23
+ def remove_timestamp_indexes(table_name)
24
+ %w(created_at updated_at).each do |column_name|
25
+ name = "index_#{table_name}_on_#{column_name}"
26
+ execute "drop index if exists #{name}"
27
+ end
28
+ end
29
+
30
+ end
31
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: footing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-26 00:00:00.000000000 Z
12
+ date: 2012-08-11 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! " Footing provides some sanity for monkey patching practices.\n
15
15
  \ It's also a utility lib that contains additional functionality for core objects
@@ -25,6 +25,8 @@ files:
25
25
  - lib/extensions/kernel.rb
26
26
  - lib/extensions/numeric.rb
27
27
  - lib/extensions/object.rb
28
+ - lib/extensions/postgresql_adapter.rb
29
+ - lib/extensions/schema_statements.rb
28
30
  - lib/extensions/string.rb
29
31
  - lib/footing.rb
30
32
  - Gemfile