Commit 2b4e6250 authored by Eloy Duran's avatar Eloy Duran

Use ActiveSupport to clean a bit up and remove some dead code.

parent ec3d6542
framework 'Foundation' framework 'Foundation'
require 'fileutils' require 'fileutils'
require 'active_support/inflector'
require 'active_support/core_ext/string/inflections'
module Pod module Pod
module Xcode module Xcode
class Project class Project
...@@ -17,8 +20,7 @@ module Pod ...@@ -17,8 +20,7 @@ module Pod
end end
def self.has_many(plural_attr_name, options = {}, &block) def self.has_many(plural_attr_name, options = {}, &block)
klass = options[:class] || PBXFileReference klass = options[:class] || Project.const_get("PBX#{plural_attr_name.to_s.classify}")
singular_attr_name = options[:singular] || plural_attr_name.to_s[0..-2] # strip off 's'
if options[:fkey_on_target] if options[:fkey_on_target]
define_method(plural_attr_name) do define_method(plural_attr_name) do
scoped = @project.objects.select_by_class(klass).select do |object| scoped = @project.objects.select_by_class(klass).select do |object|
...@@ -29,7 +31,8 @@ module Pod ...@@ -29,7 +31,8 @@ module Pod
end end
end end
else else
uuid_list_name = options[:uuid] || "#{singular_attr_name}References" singular_attr_name = plural_attr_name.to_s.singularize
uuid_list_name = "#{singular_attr_name}References"
attribute(plural_attr_name, uuid_list_name) attribute(plural_attr_name, uuid_list_name)
define_method(plural_attr_name) do define_method(plural_attr_name) do
uuids = send(uuid_list_name) uuids = send(uuid_list_name)
...@@ -50,7 +53,7 @@ module Pod ...@@ -50,7 +53,7 @@ module Pod
def self.belongs_to(singular_attr_name, options = {}) def self.belongs_to(singular_attr_name, options = {})
if uuid_name = options[:uuids] if uuid_name = options[:uuids]
# part of another objects uuid list # part of another objects uuid list
klass = options[:class] klass = options[:class] || Project.const_get("PBX#{singular_attr_name.to_s.classify}")
define_method(singular_attr_name) do define_method(singular_attr_name) do
# Loop over all objects of the class and find the one that includes # Loop over all objects of the class and find the one that includes
# this object in the specified uuid list. # this object in the specified uuid list.
...@@ -80,16 +83,6 @@ module Pod ...@@ -80,16 +83,6 @@ module Pod
end end
end end
def self.has_one(singular_attr_name, options = {})
klass = options[:class]
uuid_name = options[:uuid] || "#{singular_attr_name}Reference"
define_method(singular_attr_name) do
@project.objects.select_by_class(klass).find do |object|
object.respond_to?(uuid_name) && object.send(uuid_name) == self.uuid
end
end
end
def self.isa def self.isa
@isa ||= name.split('::').last @isa ||= name.split('::').last
end end
...@@ -157,8 +150,8 @@ module Pod ...@@ -157,8 +150,8 @@ module Pod
class PBXFileReference < PBXObject class PBXFileReference < PBXObject
attributes :path, :sourceTree, :explicitFileType, :includeInIndex attributes :path, :sourceTree, :explicitFileType, :includeInIndex
has_many :buildFiles, :uuid => :fileRef, :fkey_on_target => true, :class => Project::PBXBuildFile has_many :buildFiles, :uuid => :fileRef, :fkey_on_target => true
belongs_to :group, :class => Project::PBXGroup, :uuids => :childReferences belongs_to :group, :uuids => :childReferences
def initialize(project, uuid, attributes) def initialize(project, uuid, attributes)
is_new = uuid.nil? is_new = uuid.nil?
...@@ -185,7 +178,7 @@ module Pod ...@@ -185,7 +178,7 @@ module Pod
class PBXGroup < PBXObject class PBXGroup < PBXObject
attributes :sourceTree attributes :sourceTree
has_many :children, :singular => :child do |object| has_many :children, :class => PBXFileReference do |object|
if object.is_a?(Pod::Xcode::Project::PBXFileReference) if object.is_a?(Pod::Xcode::Project::PBXFileReference)
# Associating the file to this group through the inverse # Associating the file to this group through the inverse
# association will also remove it from the group it was in. # association will also remove it from the group it was in.
...@@ -272,8 +265,8 @@ module Pod ...@@ -272,8 +265,8 @@ module Pod
attributes :productName, :productType attributes :productName, :productType
has_many :buildPhases, :class => PBXBuildPhase has_many :buildPhases
has_many :dependencies, :singular => :dependency # TODO :class => ? has_many :dependencies # TODO :class => ?
has_many :buildRules # TODO :class => ? has_many :buildRules # TODO :class => ?
belongs_to :buildConfigurationList belongs_to :buildConfigurationList
belongs_to :product, :uuid => :productReference belongs_to :product, :uuid => :productReference
......
...@@ -4,6 +4,7 @@ require 'mac_bacon' ...@@ -4,6 +4,7 @@ require 'mac_bacon'
require 'pathname' require 'pathname'
ROOT = Pathname.new(File.expand_path('../../', __FILE__)) ROOT = Pathname.new(File.expand_path('../../', __FILE__))
gem 'activesupport', '~> 3.1.1'
$:.unshift((ROOT + 'lib').to_s) $:.unshift((ROOT + 'lib').to_s)
require 'cocoapods' require 'cocoapods'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment