Class: Rapid::Skeleton::Base

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, Helpers::Directory, Helpers::Files, Helpers::Gem, Helpers::IfSetting, Helpers::Migration, Helpers::Route, Helpers::Script, Helpers::Template, Helpers::View
Defined in:
lib/rapid/skeleton/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Route

#routes_path

Constructor Details

#initialize(settings = nil, options = {}) ⇒ Base

Returns a new instance of Base.



31
32
33
34
35
36
37
38
# File 'lib/rapid/skeleton/base.rb', line 31

def initialize settings = nil, options = {}
  @settings = settings
  @project_path = options[:project_path] || File.expand_path('.')
  @templates_path = options[:templates_path] || discover_templates_path(options[:file])
  @name = options[:name] || implied_name
  
  @check = options[:check] || Rapid::Check.current || Rapid::Check.new("", options)
end

Instance Attribute Details

#checkObject (readonly)

Returns the value of attribute check.



18
19
20
# File 'lib/rapid/skeleton/base.rb', line 18

def check
  @check
end

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/rapid/skeleton/base.rb', line 18

def name
  @name
end

#project_pathObject (readonly)

Returns the value of attribute project_path.



18
19
20
# File 'lib/rapid/skeleton/base.rb', line 18

def project_path
  @project_path
end

#settingsObject

Returns the value of attribute settings.



18
19
20
# File 'lib/rapid/skeleton/base.rb', line 18

def settings
  @settings
end

#templates_pathObject (readonly)

Returns the value of attribute templates_path.



18
19
20
# File 'lib/rapid/skeleton/base.rb', line 18

def templates_path
  @templates_path
end

Instance Method Details

#[]=(key, value) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/rapid/skeleton/base.rb', line 82

def []= key, value
  # if this is the first time this setting has been set
  if @pulled_settings.nil? || !@pulled_settings.include?(key)
    @pulled_settings.push key if @pulled_settings
    
    @check.log_value :info, key, value
    @settings[key] = value
    
  else
    old_value = @settings[key]
    old_value = old_value.on? if old_value.is_a?(Setting::Namespace::Instance)
    @settings[key] = value
    new_value = @settings[key]
    new_value = new_value.on? if new_value.is_a?(Setting::Namespace::Instance)
    
    if old_value == new_value
      @check.log_value :info, key, value
    else
      @check.log_value :warning, key, value
    end
  end
end

#pullObject



73
74
75
76
77
78
79
80
# File 'lib/rapid/skeleton/base.rb', line 73

def pull
  @pulling = true
  @pulled_settings = []
  !@check.encounters_error? { section(name) { bones } }
ensure
  @pulling = false
  @pulled_settings = nil
end

#pull!Object



65
66
67
68
69
70
71
# File 'lib/rapid/skeleton/base.rb', line 65

def pull!
  if pull
    true
  else
    raise Rapid::InvalidSkeletonError.new(self.class.name)
  end
end

#push(settings = nil) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/rapid/skeleton/base.rb', line 54

def push settings = nil
  self.settings = settings if settings
  
  @pushing = true
  is_valid = valid?
  section(name) { bones } if is_valid
  is_valid
ensure
  @pushing = false
end

#push!(settings = nil) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/rapid/skeleton/base.rb', line 44

def push! settings = nil
  if push(settings)
    true
  else
    raise Rapid::InvalidSkeletonError.new(errors.full_messages.join(', '))
  end
  
  true
end