Class: Cubism::BlockSource
- Inherits:
-
Struct
- Object
- Struct
- Cubism::BlockSource
- Defined in:
- lib/cubism/cubicle_store.rb
Overview
Container for cubicle block sources
Instance Attribute Summary collapse
-
#location ⇒ Object
Returns the value of attribute location.
-
#source ⇒ Object
Returns the value of attribute source.
-
#variable_name ⇒ Object
Returns the value of attribute variable_name.
-
#view_context ⇒ Object
Returns the value of attribute view_context.
Class Method Summary collapse
Instance Method Summary collapse
- #digest ⇒ Object
-
#initialize(*args) ⇒ BlockSource
constructor
A new instance of BlockSource.
- #marshal_dump ⇒ Object
- #marshal_load(serialized_item) ⇒ Object
- #parse! ⇒ Object
Constructor Details
#initialize(*args) ⇒ BlockSource
Returns a new instance of BlockSource.
110 111 112 113 114 115 |
# File 'lib/cubism/cubicle_store.rb', line 110 def initialize(*args) super @filename, @lineno = location.split(":") @lineno = @lineno.to_i end |
Instance Attribute Details
#location ⇒ Object
Returns the value of attribute location
93 94 95 |
# File 'lib/cubism/cubicle_store.rb', line 93 def location @location end |
#source ⇒ Object
Returns the value of attribute source
93 94 95 |
# File 'lib/cubism/cubicle_store.rb', line 93 def source @source end |
#variable_name ⇒ Object
Returns the value of attribute variable_name
93 94 95 |
# File 'lib/cubism/cubicle_store.rb', line 93 def variable_name @variable_name end |
#view_context ⇒ Object
Returns the value of attribute view_context
93 94 95 |
# File 'lib/cubism/cubicle_store.rb', line 93 def view_context @view_context end |
Class Method Details
.find_or_create(location:, view_context:) ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/cubism/cubicle_store.rb', line 100 def self.find_or_create(location:, view_context:) instance = new(location: location, view_context: view_context) Cubism.source_store.fetch(instance.digest, instance) do |instance| instance.parse! end instance end |
Instance Method Details
#digest ⇒ Object
127 128 129 |
# File 'lib/cubism/cubicle_store.rb', line 127 def digest ActiveSupport::Digest.hexdigest("#{location}:#{File.read(@filename)}") end |
#marshal_dump ⇒ Object
131 132 133 |
# File 'lib/cubism/cubicle_store.rb', line 131 def marshal_dump to_h.except(:view_context) end |
#marshal_load(serialized_item) ⇒ Object
135 136 137 138 139 |
# File 'lib/cubism/cubicle_store.rb', line 135 def marshal_load(serialized_item) members.excluding(:view_context).each do |arg| send("#{arg}=", serialized_item[arg]) end end |
#parse! ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'lib/cubism/cubicle_store.rb', line 117 def parse! return if location.start_with?("inline template") lines = File.readlines(@filename)[@lineno - 1..] preprocessor = Cubism::Preprocessor.new(source: lines.join.squish, view_context: view_context) self.variable_name = preprocessor.block_variable_name self.source = preprocessor.process end |