molten_core 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jeff Felchner
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,29 @@
1
+ # MoltenCore
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'molten_core'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install molten_core
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,12 @@
1
+ require 'molten_core/version'
2
+ require 'molten_core/array'
3
+ require 'molten_core/hash'
4
+ require 'molten_core/integer'
5
+ require 'molten_core/string'
6
+ require 'molten_core/action_controller/controller_resources'
7
+ require 'molten_core/active_model/validations/inclusion_validator'
8
+ require 'molten_core/single_table_inheritable'
9
+ require 'molten_core/unprotected_inheritance'
10
+
11
+ module MoltenCore
12
+ end
@@ -0,0 +1,13 @@
1
+ module ControllerResources
2
+ def qualified_name
3
+ self.controller_path.gsub('/','-')
4
+ end
5
+
6
+ def qualified_action_path
7
+ "#{self.qualified_name}-#{self.action_name}"
8
+ end
9
+
10
+ def qualified_full_path
11
+ self.request.fullpath.underscore.gsub(/[\/=]/, '-').gsub('?', '_')[1..-1]
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module ActiveModel
2
+ class Errors
3
+ def to_s
4
+ full_messages.to_sentence
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ module ActiveModel
2
+ module Validations
3
+ class InclusionValidator
4
+ def validate_each(record, attribute, value)
5
+ delimiter = options[:in]
6
+ exclusions = delimiter.respond_to?(:call) ? delimiter.call(record) : delimiter
7
+
8
+ valid = if value.respond_to? :all?
9
+ value.all? {|v| exclusions.include? v}
10
+ else
11
+ exclusions.send(inclusion_method(exclusions), value)
12
+ end
13
+
14
+ unless valid
15
+ record.errors.add(attribute, :inclusion, options.except(:in).merge!(:value => value))
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ class Array
2
+ def delete!(default = nil, &block)
3
+ index_of_item = self.index(&block)
4
+
5
+ return default unless index_of_item.present?
6
+
7
+ self.delete_at index_of_item
8
+ end
9
+
10
+ def compact_blank!
11
+ self.delete_if { |item| item.blank? }
12
+ end
13
+
14
+ def deep_strip!
15
+ self.each_with_index do |value, index|
16
+ if value.respond_to?(:strip)
17
+ self[index] = value.strip
18
+ elsif value.respond_to?(:deep_strip!)
19
+ self[index] = value.deep_strip!
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ class Hash
2
+ def deep_strip!
3
+ self.each do |key, value|
4
+ if value.respond_to?(:strip)
5
+ self[key] = value.strip
6
+ elsif value.respond_to?(:deep_strip!)
7
+ self[key] = value.deep_strip!
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ class Integer
2
+ def to_strict_i
3
+ self.to_i
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ module SingleTableInheritable
2
+ def update_type_and_attributes(options = {})
3
+ object, new_type, attrs = options[:object], options[:new_type], options[:attributes]
4
+
5
+ if new_type.present?
6
+ affected_object_attributes = object.attributes.except('type').merge(attrs)
7
+ affected_object = new_type.constantize.new
8
+ else
9
+ affected_object_attributes = object.attributes.merge(attrs)
10
+ affected_object = object.class.new
11
+ end
12
+
13
+ affected_object.id = object.id
14
+ affected_object.attributes = affected_object_attributes
15
+
16
+ if affected_object.valid?
17
+ object.before_update_type_and_attributes_delete
18
+ object.delete
19
+ affected_object.save
20
+ else
21
+ affected_object.instance_variable_set(:@new_record, object.new_record?)
22
+ end
23
+
24
+ affected_object
25
+ end
26
+
27
+ def before_update_type_and_attributes_delete
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ class String
2
+ def integer?
3
+ self.match /^\d+$/
4
+ end
5
+
6
+ def to_strict_i(base = 10)
7
+ self.integer? ? self.to_i(base) : nil
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ ###
2
+ # By default, the column used for Single Table Inheritance is protected from
3
+ # mass-assignment. For the majority of cases (at least in this application) we
4
+ # actually want the column to be able to be mass-assigned. Including this
5
+ # module into the class will make that possible.
6
+ #
7
+ module UnprotectedInheritance
8
+ def attributes_protected_by_default
9
+ super.tap do |protected_columns|
10
+ protected_columns.delete inheritance_column
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module MoltenCore
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: molten_core
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - jfelchner
9
+ - m5rk
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-10-02 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description: ''
16
+ email: support@chirrpy.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - README.md
21
+ - LICENSE
22
+ files:
23
+ - lib/molten_core/action_controller/controller_resources.rb
24
+ - lib/molten_core/active_model/errors.rb
25
+ - lib/molten_core/active_model/validations/inclusion_validator.rb
26
+ - lib/molten_core/array.rb
27
+ - lib/molten_core/hash.rb
28
+ - lib/molten_core/integer.rb
29
+ - lib/molten_core/single_table_inheritable.rb
30
+ - lib/molten_core/string.rb
31
+ - lib/molten_core/unprotected_inheritance.rb
32
+ - lib/molten_core/version.rb
33
+ - lib/molten_core.rb
34
+ - Rakefile
35
+ - README.md
36
+ - LICENSE
37
+ homepage: https://github.com/chirrpy/molten_core
38
+ licenses: []
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --charset = UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project: molten_core
58
+ rubygems_version: 1.8.24
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Easy Accessors for ActiveModel Objects
62
+ test_files: []