Class: Sapling::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sapling/base.rb

Direct Known Subclasses

ActiveRecord, Memory

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller = nil) ⇒ Base

Returns a new instance of Base.



5
6
7
# File 'lib/sapling/base.rb', line 5

def initialize(controller=nil)
  @controller = controller
end

Instance Attribute Details

#controllerObject

Returns the value of attribute controller.



3
4
5
# File 'lib/sapling/base.rb', line 3

def controller
  @controller
end

Instance Method Details

#active?(feature, options = {}) ⇒ Boolean

see Sapling::API::Client

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/sapling/base.rb', line 26

def active?(feature, options={})
  options = Util.normalized_options options, controller
  active_internal(feature,options)
end

#active_features(options = {}) ⇒ Object

returns a list of features enabled for a user see Sapling::API::Client



33
34
35
36
37
38
# File 'lib/sapling/base.rb', line 33

def active_features(options={})
  options = Util.normalized_options options, controller
  ret={}
  features.each {|feature_name,feature| ret[feature_name]=feature if active_internal(feature_name,options)}
  ret
end

#css_class(feature) ⇒ Object

Use these classes on the container elements of your features



49
50
51
# File 'lib/sapling/base.rb', line 49

def css_class(feature)
  "#{css_class_prefix}_#{feature.to_s}"
end

#css_class_prefixObject



44
45
46
# File 'lib/sapling/base.rb', line 44

def css_class_prefix
  "sapling_feature"
end

#css_toggle_class(feature, on) ⇒ Object

Put these on the html element to turn on/off features



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

def css_toggle_class(feature, on)
  "#{css_class(feature)}_#{on ? 'on' : 'off'}"
end

#featuresObject



9
# File 'lib/sapling/base.rb', line 9

def features; @features||={}; end

#js_generatorObject



40
41
42
# File 'lib/sapling/base.rb', line 40

def js_generator
  @js_generator ||= JavascriptGenerator.new(self)
end