Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit e8a8329983fa65ea34edcc3cee06015420bc387a @pnomolos committed Aug 22, 2012
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in dm-types-serialized-php.gemspec
+gemspec
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Phil
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
+# Dm::Types::Serialized::Php
+
+TODO: Write a gem description
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+ gem 'dm-types-serialized-php'
+
+And then execute:
+
+ $ bundle
+
+Or install it yourself as:
+
+ $ gem install dm-types-serialized-php
+
+## Usage
+
+TODO: Write usage instructions here
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Added some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
@@ -0,0 +1,2 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/dm-types-serialized-php/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Phil"]
+ gem.email = ["pnomolos@gmail.com"]
+ gem.description = %q{TODO: Write a gem description}
+ gem.summary = %q{TODO: Write a gem summary}
+ gem.homepage = ""
+
+ gem.files = `git ls-files`.split($\)
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
+ gem.name = "dm-types-serialized-php"
+ gem.require_paths = ["lib"]
+ gem.version = Dm::Types::Serialized::Php::VERSION
+
+ gem.add_dependency('php-serialize_ryan')
+end
@@ -0,0 +1,2 @@
+require 'dm-types-serialized-php/version'
+require 'dm-types-serialized-php/serialized-php.rb'
@@ -0,0 +1,47 @@
+require 'dm-core'
+require 'dm-types/support/dirty_minder'
+require 'serialized-php_ryan'
+
+module DataMapper
+ class Property
+ class SerializedPhp < Text
+
+ def custom?
+ true
+ end
+
+ def primitive?(value)
+ !::Php.serialized?(value)
+ end
+
+ def valid?(value, negated = false)
+ super || dump(value).kind_of?(::String)
+ end
+
+ def load(value)
+ if value.nil?
+ nil
+ elsif value.is_a?(::String)
+ typecast_to_primitive(value)
+ else
+ raise ArgumentError.new("+value+ of a property of SerializedPhp type must be nil or a String")
+ end
+ end
+
+ def dump(value)
+ if value.nil? || (value.is_a?(::String) && !::Php.serialized?(value))
+ value
+ else
+ ::Php.serialize(value)
+ end
+ end
+
+ def typecast_to_primitive(value)
+ ::Php.unserialize(value.to_s)
+ end
+
+ include ::DataMapper::Property::DirtyMinder
+
+ end # class Json
+ end
+end
@@ -0,0 +1,7 @@
+module DataMapper
+ class Property
+ class SerializedPhp
+ VERSION = "0.0.1"
+ end
+ end
+end

0 comments on commit e8a8329

Please sign in to comment.