Skip to content

Commit

Permalink
Merge a316509 into d31d6c9
Browse files Browse the repository at this point in the history
  • Loading branch information
gcapizzi committed Jun 3, 2013
2 parents d31d6c9 + a316509 commit 9dea51b
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions lib/naught/null_class_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def generate_class
generation_mod = Module.new
customization_mod = customization_module # get a local binding
builder = self
@operations.each do |operation|
operation.call(generation_mod)
end

apply_operations(@operations, generation_mod)

null_class = Class.new(@base_class) do
const_set :GeneratedMethods, generation_mod
const_set :Customizations, customization_mod
Expand All @@ -54,9 +54,9 @@ def generate_class
include generation_mod
include customization_mod
end
class_operations.each do |operation|
operation.call(null_class)
end

apply_operations(class_operations, null_class)

null_class
end

Expand Down Expand Up @@ -161,13 +161,29 @@ def self.get(*)
end

def define_basic_methods
define_basic_instance_methods
define_basic_class_methods
end

private

def apply_operations(operations, module_or_class)
operations.each do |operation|
operation.call(module_or_class)
end
end

def define_basic_instance_methods
defer do |subject|
subject.module_exec(@inspect_proc) do |inspect_proc|
define_method(:inspect, &inspect_proc)
def initialize(*)
end
end
end
end

def define_basic_class_methods
defer(class: true) do |subject|
subject.module_eval do
class << self
Expand All @@ -179,8 +195,6 @@ class << self
end
end

private

def class_operations
@class_operations ||= []
end
Expand Down

0 comments on commit 9dea51b

Please sign in to comment.