Module: Utusemi

Defined in:
lib/utusemi.rb,
lib/utusemi/core.rb,
lib/utusemi/railtie.rb,
lib/utusemi/version.rb,
lib/utusemi/definition.rb,
lib/utusemi/configuration.rb

Defined Under Namespace

Modules: Core Classes: AttributeDefinitionError, Configuration, Definition, Railtie

Constant Summary collapse

VERSION =
'0.0.7'

Class Method Summary collapse

Class Method Details

.configObject



24
25
26
# File 'lib/utusemi.rb', line 24

def config
  @configuration ||= Configuration.new
end

.configure(&block) ⇒ Object



28
29
30
# File 'lib/utusemi.rb', line 28

def configure(&block)
  config.instance_eval(&block)
end

.enableObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/utusemi.rb', line 10

def enable
  this = self
  ActiveSupport.on_load(:active_record) do
    # for instance
    this.include_to_activerecord_base
    # for model and relation
    this.prepend_to_activerecord_base
    this.prepend_to_activerecord_relation
    this.prepend_to_activerecord_singleton_class
    this.prepend_to_activerecord_associations_hasmanyassociation
    this.prepend_to_activerecord_associations_collectionproxy
  end
end

.include_to_activerecord_baseObject



32
33
34
35
# File 'lib/utusemi.rb', line 32

def include_to_activerecord_base
  # TODO: Organize name spaces
  ActiveRecord::Base.send(:include, Core::InstanceMethods)
end

.prepend_to_activerecord_associations_collectionproxyObject



58
59
60
# File 'lib/utusemi.rb', line 58

def prepend_to_activerecord_associations_collectionproxy
  ActiveRecord::Associations::CollectionProxy.send(:prepend, Core::ActiveRecord::CollectionProxy) if Rails::VERSION::MAJOR == 3
end

.prepend_to_activerecord_associations_hasmanyassociationObject



54
55
56
# File 'lib/utusemi.rb', line 54

def prepend_to_activerecord_associations_hasmanyassociation
  ActiveRecord::Associations::HasManyAssociation.send(:prepend, Core::ActiveRecord::Associations)
end

.prepend_to_activerecord_baseObject



37
38
39
# File 'lib/utusemi.rb', line 37

def prepend_to_activerecord_base
  ActiveRecord::Base.send(:prepend, Core::ActiveRecord::Base)
end

.prepend_to_activerecord_relationObject



41
42
43
44
# File 'lib/utusemi.rb', line 41

def prepend_to_activerecord_relation
  ActiveRecord::Relation.send(:prepend, Core::ActiveRecord::QueryMethods)
  ActiveRecord::Relation.send(:prepend, Core::ActiveRecord::Relation)
end

.prepend_to_activerecord_singleton_classObject



46
47
48
49
50
51
52
# File 'lib/utusemi.rb', line 46

def prepend_to_activerecord_singleton_class
  ActiveRecord::Base.singleton_class.send(:prepend, Core::ActiveRecord::Base::ClassMethods)
  # for rails 3.x
  ActiveRecord::Base.singleton_class.send(:prepend, Core::ActiveRecord::RelationMethod) if Rails::VERSION::MAJOR == 3
  # for association
  ActiveRecord::Base.singleton_class.send(:prepend, Core::ActiveRecord::AssociationMethods)
end