Skip to content

Commit

Permalink
Removing the BubbleWrap dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkan committed Nov 25, 2012
1 parent d3d8563 commit f3130a2
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 39 deletions.
3 changes: 1 addition & 2 deletions Rakefile
Expand Up @@ -2,11 +2,10 @@
require "bundler/gem_tasks"
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'
require 'bubble-wrap'

Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.delegate_class = 'FakeDelegate'
app.files += Dir.glob('./lib/motion_model/**/*.rb')
app.files = Dir.glob('./lib/motion_model/**/*.rb')
app.files = (app.files + Dir.glob('./app/**/*.rb')).uniq
end
101 changes: 64 additions & 37 deletions lib/motion_model/ext.rb
Expand Up @@ -2,22 +2,49 @@ class String
def humanize
self.split(/_|-| /).join(' ')
end

def titleize
self.split(/_|-| /).each{|word| word[0...1] = word[0...1].upcase}.join(' ')
end

def empty?
self.length < 1
end

def pluralize
Inflector.inflections.pluralize self
end

def singularize
Inflector.inflections.singularize self
end

def camelize(uppercase_first_letter = true)
string = self.dup
string.gsub!(/(?:_|(\/))([a-z\d]*)/i) do
new_word = $2.downcase
new_word[0] = new_word[0].upcase
new_word = "/#{new_word}" if $1 == '/'
new_word
end
if uppercase_first_letter && uppercase_first_letter != :lower
string[0] = string[0].upcase
else
string[0] = string[0].downcase
end
string.gsub!('/', '::')
string
end

def underscore
word = self.dup
word.gsub!(/::/, '/')
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
word.tr!("-", "_")
word.downcase!
word
end
end

# Inflector is a singleton class that helps
Expand All @@ -28,11 +55,11 @@ class Inflector
def self.instance
@__instance__ ||= new
end

def initialize
reset
end

def reset
# Put singular-form to plural form transformations here
@plurals = [
Expand All @@ -55,69 +82,69 @@ def reset
[/^(.*)i$/i, '\1us'], # alumni => alumnus
[/^(.*)s$/i, '\1'] # normals => normal
]

@irregulars = [
]

@uncountables = [
'fish',
'sheep'
]
end

attr_reader :plurals, :singulars, :uncountables, :irregulars

def self.inflections
if block_given?
yield Inflector.instance
else
Inflector.instance
end
end

def uncountable(word)
@uncountables << word
end

def singular(rule, replacement)
@singulars << [rule, replacement]
end

def plural(rule, replacement)
@plurals << [rule, replacement]
end

def irregular(rule, replacement)
@irregulars << [rule, replacement]
end

def uncountable?(word)
return word if @uncountables.include?(word.downcase)
false
end

def singularize(word)
return word if uncountable?(word)
plural = word.dup

@irregulars.each do |rule|
return plural if plural.gsub!(rule.first, rule.last)
end

@singulars.each do |rule|
return plural if plural.gsub!(rule.first, rule.last)
end
plural
end

def pluralize(word)
return word if uncountable?(word)
singular = word.dup

@irregulars.each do |rule|
return singular if singular.gsub!(rule.first, rule.last)
end

@plurals.each do |rule|
return singular if singular.gsub!(rule.first, rule.last)
end
Expand All @@ -141,7 +168,7 @@ class Hash
def empty?
self.length < 1
end
end
end

class Symbol
def titleize
Expand All @@ -151,23 +178,23 @@ def titleize

class Ansi
ESCAPE = "\033"

def self.color(color_constant)
"#{ESCAPE}[#{color_constant}m"
end

def self.reset_color
color 0
end

def self.yellow_color
color 33
end

def self.green_color
color 32
end

def self.red_color
color 31
end
Expand All @@ -176,46 +203,46 @@ def self.red_color
class Debug
@@silent = false
@@colorize = true

# Use silence if you want to keep messages from being echoed
# to the console.
def self.silence
@@silent = true
end

def self.colorize
@@colorize
end

def self.colorize=(value)
@@colorize = value == true
end

# Use resume when you want messages that were silenced to
# resume displaying.
def self.resume
@@silent = false
end

def self.put_message(type, message, color = Ansi.reset_color)
open_color = @@colorize ? color : ''
close_color = @@colorize ? Ansi.reset_color : ''

NSLog("#{open_color}#{type} #{caller[1]}: #{message}#{close_color}") unless @@silent
end

def self.info(msg)
put_message 'INFO', msg, Ansi.green_color
end

def self.warning(msg)
put_message 'WARNING', msg, Ansi.yellow_color
end

def self.error(msg)
put_message 'ERROR', msg, Ansi.red_color
end

end

# These are C macros in iOS SDK. Not workable for Ruby.
Expand Down

0 comments on commit f3130a2

Please sign in to comment.